From a02b60aa1eff77cdbf736e876c315f725f7fb61c Mon Sep 17 00:00:00 2001 From: Zambom Date: Sat, 18 Feb 2017 00:54:13 -0200 Subject: [PATCH] Adding subject specific mural page --- mural/templates/mural/subject_view.html | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mural/urls.py | 1 + mural/views.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ subjects/templates/subjects/subject_card.html | 2 +- subjects/templates/subjects/view.html | 2 +- 5 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 mural/templates/mural/subject_view.html diff --git a/mural/templates/mural/subject_view.html b/mural/templates/mural/subject_view.html new file mode 100644 index 0000000..458495c --- /dev/null +++ b/mural/templates/mural/subject_view.html @@ -0,0 +1,109 @@ +{% extends 'subjects/view.html' %} + +{% load static i18n pagination permissions_tags subject_counter %} +{% load django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + + {% trans 'Mural' as mural %} + + {% breadcrumb mural 'mural:subject_view' subject.slug %} +{% endblock %} + +{% block content %} + {% subject_permissions request.user subject as has_subject_permissions %} + + {% if subject.visible %} +
+
+ {% elif has_subject_permissions %} +
+
+ {% endif %} +
+
+

+ {{subject.name}} +

+ +
+ {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} + + + {% endif %} + + + + {% mural_number subject request.user %} + +
+
+
+
+
+
+
+
+
+
+ +
+
+
+

{% trans 'Wish to make a new post?' %}

+
+
+
+
+ +
+ {% for post in posts %} + {% include 'mural/_view.html' %} + {% endfor %} +
+ +
0 %} style="display:none" {% endif %}> + +

{% trans 'There are no posts in this mural yet.' %}

+
+
+
+

{% trans 'Filter' %}

+ +
+
+ +
+
+ +
+ + +
+
+
+
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/mural/urls.py b/mural/urls.py index c9962eb..7fb0791 100644 --- a/mural/urls.py +++ b/mural/urls.py @@ -14,6 +14,7 @@ urlpatterns = [ url(r'^delete_gen/(?P[\w_-]+)/$', views.GeneralDelete.as_view(), name='delete_general'), url(r'^delete_cat/(?P[\w_-]+)/$', views.CategoryDelete.as_view(), name='delete_category'), url(r'^delete_sub/(?P[\w_-]+)/$', views.SubjectDelete.as_view(), name='delete_subject'), + url(r'^subject/(?P[\w_-]+)/$', views.SubjectView.as_view(), name='subject_view'), url(r'^load_category/([\w_-]+)/$', views.load_category_posts, name='load_category'), url(r'^load_subject/([\w_-]+)/$', views.load_subject_posts, name='load_subject'), url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), diff --git a/mural/views.py b/mural/views.py index 4149048..cfb43c9 100644 --- a/mural/views.py +++ b/mural/views.py @@ -719,6 +719,71 @@ class SubjectDelete(LoginRequiredMixin, generic.DeleteView): return reverse_lazy('mural:deleted_post') +class SubjectView(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'mural/subject_view.html' + context_object_name = "posts" + paginate_by = 10 + + def get_queryset(self): + user = self.request.user + favorites = self.request.GET.get('favorite', False) + mines = self.request.GET.get('mine', False) + showing = self.request.GET.get('showing', False) + page = self.request.GET.get('page', False) + slug = self.kwargs.get('slug') + subject = get_object_or_404(Subject, slug = slug) + + if not favorites: + if mines: + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(mural_ptr__user = user, space = subject) + else: + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space = subject) + else: + if mines: + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user, space = subject) + else: + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(favorites_post__isnull = False, favorites_post__user = user, space = subject) + + if showing: #Exclude ajax creation posts results + showing = showing.split(',') + posts = posts.exclude(id__in = showing) + + if not page: #Don't need this if is pagination + MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space = subject) | Q(comment__post__subjectpost__space = subject))).update(viewed = True) + + return posts.order_by("-most_recent") + + def get_context_data(self, **kwargs): + context = super(SubjectView, self).get_context_data(**kwargs) + + page = self.request.GET.get('page', '') + + slug = self.kwargs.get('slug', None) + subject = get_object_or_404(Subject, slug = slug) + + if page: + self.template_name = "mural/_list_view.html" + + context['title'] = _('%s - Mural')%(str(subject)) + context['subject'] = subject + context['favorites'] = "" + context['mines'] = "" + + favs = self.request.GET.get('favorite', False) + + if favs: + context['favorites'] = "checked" + + mines = self.request.GET.get('mine', False) + + if mines: + context['mines'] = "checked" + + return context + """ Section for common post functions """ diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index b4b83a8..31e97a9 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -40,7 +40,7 @@ {% notifies_number subject request.user %} - + {% mural_number subject request.user %} diff --git a/subjects/templates/subjects/view.html b/subjects/templates/subjects/view.html index b28f99b..b8af93e 100644 --- a/subjects/templates/subjects/view.html +++ b/subjects/templates/subjects/view.html @@ -62,7 +62,7 @@ {% notifies_number subject request.user %} - + {% mural_number subject request.user %} -- libgit2 0.21.2