Commit 23f0c380bd03e87cab0468b101f2cbb40cbe5d9a
1 parent
d87731ba
Exists in
master
and in
2 other branches
Some updates in news view
Showing
1 changed file
with
22 additions
and
0 deletions
Show diff stats
news/views.py
... | ... | @@ -4,10 +4,25 @@ from django.contrib.auth.mixins import LoginRequiredMixin |
4 | 4 | from log.models import Log |
5 | 5 | from log.mixins import LogMixin |
6 | 6 | from django.core.urlresolvers import reverse, reverse_lazy |
7 | +from django.contrib import messages | |
7 | 8 | |
8 | 9 | from .models import News |
9 | 10 | from .forms import NewsForm |
10 | 11 | |
12 | +class VisualizeNews(LoginRequiredMixin,LogMixin,generic.ListView): | |
13 | + login_url = reverse_lazy("users:login") | |
14 | + redirect_field_name = 'next' | |
15 | + template_name = 'news/view.html' | |
16 | + context_object_name = "news" | |
17 | + | |
18 | + def get_context_data(self, **kwargs): | |
19 | + context = super(VisualizeNews, self).get_context_data(**kwargs) | |
20 | + slug = self.kwargs.get('slug', '') | |
21 | + news = News.objects.get(slug=slug) | |
22 | + context['news'] = news | |
23 | + | |
24 | + return context | |
25 | + | |
11 | 26 | class ListNewsView(LoginRequiredMixin,LogMixin,generic.ListView): |
12 | 27 | login_url = reverse_lazy("users:login") |
13 | 28 | redirect_field_name = 'next' |
... | ... | @@ -33,3 +48,10 @@ class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): |
33 | 48 | context.status_code = 400 |
34 | 49 | |
35 | 50 | return context |
51 | + def get_success_url(self): | |
52 | + messages.success(self.request, _('News successfully created!')) | |
53 | + | |
54 | + return reverse_lazy('news:view', kwargs = {'slug': self.object.slug} ) | |
55 | + | |
56 | +class UpdateNewsView(LoginRequiredMixin,LogMixin,generic.UpdateView): | |
57 | + pass | ... | ... |