diff --git a/links/models.py b/links/models.py index 890472e..cc988bc 100644 --- a/links/models.py +++ b/links/models.py @@ -23,5 +23,14 @@ class Link(Resource): verbose_name_plural = "Links" def __str__(self): - pass + return self.name + + def access_link(self): + return 'links:view' + + def update_link(self): + return 'links:update' + + def delete_link(self): + return 'links:delete' \ No newline at end of file diff --git a/links/templates/links/delete.html b/links/templates/links/delete.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/links/templates/links/delete.html diff --git a/links/templates/links/update.html b/links/templates/links/update.html new file mode 100644 index 0000000..7104b04 --- /dev/null +++ b/links/templates/links/update.html @@ -0,0 +1,36 @@ +{% extends 'subjects/view.html' %} + +{% load static i18n django_bootstrap_breadcrumbs %} + +{% block style %} + {{block.super}} + +{% endblock %} + +{% block javascript %} + {{block.super}} + +{% endblock %} + +{% block breadcrumbs %} + {{ block.super }} + + {% breadcrumb topic 'subjects:topic_view' topic.subject.slug topic.slug %} + + {% trans 'Edit: ' as bread %} + {% with bread|add:link.name as bread_slug %} + {% breadcrumb bread_slug 'links:update' topic.slug link.slug %} + {% endwith %} +{% endblock %} + +{% block content %} +
+
+
+ {% include 'links/_form.html' %} +
+
+
+
+
+{% endblock %} diff --git a/links/urls.py b/links/urls.py index bd42049..c6857c4 100644 --- a/links/urls.py +++ b/links/urls.py @@ -4,4 +4,7 @@ from django.contrib.auth import views as auth_views from . import views urlpatterns = [ - url(r'^create/(?P[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'),] \ No newline at end of file + url(r'^create/(?P[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'), + url(r'^delete/(?P[\w_-]+)/$', views.DeleteLinkView.as_view(), name='delete'), + url(r'^update/(?P[\w_-]+)/(?P[\w_-]+)/$', views.UpdateLinkView.as_view(), name='update'), + url(r'^view/(?P[\w_-]+)/$', views.DetailLinkView.as_view(), name='view')] \ No newline at end of file diff --git a/links/views.py b/links/views.py index cb0bf0b..ffcf75d 100644 --- a/links/views.py +++ b/links/views.py @@ -20,119 +20,249 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission from topics.models import Topic # Create your views here. class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): - log_component = 'resources' - log_action = 'create' - log_resource = 'file_link' - log_context = {} + log_component = 'resources' + log_action = 'create' + log_resource = 'file_link' + log_context = {} - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - template_name = 'links/create.html' - form_class = LinkForm + template_name = 'links/create.html' + form_class = LinkForm - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - if not has_subject_permissions(request.user, topic.subject): - return redirect(reverse_lazy('subjects:home')) + if not has_subject_permissions(request.user, topic.subject): + return redirect(reverse_lazy('subjects:home')) - return super(CreateLinkView, self).dispatch(request, *args, **kwargs) + return super(CreateLinkView, self).dispatch(request, *args, **kwargs) - def get(self, request, *args, **kwargs): - self.object = None - - form_class = self.get_form_class() - form = self.get_form(form_class) + def get(self, request, *args, **kwargs): + self.object = None + + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) - def post(self, request, *args, **kwargs): - self.object = None - - form_class = self.get_form_class() - form = self.get_form(form_class) + def post(self, request, *args, **kwargs): + self.object = None + + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - - if (form.is_valid() and pendencies_form.is_valid()): - return self.form_valid(form, pendencies_form) - else: - return self.form_invalid(form, pendencies_form) + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + + if (form.is_valid() and pendencies_form.is_valid()): + return self.form_valid(form, pendencies_form) + else: + return self.form_invalid(form, pendencies_form) - def get_initial(self): - initial = super(CreateLinkView, self).get_initial() + def get_initial(self): + initial = super(CreateLinkView, self).get_initial() - slug = self.kwargs.get('slug', '') + slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) - initial['subject'] = topic.subject - - return initial + topic = get_object_or_404(Topic, slug = slug) + initial['subject'] = topic.subject + + return initial - def form_invalid(self, form, pendencies_form): - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + def form_invalid(self, form, pendencies_form): + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) - def form_valid(self, form, pendencies_form): - self.object = form.save(commit = False) + def form_valid(self, form, pendencies_form): + self.object = form.save(commit = False) - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - self.object.topic = topic - self.object.order = topic.resource_topic.count() + 1 + self.object.topic = topic + self.object.order = topic.resource_topic.count() + 1 - if not self.object.topic.visible and not self.object.topic.repository: - self.object.visible = False + if not self.object.topic.visible and not self.object.topic.repository: + self.object.visible = False - self.object.save() + self.object.save() - pend_form = pendencies_form.save(commit = False) - pend_form.resource = self.object - - if not pend_form.action == "": - pend_form.save() - - self.log_context['category_id'] = self.object.topic.subject.category.id - self.log_context['category_name'] = self.object.topic.subject.category.name - self.log_context['category_slug'] = self.object.topic.subject.category.slug - self.log_context['subject_id'] = self.object.topic.subject.id - self.log_context['subject_name'] = self.object.topic.subject.name - self.log_context['subject_slug'] = self.object.topic.subject.slug - self.log_context['topic_id'] = self.object.topic.id - self.log_context['topic_name'] = self.object.topic.name - self.log_context['topic_slug'] = self.object.topic.slug - self.log_context['link_id'] = self.object.id - self.log_context['link_name'] = self.object.name - self.log_context['link_slug'] = self.object.slug + pend_form = pendencies_form.save(commit = False) + pend_form.resource = self.object + + if not pend_form.action == "": + pend_form.save() + + self.log_context['category_id'] = self.object.topic.subject.category.id + self.log_context['category_name'] = self.object.topic.subject.category.name + self.log_context['category_slug'] = self.object.topic.subject.category.slug + self.log_context['subject_id'] = self.object.topic.subject.id + self.log_context['subject_name'] = self.object.topic.subject.name + self.log_context['subject_slug'] = self.object.topic.subject.slug + self.log_context['topic_id'] = self.object.topic.id + self.log_context['topic_name'] = self.object.topic.name + self.log_context['topic_slug'] = self.object.topic.slug + self.log_context['link_id'] = self.object.id + self.log_context['link_name'] = self.object.name + self.log_context['link_slug'] = self.object.slug - super(CreateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + super(CreateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - return redirect(self.get_success_url()) + return redirect(self.get_success_url()) - def get_context_data(self, **kwargs): - context = super(CreateLinkView, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(CreateLinkView, self).get_context_data(**kwargs) - context['title'] = _('Create Webiste Link') + context['title'] = _('Create Webiste Link') - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - context['topic'] = topic - context['subject'] = topic.subject + context['topic'] = topic + context['subject'] = topic.subject - return context + return context - def get_success_url(self): - 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)) + def get_success_url(self): + 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)) - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) \ No newline at end of file + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) + + + +class DeleteLinkView(LoginRequiredMixin, LogMixin, generic.edit.DeleteView): + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + model = Link + template_name = 'links/delete.html' + + +class DetailLinkView(LoginRequiredMixin, LogMixin, generic.detail.DetailView): + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + model = Link + template_name = 'links/view.html' + context_object_name = 'web_link' + +class UpdateLinkView(LoginRequiredMixin, LogMixin, generic.edit.UpdateView): + model = Link + form_class = LinkForm + template_name = 'links/update.html' + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + def dispatch(self, request, *args, **kwargs): + + + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) + + if not has_subject_permissions(request.user, topic.subject): + return redirect(reverse_lazy('subjects:home')) + + return super(UpdateLinkView, self).dispatch(request, *args, **kwargs) + + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + + form_class = self.get_form_class() + form = self.get_form(form_class) + + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) + + pend_form = self.object.pendencies_resource.all() + + if len(pend_form) > 0: + pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + else: + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + + def post(self, request, *args, **kwargs): + self.object = self.get_object() + + form_class = self.get_form_class() + form = self.get_form(form_class) + + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) + + pend_form = self.object.pendencies_resource.all() + + if len(pend_form) > 0: + pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + else: + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + + if (form.is_valid() and pendencies_form.is_valid()): + return self.form_valid(form, pendencies_form) + else: + return self.form_invalid(form, pendencies_form) + + def form_invalid(self, form, pendencies_form): + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + + def form_valid(self, form, pendencies_form): + self.object = form.save(commit = False) + + if not self.object.topic.visible and not self.object.topic.repository: + self.object.visible = False + + self.object.save() + + pend_form = pendencies_form.save(commit = False) + pend_form.resource = self.object + + if not pend_form.action == "": + pend_form.save() + + self.log_context['category_id'] = self.object.topic.subject.category.id + self.log_context['category_name'] = self.object.topic.subject.category.name + self.log_context['category_slug'] = self.object.topic.subject.category.slug + self.log_context['subject_id'] = self.object.topic.subject.id + self.log_context['subject_name'] = self.object.topic.subject.name + self.log_context['subject_slug'] = self.object.topic.subject.slug + self.log_context['topic_id'] = self.object.topic.id + self.log_context['topic_name'] = self.object.topic.name + self.log_context['topic_slug'] = self.object.topic.slug + self.log_context['link_id'] = self.object.id + self.log_context['link_name'] = self.object.name + self.log_context['link_slug'] = self.object.slug + + super(UpdateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + + return redirect(self.get_success_url()) + + def get_context_data(self, **kwargs): + context = super(UpdateLinkView, self).get_context_data(**kwargs) + + context['title'] = _('Update Website Link') + + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) + + context['topic'] = topic + context['subject'] = topic.subject + + return context + + def get_success_url(self): + messages.success(self.request, _('The Website Link "%s" was updated successfully!')%(self.object.name)) + + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) diff --git a/notifications/views.py b/notifications/views.py index 7f37e3e..2e74990 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -20,226 +20,226 @@ from .models import Notification from .utils import get_order_by, is_date class SubjectNotifications(LoginRequiredMixin, generic.ListView): - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - context_object_name = 'notifications' - template_name = 'notifications/subject.html' - paginate_by = 10 - total = 0 + context_object_name = 'notifications' + template_name = 'notifications/subject.html' + paginate_by = 10 + total = 0 - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - if not has_subject_view_permissions(request.user, subject): - return redirect(reverse_lazy('subjects:home')) + if not has_subject_view_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) - return super(SubjectNotifications, self).dispatch(request, *args, **kwargs) + return super(SubjectNotifications, self).dispatch(request, *args, **kwargs) - def get_queryset(self): - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + def get_queryset(self): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - 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") + 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") - self.total = notifications.count() + self.total = notifications.count() - return notifications + return notifications - def get_context_data(self, **kwargs): - context = super(SubjectNotifications, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(SubjectNotifications, self).get_context_data(**kwargs) - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - context['title'] = _('%s - Pendencies')%(subject.name) - context['subject'] = subject - context['total'] = self.total + context['title'] = _('%s - Pendencies')%(subject.name) + context['subject'] = subject + context['total'] = self.total - return context + return context class SubjectHistory(LoginRequiredMixin, generic.ListView): - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - context_object_name = 'notifications' - template_name = 'notifications/subject.html' - paginate_by = 10 - total = 0 - num_rows = 0 + context_object_name = 'notifications' + template_name = 'notifications/subject.html' + paginate_by = 10 + total = 0 + num_rows = 0 - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - if not has_subject_view_permissions(request.user, subject): - return redirect(reverse_lazy('subjects:home')) + if not has_subject_view_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) - return super(SubjectHistory, self).dispatch(request, *args, **kwargs) + return super(SubjectHistory, self).dispatch(request, *args, **kwargs) - def get_queryset(self): - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + def get_queryset(self): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - order = get_order_by(self.request.GET.get("order_by", None)) - search = self.request.GET.get("search", None) + order = get_order_by(self.request.GET.get("order_by", None)) + search = self.request.GET.get("search", None) - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) - self.total = notifications.filter(creation_date = datetime.now()).count() - - if search: - queries = Q(task__resource__name__icontains = search) - queries |= Q(task__action__icontains = search) + self.total = notifications.filter(creation_date = datetime.now()).count() + + if search: + queries = Q(task__resource__name__icontains = search) + queries |= Q(task__action__icontains = search) - if search.isdigit(): - queries |= Q(level = search) + if search.isdigit(): + queries |= Q(level = search) - if is_date(search): - search_date = parser.parse(search) - search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) + if is_date(search): + search_date = parser.parse(search) + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) - queries |= Q(creation_date = search_date) - queries |= Q(task__limit_date = search_date) - queries |= Q(task__end_date = search_date) - queries |= Q(meta__date = search_date) + queries |= Q(creation_date = search_date) + queries |= Q(task__limit_date = search_date) + queries |= Q(task__end_date = search_date) + queries |= Q(meta__date = search_date) - notifications = notifications.filter(queries).order_by(*order) + notifications = notifications.filter(queries).order_by(*order) - self.num_rows = notifications.count() + self.num_rows = notifications.count() - return notifications + return notifications - def get_context_data(self, **kwargs): - context = super(SubjectHistory, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(SubjectHistory, self).get_context_data(**kwargs) - slug = self.kwargs.get('slug', '') - subject = get_object_or_404(Subject, slug = slug) + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) - context['title'] = _('%s - Pendencies')%(subject.name) - context['subject'] = subject - context['history'] = True - context['total'] = self.total - context['rows'] = self.num_rows - context['searched'] = self.request.GET.get("search", "") + context['title'] = _('%s - Pendencies')%(subject.name) + context['subject'] = subject + context['history'] = True + context['total'] = self.total + context['rows'] = self.num_rows + context['searched'] = self.request.GET.get("search", "") - return context + return context class IndexView(LoginRequiredMixin, generic.ListView): - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - context_object_name = 'notifications' - template_name = 'notifications/index.html' - paginate_by = 10 + context_object_name = 'notifications' + template_name = 'notifications/index.html' + paginate_by = 10 - def get_queryset(self): - 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')) + def get_queryset(self): + 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')) - return notifications + return notifications - def get_context_data(self, **kwargs): - context = super(IndexView, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(IndexView, self).get_context_data(**kwargs) - context['title'] = _('Pendencies') + context['title'] = _('Pendencies') - return context + return context class AjaxNotifications(LoginRequiredMixin, generic.ListView): - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - context_object_name = 'notifications' - template_name = 'notifications/_view.html' + context_object_name = 'notifications' + template_name = 'notifications/_view.html' - def get_queryset(self): - subject_id = self.kwargs.get('id', '') - - 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") + def get_queryset(self): + subject_id = self.kwargs.get('id', '') + + 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") - return notifications + return notifications class AjaxHistory(LoginRequiredMixin, generic.ListView): - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - context_object_name = 'notifications' - template_name = 'notifications/_ajax_history.html' + context_object_name = 'notifications' + template_name = 'notifications/_ajax_history.html' - def get_queryset(self): - subject_id = self.kwargs.get('id', '') + def get_queryset(self): + subject_id = self.kwargs.get('id', '') - order = get_order_by(self.request.GET.get("order_by", None)) - search = self.request.GET.get("search", None) + order = get_order_by(self.request.GET.get("order_by", None)) + search = self.request.GET.get("search", None) - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id).order_by(*order) + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id).order_by(*order) - if search: - queries = Q(task__resource__name__icontains = search) - queries |= Q(task__action__icontains = search) + if search: + queries = Q(task__resource__name__icontains = search) + queries |= Q(task__action__icontains = search) - if search.isdigit(): - queries |= Q(level = search) + if search.isdigit(): + queries |= Q(level = search) - if is_date(search): - search_date = parser.parse(search) - search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) + if is_date(search): + search_date = parser.parse(search) + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) - queries |= Q(creation_date = search_date) - queries |= Q(task__limit_date = search_date) - queries |= Q(task__end_date = search_date) - queries |= Q(meta__date = search_date) + queries |= Q(creation_date = search_date) + queries |= Q(task__limit_date = search_date) + queries |= Q(task__end_date = search_date) + queries |= Q(meta__date = search_date) - notifications = notifications.filter(queries).order_by(*order) + notifications = notifications.filter(queries).order_by(*order) - self.num_rows = notifications.count() + self.num_rows = notifications.count() - return notifications + return notifications - def get_context_data(self, **kwargs): - context = super(AjaxHistory, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(AjaxHistory, self).get_context_data(**kwargs) - subject_id = self.kwargs.get('id', '') + subject_id = self.kwargs.get('id', '') - context['subject_id'] = subject_id - context['rows'] = self.num_rows - context['searched'] = self.request.GET.get("search", "") - context['order_by'] = self.request.GET.get("order_by", "") + context['subject_id'] = subject_id + context['rows'] = self.num_rows + context['searched'] = self.request.GET.get("search", "") + context['order_by'] = self.request.GET.get("order_by", "") - return context + return context @login_required def set_goal(request): - if request.method == "POST" and request.is_ajax(): - meta = request.POST.get('meta', None) + if request.method == "POST" and request.is_ajax(): + meta = request.POST.get('meta', None) - if not meta: - return JsonResponse({'error': True, 'message': _('No goal date received')}) + if not meta: + return JsonResponse({'error': True, 'message': _('No goal date received')}) - meta = parser.parse(meta) + meta = parser.parse(meta) - notify_id = request.POST.get('id', None) + notify_id = request.POST.get('id', None) - if not notify_id: - return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) + if not notify_id: + return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) - notification = get_object_or_404(Notification, id = notify_id) + notification = get_object_or_404(Notification, id = notify_id) - meta = timezone.make_aware(meta, timezone.get_current_timezone()) + meta = timezone.make_aware(meta, timezone.get_current_timezone()) - if meta < timezone.now(): - return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) + if meta < timezone.now(): + return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) - if meta.date() > notification.task.resource.topic.subject.end_date: - return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) + if meta.date() > notification.task.resource.topic.subject.end_date: + return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) - notification.meta = meta - notification.save() + notification.meta = meta + notification.save() - if notification.level == 2: - message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) - else: - message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + if notification.level == 2: + message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + else: + message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) - return JsonResponse({'error': False, 'message': message}) \ No newline at end of file + return JsonResponse({'error': False, 'message': message}) \ No newline at end of file diff --git a/topics/templates/resources/list.html b/topics/templates/resources/list.html index d49671c..8815e1e 100644 --- a/topics/templates/resources/list.html +++ b/topics/templates/resources/list.html @@ -14,8 +14,8 @@

- - {{ resource }} + + {{ resource.name }}

-- libgit2 0.21.2