Commit 61a4d3f11607e9e995aa3e16a26ca4d5607fb690
Exists in
master
and in
2 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
8 changed files
with
53 additions
and
5 deletions
Show diff stats
amadeus/settings.py
amadeus/static/img/no_image.jpg
amadeus/templates/base.html
... | ... | @@ -166,6 +166,7 @@ |
166 | 166 | <ul class="dropdown-menu" role="menu"> |
167 | 167 | <li><a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> |
168 | 168 | <li><a href="{% url 'categories:index' %}">{% trans 'Manage Categories' %}</a></li> |
169 | + <li><a href="">{% trans 'Manage News' %}</a></li> | |
169 | 170 | <li class="dropdown-accordion" data-accordion="#system_accordion"> |
170 | 171 | <div class="panel-group" id="system_accordion"> |
171 | 172 | <div class="panel panel-default"> | ... | ... |
amadeus/urls.py
... | ... | @@ -43,6 +43,7 @@ urlpatterns = [ |
43 | 43 | url(r'^links/', include('links.urls', namespace='links')), |
44 | 44 | url(r'^pdf_files/', include('pdf_file.urls', namespace='pdf_files')), |
45 | 45 | url(r'^webconferences/', include('webconference.urls', namespace = 'webconferences')), |
46 | + url(r'^news/', include('news.urls', namespace='news')), | |
46 | 47 | url(r'^i18n/', include('django.conf.urls.i18n')), |
47 | 48 | #API |
48 | 49 | url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), | ... | ... |
news/models.py
... | ... | @@ -15,7 +15,13 @@ def validate_img_extension(value): |
15 | 15 | raise ValidationError(_('File not supported.')) |
16 | 16 | |
17 | 17 | class News(models.Model): |
18 | - title = models.CharField( _("Name"), unique = True,max_length= 200) | |
19 | - slug = AutoSlugField(_("Slug"),populate_from='title',unique=True) | |
20 | - image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension]) | |
21 | - content = models.TextField(_('Description')) | |
18 | + title = models.CharField( _("Name"), unique = True,max_length= 200) | |
19 | + slug = AutoSlugField(_("Slug"),populate_from='title',unique=True) | |
20 | + image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension]) | |
21 | + content = models.TextField(_('News Content')) | |
22 | + class Meta: | |
23 | + verbose_name = _('News') | |
24 | + verbose_name_plural = _('News') | |
25 | + | |
26 | + def __str__(self): | |
27 | + return self.title | ... | ... |
news/urls.py
news/views.py
1 | 1 | from django.shortcuts import render |
2 | +from django.views import generic | |
3 | +from django.contrib.auth.mixins import LoginRequiredMixin | |
4 | +from log.models import Log | |
5 | +from log.mixins import LogMixin | |
6 | +from django.core.urlresolvers import reverse, reverse_lazy | |
2 | 7 | |
3 | -# Create your views here. | |
8 | +from .models import News | |
9 | +from .forms import NewsForm | |
10 | + | |
11 | +class ListNewsView(LoginRequiredMixin,LogMixin,generic.ListView): | |
12 | + login_url = reverse_lazy("users:login") | |
13 | + redirect_field_name = 'next' | |
14 | + | |
15 | + template_name = 'news/list.html' | |
16 | + context_object_name = "news" | |
17 | + paginate_by = 10 | |
18 | + | |
19 | + def get_queryset(self): | |
20 | + news = News.objects.all() | |
21 | + return news | |
22 | + | |
23 | +class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): | |
24 | + login_url = reverse_lazy("users:login") | |
25 | + redirect_field_name = 'next' | |
26 | + | |
27 | + | |
28 | + template_name = 'news/_form.html' | |
29 | + form_class = NewsForm | |
30 | + | |
31 | + def form_invalid(self, form): | |
32 | + context = super(CreateNewsView, self).form_invalid(form) | |
33 | + context.status_code = 400 | |
34 | + | |
35 | + return context | ... | ... |