Commit 2384ac7f3fe335ef3d938b47d86f26e3610ae022
1 parent
fd1aead1
Exists in
master
and in
3 other branches
update link update view cycle but there is still a problem on filling the data correctly
Showing
7 changed files
with
414 additions
and
236 deletions
Show diff stats
links/models.py
| @@ -23,5 +23,14 @@ class Link(Resource): | @@ -23,5 +23,14 @@ class Link(Resource): | ||
| 23 | verbose_name_plural = "Links" | 23 | verbose_name_plural = "Links" |
| 24 | 24 | ||
| 25 | def __str__(self): | 25 | def __str__(self): |
| 26 | - pass | 26 | + return self.name |
| 27 | + | ||
| 28 | + def access_link(self): | ||
| 29 | + return 'links:view' | ||
| 30 | + | ||
| 31 | + def update_link(self): | ||
| 32 | + return 'links:update' | ||
| 33 | + | ||
| 34 | + def delete_link(self): | ||
| 35 | + return 'links:delete' | ||
| 27 | 36 | ||
| 28 | \ No newline at end of file | 37 | \ No newline at end of file |
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 1 | +{% extends 'subjects/view.html' %} | ||
| 2 | + | ||
| 3 | +{% load static i18n django_bootstrap_breadcrumbs %} | ||
| 4 | + | ||
| 5 | +{% block style %} | ||
| 6 | + {{block.super}} | ||
| 7 | + <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> | ||
| 8 | +{% endblock %} | ||
| 9 | + | ||
| 10 | +{% block javascript %} | ||
| 11 | + {{block.super}} | ||
| 12 | + <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> | ||
| 13 | +{% endblock %} | ||
| 14 | + | ||
| 15 | +{% block breadcrumbs %} | ||
| 16 | + {{ block.super }} | ||
| 17 | + | ||
| 18 | + {% breadcrumb topic 'subjects:topic_view' topic.subject.slug topic.slug %} | ||
| 19 | + | ||
| 20 | + {% trans 'Edit: ' as bread %} | ||
| 21 | + {% with bread|add:link.name as bread_slug %} | ||
| 22 | + {% breadcrumb bread_slug 'links:update' topic.slug link.slug %} | ||
| 23 | + {% endwith %} | ||
| 24 | +{% endblock %} | ||
| 25 | + | ||
| 26 | +{% block content %} | ||
| 27 | + <div class="card"> | ||
| 28 | + <div class="card-content"> | ||
| 29 | + <div class="card-body"> | ||
| 30 | + {% include 'links/_form.html' %} | ||
| 31 | + </div> | ||
| 32 | + </div> | ||
| 33 | + </div> | ||
| 34 | + <br clear="all" /> | ||
| 35 | + <br clear="all" /> | ||
| 36 | +{% endblock %} |
links/urls.py
| @@ -4,4 +4,7 @@ from django.contrib.auth import views as auth_views | @@ -4,4 +4,7 @@ from django.contrib.auth import views as auth_views | ||
| 4 | from . import views | 4 | from . import views |
| 5 | 5 | ||
| 6 | urlpatterns = [ | 6 | urlpatterns = [ |
| 7 | - url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'),] | ||
| 8 | \ No newline at end of file | 7 | \ No newline at end of file |
| 8 | + url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'), | ||
| 9 | + url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteLinkView.as_view(), name='delete'), | ||
| 10 | + url(r'^update/(?P<topic_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateLinkView.as_view(), name='update'), | ||
| 11 | + url(r'^view/(?P<slug>[\w_-]+)/$', views.DetailLinkView.as_view(), name='view')] | ||
| 9 | \ No newline at end of file | 12 | \ No newline at end of file |
links/views.py
| @@ -20,119 +20,249 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission | @@ -20,119 +20,249 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission | ||
| 20 | from topics.models import Topic | 20 | from topics.models import Topic |
| 21 | # Create your views here. | 21 | # Create your views here. |
| 22 | class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | 22 | class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 23 | - log_component = 'resources' | ||
| 24 | - log_action = 'create' | ||
| 25 | - log_resource = 'file_link' | ||
| 26 | - log_context = {} | 23 | + log_component = 'resources' |
| 24 | + log_action = 'create' | ||
| 25 | + log_resource = 'file_link' | ||
| 26 | + log_context = {} | ||
| 27 | 27 | ||
| 28 | - login_url = reverse_lazy("users:login") | ||
| 29 | - redirect_field_name = 'next' | 28 | + login_url = reverse_lazy("users:login") |
| 29 | + redirect_field_name = 'next' | ||
| 30 | 30 | ||
| 31 | - template_name = 'links/create.html' | ||
| 32 | - form_class = LinkForm | 31 | + template_name = 'links/create.html' |
| 32 | + form_class = LinkForm | ||
| 33 | 33 | ||
| 34 | - def dispatch(self, request, *args, **kwargs): | ||
| 35 | - slug = self.kwargs.get('slug', '') | ||
| 36 | - topic = get_object_or_404(Topic, slug = slug) | 34 | + def dispatch(self, request, *args, **kwargs): |
| 35 | + slug = self.kwargs.get('slug', '') | ||
| 36 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 37 | 37 | ||
| 38 | - if not has_subject_permissions(request.user, topic.subject): | ||
| 39 | - return redirect(reverse_lazy('subjects:home')) | 38 | + if not has_subject_permissions(request.user, topic.subject): |
| 39 | + return redirect(reverse_lazy('subjects:home')) | ||
| 40 | 40 | ||
| 41 | - return super(CreateLinkView, self).dispatch(request, *args, **kwargs) | 41 | + return super(CreateLinkView, self).dispatch(request, *args, **kwargs) |
| 42 | 42 | ||
| 43 | - def get(self, request, *args, **kwargs): | ||
| 44 | - self.object = None | ||
| 45 | - | ||
| 46 | - form_class = self.get_form_class() | ||
| 47 | - form = self.get_form(form_class) | 43 | + def get(self, request, *args, **kwargs): |
| 44 | + self.object = None | ||
| 45 | + | ||
| 46 | + form_class = self.get_form_class() | ||
| 47 | + form = self.get_form(form_class) | ||
| 48 | 48 | ||
| 49 | - slug = self.kwargs.get('slug', '') | ||
| 50 | - topic = get_object_or_404(Topic, slug = slug) | 49 | + slug = self.kwargs.get('slug', '') |
| 50 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 51 | 51 | ||
| 52 | - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | 52 | + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
| 53 | 53 | ||
| 54 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 54 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
| 55 | 55 | ||
| 56 | - def post(self, request, *args, **kwargs): | ||
| 57 | - self.object = None | ||
| 58 | - | ||
| 59 | - form_class = self.get_form_class() | ||
| 60 | - form = self.get_form(form_class) | 56 | + def post(self, request, *args, **kwargs): |
| 57 | + self.object = None | ||
| 58 | + | ||
| 59 | + form_class = self.get_form_class() | ||
| 60 | + form = self.get_form(form_class) | ||
| 61 | 61 | ||
| 62 | - slug = self.kwargs.get('slug', '') | ||
| 63 | - topic = get_object_or_404(Topic, slug = slug) | 62 | + slug = self.kwargs.get('slug', '') |
| 63 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 64 | 64 | ||
| 65 | - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
| 66 | - | ||
| 67 | - if (form.is_valid() and pendencies_form.is_valid()): | ||
| 68 | - return self.form_valid(form, pendencies_form) | ||
| 69 | - else: | ||
| 70 | - return self.form_invalid(form, pendencies_form) | 65 | + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
| 66 | + | ||
| 67 | + if (form.is_valid() and pendencies_form.is_valid()): | ||
| 68 | + return self.form_valid(form, pendencies_form) | ||
| 69 | + else: | ||
| 70 | + return self.form_invalid(form, pendencies_form) | ||
| 71 | 71 | ||
| 72 | - def get_initial(self): | ||
| 73 | - initial = super(CreateLinkView, self).get_initial() | 72 | + def get_initial(self): |
| 73 | + initial = super(CreateLinkView, self).get_initial() | ||
| 74 | 74 | ||
| 75 | - slug = self.kwargs.get('slug', '') | 75 | + slug = self.kwargs.get('slug', '') |
| 76 | 76 | ||
| 77 | - topic = get_object_or_404(Topic, slug = slug) | ||
| 78 | - initial['subject'] = topic.subject | ||
| 79 | - | ||
| 80 | - return initial | 77 | + topic = get_object_or_404(Topic, slug = slug) |
| 78 | + initial['subject'] = topic.subject | ||
| 79 | + | ||
| 80 | + return initial | ||
| 81 | 81 | ||
| 82 | - def form_invalid(self, form, pendencies_form): | ||
| 83 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 82 | + def form_invalid(self, form, pendencies_form): |
| 83 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
| 84 | 84 | ||
| 85 | - def form_valid(self, form, pendencies_form): | ||
| 86 | - self.object = form.save(commit = False) | 85 | + def form_valid(self, form, pendencies_form): |
| 86 | + self.object = form.save(commit = False) | ||
| 87 | 87 | ||
| 88 | - slug = self.kwargs.get('slug', '') | ||
| 89 | - topic = get_object_or_404(Topic, slug = slug) | 88 | + slug = self.kwargs.get('slug', '') |
| 89 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 90 | 90 | ||
| 91 | - self.object.topic = topic | ||
| 92 | - self.object.order = topic.resource_topic.count() + 1 | 91 | + self.object.topic = topic |
| 92 | + self.object.order = topic.resource_topic.count() + 1 | ||
| 93 | 93 | ||
| 94 | - if not self.object.topic.visible and not self.object.topic.repository: | ||
| 95 | - self.object.visible = False | 94 | + if not self.object.topic.visible and not self.object.topic.repository: |
| 95 | + self.object.visible = False | ||
| 96 | 96 | ||
| 97 | - self.object.save() | 97 | + self.object.save() |
| 98 | 98 | ||
| 99 | - pend_form = pendencies_form.save(commit = False) | ||
| 100 | - pend_form.resource = self.object | ||
| 101 | - | ||
| 102 | - if not pend_form.action == "": | ||
| 103 | - pend_form.save() | ||
| 104 | - | ||
| 105 | - self.log_context['category_id'] = self.object.topic.subject.category.id | ||
| 106 | - self.log_context['category_name'] = self.object.topic.subject.category.name | ||
| 107 | - self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
| 108 | - self.log_context['subject_id'] = self.object.topic.subject.id | ||
| 109 | - self.log_context['subject_name'] = self.object.topic.subject.name | ||
| 110 | - self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
| 111 | - self.log_context['topic_id'] = self.object.topic.id | ||
| 112 | - self.log_context['topic_name'] = self.object.topic.name | ||
| 113 | - self.log_context['topic_slug'] = self.object.topic.slug | ||
| 114 | - self.log_context['link_id'] = self.object.id | ||
| 115 | - self.log_context['link_name'] = self.object.name | ||
| 116 | - self.log_context['link_slug'] = self.object.slug | 99 | + pend_form = pendencies_form.save(commit = False) |
| 100 | + pend_form.resource = self.object | ||
| 101 | + | ||
| 102 | + if not pend_form.action == "": | ||
| 103 | + pend_form.save() | ||
| 104 | + | ||
| 105 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
| 106 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
| 107 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
| 108 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
| 109 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
| 110 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
| 111 | + self.log_context['topic_id'] = self.object.topic.id | ||
| 112 | + self.log_context['topic_name'] = self.object.topic.name | ||
| 113 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
| 114 | + self.log_context['link_id'] = self.object.id | ||
| 115 | + self.log_context['link_name'] = self.object.name | ||
| 116 | + self.log_context['link_slug'] = self.object.slug | ||
| 117 | 117 | ||
| 118 | - super(CreateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 118 | + super(CreateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
| 119 | 119 | ||
| 120 | - return redirect(self.get_success_url()) | 120 | + return redirect(self.get_success_url()) |
| 121 | 121 | ||
| 122 | - def get_context_data(self, **kwargs): | ||
| 123 | - context = super(CreateLinkView, self).get_context_data(**kwargs) | 122 | + def get_context_data(self, **kwargs): |
| 123 | + context = super(CreateLinkView, self).get_context_data(**kwargs) | ||
| 124 | 124 | ||
| 125 | - context['title'] = _('Create Webiste Link') | 125 | + context['title'] = _('Create Webiste Link') |
| 126 | 126 | ||
| 127 | - slug = self.kwargs.get('slug', '') | ||
| 128 | - topic = get_object_or_404(Topic, slug = slug) | 127 | + slug = self.kwargs.get('slug', '') |
| 128 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 129 | 129 | ||
| 130 | - context['topic'] = topic | ||
| 131 | - context['subject'] = topic.subject | 130 | + context['topic'] = topic |
| 131 | + context['subject'] = topic.subject | ||
| 132 | 132 | ||
| 133 | - return context | 133 | + return context |
| 134 | 134 | ||
| 135 | - def get_success_url(self): | ||
| 136 | - messages.success(self.request, _('The Link "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) | 135 | + def get_success_url(self): |
| 136 | + messages.success(self.request, _('The Link "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) | ||
| 137 | 137 | ||
| 138 | - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | ||
| 139 | \ No newline at end of file | 138 | \ No newline at end of file |
| 139 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | ||
| 140 | + | ||
| 141 | + | ||
| 142 | + | ||
| 143 | +class DeleteLinkView(LoginRequiredMixin, LogMixin, generic.edit.DeleteView): | ||
| 144 | + | ||
| 145 | + login_url = reverse_lazy("users:login") | ||
| 146 | + redirect_field_name = 'next' | ||
| 147 | + model = Link | ||
| 148 | + template_name = 'links/delete.html' | ||
| 149 | + | ||
| 150 | + | ||
| 151 | +class DetailLinkView(LoginRequiredMixin, LogMixin, generic.detail.DetailView): | ||
| 152 | + | ||
| 153 | + login_url = reverse_lazy("users:login") | ||
| 154 | + redirect_field_name = 'next' | ||
| 155 | + | ||
| 156 | + model = Link | ||
| 157 | + template_name = 'links/view.html' | ||
| 158 | + context_object_name = 'web_link' | ||
| 159 | + | ||
| 160 | +class UpdateLinkView(LoginRequiredMixin, LogMixin, generic.edit.UpdateView): | ||
| 161 | + model = Link | ||
| 162 | + form_class = LinkForm | ||
| 163 | + template_name = 'links/update.html' | ||
| 164 | + | ||
| 165 | + login_url = reverse_lazy("users:login") | ||
| 166 | + redirect_field_name = 'next' | ||
| 167 | + | ||
| 168 | + def dispatch(self, request, *args, **kwargs): | ||
| 169 | + | ||
| 170 | + | ||
| 171 | + slug = self.kwargs.get('topic_slug', '') | ||
| 172 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 173 | + | ||
| 174 | + if not has_subject_permissions(request.user, topic.subject): | ||
| 175 | + return redirect(reverse_lazy('subjects:home')) | ||
| 176 | + | ||
| 177 | + return super(UpdateLinkView, self).dispatch(request, *args, **kwargs) | ||
| 178 | + | ||
| 179 | + | ||
| 180 | + def get(self, request, *args, **kwargs): | ||
| 181 | + self.object = self.get_object() | ||
| 182 | + | ||
| 183 | + form_class = self.get_form_class() | ||
| 184 | + form = self.get_form(form_class) | ||
| 185 | + | ||
| 186 | + slug = self.kwargs.get('topic_slug', '') | ||
| 187 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 188 | + | ||
| 189 | + pend_form = self.object.pendencies_resource.all() | ||
| 190 | + | ||
| 191 | + if len(pend_form) > 0: | ||
| 192 | + pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
| 193 | + else: | ||
| 194 | + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
| 195 | + | ||
| 196 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
| 197 | + | ||
| 198 | + def post(self, request, *args, **kwargs): | ||
| 199 | + self.object = self.get_object() | ||
| 200 | + | ||
| 201 | + form_class = self.get_form_class() | ||
| 202 | + form = self.get_form(form_class) | ||
| 203 | + | ||
| 204 | + slug = self.kwargs.get('topic_slug', '') | ||
| 205 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 206 | + | ||
| 207 | + pend_form = self.object.pendencies_resource.all() | ||
| 208 | + | ||
| 209 | + if len(pend_form) > 0: | ||
| 210 | + pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
| 211 | + else: | ||
| 212 | + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
| 213 | + | ||
| 214 | + if (form.is_valid() and pendencies_form.is_valid()): | ||
| 215 | + return self.form_valid(form, pendencies_form) | ||
| 216 | + else: | ||
| 217 | + return self.form_invalid(form, pendencies_form) | ||
| 218 | + | ||
| 219 | + def form_invalid(self, form, pendencies_form): | ||
| 220 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
| 221 | + | ||
| 222 | + def form_valid(self, form, pendencies_form): | ||
| 223 | + self.object = form.save(commit = False) | ||
| 224 | + | ||
| 225 | + if not self.object.topic.visible and not self.object.topic.repository: | ||
| 226 | + self.object.visible = False | ||
| 227 | + | ||
| 228 | + self.object.save() | ||
| 229 | + | ||
| 230 | + pend_form = pendencies_form.save(commit = False) | ||
| 231 | + pend_form.resource = self.object | ||
| 232 | + | ||
| 233 | + if not pend_form.action == "": | ||
| 234 | + pend_form.save() | ||
| 235 | + | ||
| 236 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
| 237 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
| 238 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
| 239 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
| 240 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
| 241 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
| 242 | + self.log_context['topic_id'] = self.object.topic.id | ||
| 243 | + self.log_context['topic_name'] = self.object.topic.name | ||
| 244 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
| 245 | + self.log_context['link_id'] = self.object.id | ||
| 246 | + self.log_context['link_name'] = self.object.name | ||
| 247 | + self.log_context['link_slug'] = self.object.slug | ||
| 248 | + | ||
| 249 | + super(UpdateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
| 250 | + | ||
| 251 | + return redirect(self.get_success_url()) | ||
| 252 | + | ||
| 253 | + def get_context_data(self, **kwargs): | ||
| 254 | + context = super(UpdateLinkView, self).get_context_data(**kwargs) | ||
| 255 | + | ||
| 256 | + context['title'] = _('Update Website Link') | ||
| 257 | + | ||
| 258 | + slug = self.kwargs.get('topic_slug', '') | ||
| 259 | + topic = get_object_or_404(Topic, slug = slug) | ||
| 260 | + | ||
| 261 | + context['topic'] = topic | ||
| 262 | + context['subject'] = topic.subject | ||
| 263 | + | ||
| 264 | + return context | ||
| 265 | + | ||
| 266 | + def get_success_url(self): | ||
| 267 | + messages.success(self.request, _('The Website Link "%s" was updated successfully!')%(self.object.name)) | ||
| 268 | + | ||
| 269 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
notifications/views.py
| @@ -20,226 +20,226 @@ from .models import Notification | @@ -20,226 +20,226 @@ from .models import Notification | ||
| 20 | from .utils import get_order_by, is_date | 20 | from .utils import get_order_by, is_date |
| 21 | 21 | ||
| 22 | class SubjectNotifications(LoginRequiredMixin, generic.ListView): | 22 | class SubjectNotifications(LoginRequiredMixin, generic.ListView): |
| 23 | - login_url = reverse_lazy("users:login") | ||
| 24 | - redirect_field_name = 'next' | 23 | + login_url = reverse_lazy("users:login") |
| 24 | + redirect_field_name = 'next' | ||
| 25 | 25 | ||
| 26 | - context_object_name = 'notifications' | ||
| 27 | - template_name = 'notifications/subject.html' | ||
| 28 | - paginate_by = 10 | ||
| 29 | - total = 0 | 26 | + context_object_name = 'notifications' |
| 27 | + template_name = 'notifications/subject.html' | ||
| 28 | + paginate_by = 10 | ||
| 29 | + total = 0 | ||
| 30 | 30 | ||
| 31 | - def dispatch(self, request, *args, **kwargs): | ||
| 32 | - slug = self.kwargs.get('slug', '') | ||
| 33 | - subject = get_object_or_404(Subject, slug = slug) | 31 | + def dispatch(self, request, *args, **kwargs): |
| 32 | + slug = self.kwargs.get('slug', '') | ||
| 33 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 34 | 34 | ||
| 35 | - if not has_subject_view_permissions(request.user, subject): | ||
| 36 | - return redirect(reverse_lazy('subjects:home')) | 35 | + if not has_subject_view_permissions(request.user, subject): |
| 36 | + return redirect(reverse_lazy('subjects:home')) | ||
| 37 | 37 | ||
| 38 | - return super(SubjectNotifications, self).dispatch(request, *args, **kwargs) | 38 | + return super(SubjectNotifications, self).dispatch(request, *args, **kwargs) |
| 39 | 39 | ||
| 40 | - def get_queryset(self): | ||
| 41 | - slug = self.kwargs.get('slug', '') | ||
| 42 | - subject = get_object_or_404(Subject, slug = slug) | 40 | + def get_queryset(self): |
| 41 | + slug = self.kwargs.get('slug', '') | ||
| 42 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 43 | 43 | ||
| 44 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | 44 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") |
| 45 | 45 | ||
| 46 | - self.total = notifications.count() | 46 | + self.total = notifications.count() |
| 47 | 47 | ||
| 48 | - return notifications | 48 | + return notifications |
| 49 | 49 | ||
| 50 | - def get_context_data(self, **kwargs): | ||
| 51 | - context = super(SubjectNotifications, self).get_context_data(**kwargs) | 50 | + def get_context_data(self, **kwargs): |
| 51 | + context = super(SubjectNotifications, self).get_context_data(**kwargs) | ||
| 52 | 52 | ||
| 53 | - slug = self.kwargs.get('slug', '') | ||
| 54 | - subject = get_object_or_404(Subject, slug = slug) | 53 | + slug = self.kwargs.get('slug', '') |
| 54 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 55 | 55 | ||
| 56 | - context['title'] = _('%s - Pendencies')%(subject.name) | ||
| 57 | - context['subject'] = subject | ||
| 58 | - context['total'] = self.total | 56 | + context['title'] = _('%s - Pendencies')%(subject.name) |
| 57 | + context['subject'] = subject | ||
| 58 | + context['total'] = self.total | ||
| 59 | 59 | ||
| 60 | - return context | 60 | + return context |
| 61 | 61 | ||
| 62 | class SubjectHistory(LoginRequiredMixin, generic.ListView): | 62 | class SubjectHistory(LoginRequiredMixin, generic.ListView): |
| 63 | - login_url = reverse_lazy("users:login") | ||
| 64 | - redirect_field_name = 'next' | 63 | + login_url = reverse_lazy("users:login") |
| 64 | + redirect_field_name = 'next' | ||
| 65 | 65 | ||
| 66 | - context_object_name = 'notifications' | ||
| 67 | - template_name = 'notifications/subject.html' | ||
| 68 | - paginate_by = 10 | ||
| 69 | - total = 0 | ||
| 70 | - num_rows = 0 | 66 | + context_object_name = 'notifications' |
| 67 | + template_name = 'notifications/subject.html' | ||
| 68 | + paginate_by = 10 | ||
| 69 | + total = 0 | ||
| 70 | + num_rows = 0 | ||
| 71 | 71 | ||
| 72 | - def dispatch(self, request, *args, **kwargs): | ||
| 73 | - slug = self.kwargs.get('slug', '') | ||
| 74 | - subject = get_object_or_404(Subject, slug = slug) | 72 | + def dispatch(self, request, *args, **kwargs): |
| 73 | + slug = self.kwargs.get('slug', '') | ||
| 74 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 75 | 75 | ||
| 76 | - if not has_subject_view_permissions(request.user, subject): | ||
| 77 | - return redirect(reverse_lazy('subjects:home')) | 76 | + if not has_subject_view_permissions(request.user, subject): |
| 77 | + return redirect(reverse_lazy('subjects:home')) | ||
| 78 | 78 | ||
| 79 | - return super(SubjectHistory, self).dispatch(request, *args, **kwargs) | 79 | + return super(SubjectHistory, self).dispatch(request, *args, **kwargs) |
| 80 | 80 | ||
| 81 | - def get_queryset(self): | ||
| 82 | - slug = self.kwargs.get('slug', '') | ||
| 83 | - subject = get_object_or_404(Subject, slug = slug) | 81 | + def get_queryset(self): |
| 82 | + slug = self.kwargs.get('slug', '') | ||
| 83 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 84 | 84 | ||
| 85 | - order = get_order_by(self.request.GET.get("order_by", None)) | ||
| 86 | - search = self.request.GET.get("search", None) | 85 | + order = get_order_by(self.request.GET.get("order_by", None)) |
| 86 | + search = self.request.GET.get("search", None) | ||
| 87 | 87 | ||
| 88 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) | 88 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) |
| 89 | 89 | ||
| 90 | - self.total = notifications.filter(creation_date = datetime.now()).count() | ||
| 91 | - | ||
| 92 | - if search: | ||
| 93 | - queries = Q(task__resource__name__icontains = search) | ||
| 94 | - queries |= Q(task__action__icontains = search) | 90 | + self.total = notifications.filter(creation_date = datetime.now()).count() |
| 91 | + | ||
| 92 | + if search: | ||
| 93 | + queries = Q(task__resource__name__icontains = search) | ||
| 94 | + queries |= Q(task__action__icontains = search) | ||
| 95 | 95 | ||
| 96 | - if search.isdigit(): | ||
| 97 | - queries |= Q(level = search) | 96 | + if search.isdigit(): |
| 97 | + queries |= Q(level = search) | ||
| 98 | 98 | ||
| 99 | - if is_date(search): | ||
| 100 | - search_date = parser.parse(search) | ||
| 101 | - search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) | 99 | + if is_date(search): |
| 100 | + search_date = parser.parse(search) | ||
| 101 | + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) | ||
| 102 | 102 | ||
| 103 | - queries |= Q(creation_date = search_date) | ||
| 104 | - queries |= Q(task__limit_date = search_date) | ||
| 105 | - queries |= Q(task__end_date = search_date) | ||
| 106 | - queries |= Q(meta__date = search_date) | 103 | + queries |= Q(creation_date = search_date) |
| 104 | + queries |= Q(task__limit_date = search_date) | ||
| 105 | + queries |= Q(task__end_date = search_date) | ||
| 106 | + queries |= Q(meta__date = search_date) | ||
| 107 | 107 | ||
| 108 | - notifications = notifications.filter(queries).order_by(*order) | 108 | + notifications = notifications.filter(queries).order_by(*order) |
| 109 | 109 | ||
| 110 | - self.num_rows = notifications.count() | 110 | + self.num_rows = notifications.count() |
| 111 | 111 | ||
| 112 | - return notifications | 112 | + return notifications |
| 113 | 113 | ||
| 114 | - def get_context_data(self, **kwargs): | ||
| 115 | - context = super(SubjectHistory, self).get_context_data(**kwargs) | 114 | + def get_context_data(self, **kwargs): |
| 115 | + context = super(SubjectHistory, self).get_context_data(**kwargs) | ||
| 116 | 116 | ||
| 117 | - slug = self.kwargs.get('slug', '') | ||
| 118 | - subject = get_object_or_404(Subject, slug = slug) | 117 | + slug = self.kwargs.get('slug', '') |
| 118 | + subject = get_object_or_404(Subject, slug = slug) | ||
| 119 | 119 | ||
| 120 | - context['title'] = _('%s - Pendencies')%(subject.name) | ||
| 121 | - context['subject'] = subject | ||
| 122 | - context['history'] = True | ||
| 123 | - context['total'] = self.total | ||
| 124 | - context['rows'] = self.num_rows | ||
| 125 | - context['searched'] = self.request.GET.get("search", "") | 120 | + context['title'] = _('%s - Pendencies')%(subject.name) |
| 121 | + context['subject'] = subject | ||
| 122 | + context['history'] = True | ||
| 123 | + context['total'] = self.total | ||
| 124 | + context['rows'] = self.num_rows | ||
| 125 | + context['searched'] = self.request.GET.get("search", "") | ||
| 126 | 126 | ||
| 127 | - return context | 127 | + return context |
| 128 | 128 | ||
| 129 | class IndexView(LoginRequiredMixin, generic.ListView): | 129 | class IndexView(LoginRequiredMixin, generic.ListView): |
| 130 | - login_url = reverse_lazy("users:login") | ||
| 131 | - redirect_field_name = 'next' | 130 | + login_url = reverse_lazy("users:login") |
| 131 | + redirect_field_name = 'next' | ||
| 132 | 132 | ||
| 133 | - context_object_name = 'notifications' | ||
| 134 | - template_name = 'notifications/index.html' | ||
| 135 | - paginate_by = 10 | 133 | + context_object_name = 'notifications' |
| 134 | + template_name = 'notifications/index.html' | ||
| 135 | + paginate_by = 10 | ||
| 136 | 136 | ||
| 137 | - def get_queryset(self): | ||
| 138 | - notifications = Notification.objects.filter(user = self.request.user, viewed = False, creation_date = datetime.now()).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) | 137 | + def get_queryset(self): |
| 138 | + notifications = Notification.objects.filter(user = self.request.user, viewed = False, creation_date = datetime.now()).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) | ||
| 139 | 139 | ||
| 140 | - return notifications | 140 | + return notifications |
| 141 | 141 | ||
| 142 | - def get_context_data(self, **kwargs): | ||
| 143 | - context = super(IndexView, self).get_context_data(**kwargs) | 142 | + def get_context_data(self, **kwargs): |
| 143 | + context = super(IndexView, self).get_context_data(**kwargs) | ||
| 144 | 144 | ||
| 145 | - context['title'] = _('Pendencies') | 145 | + context['title'] = _('Pendencies') |
| 146 | 146 | ||
| 147 | - return context | 147 | + return context |
| 148 | 148 | ||
| 149 | class AjaxNotifications(LoginRequiredMixin, generic.ListView): | 149 | class AjaxNotifications(LoginRequiredMixin, generic.ListView): |
| 150 | - login_url = reverse_lazy("users:login") | ||
| 151 | - redirect_field_name = 'next' | 150 | + login_url = reverse_lazy("users:login") |
| 151 | + redirect_field_name = 'next' | ||
| 152 | 152 | ||
| 153 | - context_object_name = 'notifications' | ||
| 154 | - template_name = 'notifications/_view.html' | 153 | + context_object_name = 'notifications' |
| 154 | + template_name = 'notifications/_view.html' | ||
| 155 | 155 | ||
| 156 | - def get_queryset(self): | ||
| 157 | - subject_id = self.kwargs.get('id', '') | ||
| 158 | - | ||
| 159 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | 156 | + def get_queryset(self): |
| 157 | + subject_id = self.kwargs.get('id', '') | ||
| 158 | + | ||
| 159 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | ||
| 160 | 160 | ||
| 161 | - return notifications | 161 | + return notifications |
| 162 | 162 | ||
| 163 | class AjaxHistory(LoginRequiredMixin, generic.ListView): | 163 | class AjaxHistory(LoginRequiredMixin, generic.ListView): |
| 164 | - login_url = reverse_lazy("users:login") | ||
| 165 | - redirect_field_name = 'next' | 164 | + login_url = reverse_lazy("users:login") |
| 165 | + redirect_field_name = 'next' | ||
| 166 | 166 | ||
| 167 | - context_object_name = 'notifications' | ||
| 168 | - template_name = 'notifications/_ajax_history.html' | 167 | + context_object_name = 'notifications' |
| 168 | + template_name = 'notifications/_ajax_history.html' | ||
| 169 | 169 | ||
| 170 | - def get_queryset(self): | ||
| 171 | - subject_id = self.kwargs.get('id', '') | 170 | + def get_queryset(self): |
| 171 | + subject_id = self.kwargs.get('id', '') | ||
| 172 | 172 | ||
| 173 | - order = get_order_by(self.request.GET.get("order_by", None)) | ||
| 174 | - search = self.request.GET.get("search", None) | 173 | + order = get_order_by(self.request.GET.get("order_by", None)) |
| 174 | + search = self.request.GET.get("search", None) | ||
| 175 | 175 | ||
| 176 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id).order_by(*order) | 176 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id).order_by(*order) |
| 177 | 177 | ||
| 178 | - if search: | ||
| 179 | - queries = Q(task__resource__name__icontains = search) | ||
| 180 | - queries |= Q(task__action__icontains = search) | 178 | + if search: |
| 179 | + queries = Q(task__resource__name__icontains = search) | ||
| 180 | + queries |= Q(task__action__icontains = search) | ||
| 181 | 181 | ||
| 182 | - if search.isdigit(): | ||
| 183 | - queries |= Q(level = search) | 182 | + if search.isdigit(): |
| 183 | + queries |= Q(level = search) | ||
| 184 | 184 | ||
| 185 | - if is_date(search): | ||
| 186 | - search_date = parser.parse(search) | ||
| 187 | - search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) | 185 | + if is_date(search): |
| 186 | + search_date = parser.parse(search) | ||
| 187 | + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) | ||
| 188 | 188 | ||
| 189 | - queries |= Q(creation_date = search_date) | ||
| 190 | - queries |= Q(task__limit_date = search_date) | ||
| 191 | - queries |= Q(task__end_date = search_date) | ||
| 192 | - queries |= Q(meta__date = search_date) | 189 | + queries |= Q(creation_date = search_date) |
| 190 | + queries |= Q(task__limit_date = search_date) | ||
| 191 | + queries |= Q(task__end_date = search_date) | ||
| 192 | + queries |= Q(meta__date = search_date) | ||
| 193 | 193 | ||
| 194 | - notifications = notifications.filter(queries).order_by(*order) | 194 | + notifications = notifications.filter(queries).order_by(*order) |
| 195 | 195 | ||
| 196 | - self.num_rows = notifications.count() | 196 | + self.num_rows = notifications.count() |
| 197 | 197 | ||
| 198 | - return notifications | 198 | + return notifications |
| 199 | 199 | ||
| 200 | - def get_context_data(self, **kwargs): | ||
| 201 | - context = super(AjaxHistory, self).get_context_data(**kwargs) | 200 | + def get_context_data(self, **kwargs): |
| 201 | + context = super(AjaxHistory, self).get_context_data(**kwargs) | ||
| 202 | 202 | ||
| 203 | - subject_id = self.kwargs.get('id', '') | 203 | + subject_id = self.kwargs.get('id', '') |
| 204 | 204 | ||
| 205 | - context['subject_id'] = subject_id | ||
| 206 | - context['rows'] = self.num_rows | ||
| 207 | - context['searched'] = self.request.GET.get("search", "") | ||
| 208 | - context['order_by'] = self.request.GET.get("order_by", "") | 205 | + context['subject_id'] = subject_id |
| 206 | + context['rows'] = self.num_rows | ||
| 207 | + context['searched'] = self.request.GET.get("search", "") | ||
| 208 | + context['order_by'] = self.request.GET.get("order_by", "") | ||
| 209 | 209 | ||
| 210 | - return context | 210 | + return context |
| 211 | 211 | ||
| 212 | @login_required | 212 | @login_required |
| 213 | def set_goal(request): | 213 | def set_goal(request): |
| 214 | - if request.method == "POST" and request.is_ajax(): | ||
| 215 | - meta = request.POST.get('meta', None) | 214 | + if request.method == "POST" and request.is_ajax(): |
| 215 | + meta = request.POST.get('meta', None) | ||
| 216 | 216 | ||
| 217 | - if not meta: | ||
| 218 | - return JsonResponse({'error': True, 'message': _('No goal date received')}) | 217 | + if not meta: |
| 218 | + return JsonResponse({'error': True, 'message': _('No goal date received')}) | ||
| 219 | 219 | ||
| 220 | - meta = parser.parse(meta) | 220 | + meta = parser.parse(meta) |
| 221 | 221 | ||
| 222 | - notify_id = request.POST.get('id', None) | 222 | + notify_id = request.POST.get('id', None) |
| 223 | 223 | ||
| 224 | - if not notify_id: | ||
| 225 | - return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) | 224 | + if not notify_id: |
| 225 | + return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) | ||
| 226 | 226 | ||
| 227 | - notification = get_object_or_404(Notification, id = notify_id) | 227 | + notification = get_object_or_404(Notification, id = notify_id) |
| 228 | 228 | ||
| 229 | - meta = timezone.make_aware(meta, timezone.get_current_timezone()) | 229 | + meta = timezone.make_aware(meta, timezone.get_current_timezone()) |
| 230 | 230 | ||
| 231 | - if meta < timezone.now(): | ||
| 232 | - return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) | 231 | + if meta < timezone.now(): |
| 232 | + return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) | ||
| 233 | 233 | ||
| 234 | - if meta.date() > notification.task.resource.topic.subject.end_date: | ||
| 235 | - return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) | 234 | + if meta.date() > notification.task.resource.topic.subject.end_date: |
| 235 | + return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) | ||
| 236 | 236 | ||
| 237 | - notification.meta = meta | ||
| 238 | - notification.save() | 237 | + notification.meta = meta |
| 238 | + notification.save() | ||
| 239 | 239 | ||
| 240 | - if notification.level == 2: | ||
| 241 | - message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | ||
| 242 | - else: | ||
| 243 | - message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | 240 | + if notification.level == 2: |
| 241 | + message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | ||
| 242 | + else: | ||
| 243 | + message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | ||
| 244 | 244 | ||
| 245 | - return JsonResponse({'error': False, 'message': message}) | ||
| 246 | \ No newline at end of file | 245 | \ No newline at end of file |
| 246 | + return JsonResponse({'error': False, 'message': message}) | ||
| 247 | \ No newline at end of file | 247 | \ No newline at end of file |
topics/templates/resources/list.html
| @@ -14,8 +14,8 @@ | @@ -14,8 +14,8 @@ | ||
| 14 | <input type="hidden" class="url_order" value="{% url 'topics:update_resource_order' %}" /> | 14 | <input type="hidden" class="url_order" value="{% url 'topics:update_resource_order' %}" /> |
| 15 | 15 | ||
| 16 | <h4 class="pull-left list-group-item-heading"> | 16 | <h4 class="pull-left list-group-item-heading"> |
| 17 | - <a href="{% url resource.access_link resource.slug %}" class="resource_link" {% if resource.show_window %}target="_blank"{% endif %}> | ||
| 18 | - {{ resource }} | 17 | + <a href="{% url resource.access_link resource.slug %}" class="resource_link" > |
| 18 | + {{ resource.name }} | ||
| 19 | </a> | 19 | </a> |
| 20 | </h4> | 20 | </h4> |
| 21 | 21 |