Commit 7888976108f7124c0bbd847d507dd203db4c6b7a
1 parent
207a989d
Exists in
master
and in
2 other branches
Including news logs
Showing
1 changed file
with
71 additions
and
18 deletions
Show diff stats
news/views.py
... | ... | @@ -12,6 +12,11 @@ from .models import News |
12 | 12 | from .forms import NewsForm |
13 | 13 | |
14 | 14 | class VisualizeNews(LoginRequiredMixin,LogMixin,generic.ListView): |
15 | + log_action = "view_new" | |
16 | + log_resource = "news" | |
17 | + log_component = "news" | |
18 | + log_context = {} | |
19 | + | |
15 | 20 | login_url = reverse_lazy("users:login") |
16 | 21 | redirect_field_name = 'next' |
17 | 22 | template_name = 'news/view.html' |
... | ... | @@ -27,9 +32,20 @@ class VisualizeNews(LoginRequiredMixin,LogMixin,generic.ListView): |
27 | 32 | slug = self.kwargs.get('slug', '') |
28 | 33 | new = News.objects.get(slug=slug) |
29 | 34 | |
35 | + self.log_context['new_title'] = new.title | |
36 | + self.log_context['new_slug'] = new.slug | |
37 | + | |
38 | + super(VisualizeNews, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
39 | + | |
30 | 40 | return new |
31 | 41 | |
32 | 42 | class ListNewsView(LoginRequiredMixin,LogMixin,generic.ListView): |
43 | + log_action = "view_list_of_news" | |
44 | + log_resource = "news" | |
45 | + log_component = "news" | |
46 | + log_context = {} | |
47 | + | |
48 | + | |
33 | 49 | login_url = reverse_lazy("users:login") |
34 | 50 | redirect_field_name = 'next' |
35 | 51 | |
... | ... | @@ -46,10 +62,17 @@ class ListNewsView(LoginRequiredMixin,LogMixin,generic.ListView): |
46 | 62 | context = super(ListNewsView, self).get_context_data(**kwargs) |
47 | 63 | context['title'] = _('Manage News') |
48 | 64 | |
65 | + super(ListNewsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
66 | + | |
49 | 67 | return context |
50 | 68 | |
51 | 69 | |
52 | 70 | class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): |
71 | + log_action = "create" | |
72 | + log_resource = "news" | |
73 | + log_component = "news" | |
74 | + log_context = {} | |
75 | + | |
53 | 76 | login_url = reverse_lazy("users:login") |
54 | 77 | redirect_field_name = 'next' |
55 | 78 | template_name = 'news/create.html' |
... | ... | @@ -62,6 +85,13 @@ class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): |
62 | 85 | |
63 | 86 | self.object.save() |
64 | 87 | |
88 | + self.log_context['new_creator_user'] = self.object.creator.get_short_name() | |
89 | + self.log_context['new_title'] = self.object.title | |
90 | + self.log_context['new_slug'] = self.object.slug | |
91 | + | |
92 | + super(CreateNewsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
93 | + | |
94 | + | |
65 | 95 | return super(CreateNewsView, self).form_valid(form) |
66 | 96 | |
67 | 97 | def get_success_url(self): |
... | ... | @@ -76,31 +106,43 @@ class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): |
76 | 106 | return context |
77 | 107 | |
78 | 108 | class UpdateNewsView(LoginRequiredMixin,LogMixin,generic.UpdateView): |
79 | - login_url = reverse_lazy("users:login") | |
80 | - redirect_field_name = 'next' | |
81 | - template_name = 'news/update.html' | |
82 | - form_class = NewsForm | |
83 | - model = News | |
109 | + log_action = "update" | |
110 | + log_resource = "news" | |
111 | + log_component = "news" | |
112 | + log_context = {} | |
84 | 113 | |
85 | - def get_success_url(self): | |
86 | - messages.success(self.request, _('News successfully created!')) | |
114 | + login_url = reverse_lazy("users:login") | |
115 | + redirect_field_name = 'next' | |
116 | + template_name = 'news/update.html' | |
117 | + form_class = NewsForm | |
118 | + model = News | |
87 | 119 | |
88 | - return reverse_lazy('news:view', kwargs = {'slug': self.object.slug} ) | |
120 | + def get_success_url(self): | |
121 | + messages.success(self.request, _('News successfully created!')) | |
89 | 122 | |
90 | - def get_context_data (self, **kwargs): | |
91 | - context = super(UpdateNewsView, self).get_context_data(**kwargs) | |
92 | - context['title'] = _("Update News") | |
123 | + return reverse_lazy('news:view', kwargs = {'slug': self.object.slug} ) | |
93 | 124 | |
94 | - return context | |
125 | + def get_context_data (self, **kwargs): | |
126 | + context = super(UpdateNewsView, self).get_context_data(**kwargs) | |
127 | + context['title'] = _("Update News") | |
95 | 128 | |
96 | - def form_valid(self, form): | |
97 | - self.object = form.save(commit = False) | |
98 | - creator = self.request.user | |
99 | - self.object.creator = creator | |
129 | + return context | |
100 | 130 | |
101 | - self.object.save() | |
131 | + def form_valid(self, form): | |
132 | + self.object = form.save(commit = False) | |
133 | + creator = self.request.user | |
134 | + self.object.creator = creator | |
102 | 135 | |
103 | - return super(UpdateNewsView, self).form_valid(form) | |
136 | + self.object.save() | |
137 | + | |
138 | + self.log_context['new_update_user'] = self.object.creator.get_short_name() | |
139 | + self.log_context['new_title'] = self.object.title | |
140 | + self.log_context['new_slug'] = self.object.slug | |
141 | + | |
142 | + super(UpdateNewsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
143 | + | |
144 | + | |
145 | + return super(UpdateNewsView, self).form_valid(form) | |
104 | 146 | |
105 | 147 | class SearchNewsView(LoginRequiredMixin, LogMixin, generic.ListView): |
106 | 148 | login_url = reverse_lazy("users:login") |
... | ... | @@ -145,6 +187,11 @@ class SearchNewsView(LoginRequiredMixin, LogMixin, generic.ListView): |
145 | 187 | return context |
146 | 188 | |
147 | 189 | class DeleteNewsView(LoginRequiredMixin,LogMixin,generic.DeleteView): |
190 | + log_component = 'news' | |
191 | + log_action = 'delete' | |
192 | + log_resource = 'news' | |
193 | + log_context = {} | |
194 | + | |
148 | 195 | login_url = reverse_lazy("users:login") |
149 | 196 | redirect_field_name = 'next' |
150 | 197 | |
... | ... | @@ -167,4 +214,10 @@ class DeleteNewsView(LoginRequiredMixin,LogMixin,generic.DeleteView): |
167 | 214 | news = get_object_or_404(News, slug = self.kwargs.get('slug')) |
168 | 215 | context['new'] = news |
169 | 216 | |
217 | + self.log_context['new_creator'] = news.creator.get_short_name() | |
218 | + self.log_context['new_title'] = news.title | |
219 | + self.log_context['new_slug'] = news.slug | |
220 | + | |
221 | + super(DeleteNewsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
222 | + | |
170 | 223 | return context | ... | ... |