Commit a02b60aa1eff77cdbf736e876c315f725f7fb61c
1 parent
fa5642a9
Exists in
master
and in
3 other branches
Adding subject specific mural page
Showing
5 changed files
with
177 additions
and
2 deletions
Show diff stats
@@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
1 | +{% extends 'subjects/view.html' %} | ||
2 | + | ||
3 | +{% load static i18n pagination permissions_tags subject_counter %} | ||
4 | +{% load django_bootstrap_breadcrumbs %} | ||
5 | + | ||
6 | +{% block breadcrumbs %} | ||
7 | + {{ block.super }} | ||
8 | + | ||
9 | + {% trans 'Mural' as mural %} | ||
10 | + | ||
11 | + {% breadcrumb mural 'mural:subject_view' subject.slug %} | ||
12 | +{% endblock %} | ||
13 | + | ||
14 | +{% block content %} | ||
15 | + {% subject_permissions request.user subject as has_subject_permissions %} | ||
16 | + | ||
17 | + {% if subject.visible %} | ||
18 | + <div class="panel panel-info subject-panel" id="subject_{{subject.slug}}"> | ||
19 | + <div class="panel-heading"> | ||
20 | + {% elif has_subject_permissions %} | ||
21 | + <div class="panel panel-info subject-panel-invisible" id="subject_{{subject.slug}}"> | ||
22 | + <div class="panel-heading panel-invisible"> | ||
23 | + {% endif %} | ||
24 | + <div class="row"> | ||
25 | + <div class="col-md-12 category-header"> | ||
26 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | ||
27 | + <span>{{subject.name}}</span> | ||
28 | + </h4> | ||
29 | + | ||
30 | + <div class="col-md-5 pull-right category-card-items"> | ||
31 | + {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} | ||
32 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
33 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
34 | + </a> | ||
35 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
36 | + {% if request.user not in subject.professor.all %} | ||
37 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
38 | + {% endif %} | ||
39 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
40 | + <li><a href="{% url 'groups:index' subject.slug %}"><i class="fa fa-group fa-fw" aria-hidden="true"></i>{% trans 'Groups' %}</a></li> | ||
41 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}?view=index','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
42 | + </ul> | ||
43 | + {% endif %} | ||
44 | + | ||
45 | + <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon"> | ||
46 | + <i class="fa fa-list" aria-hidden="true"></i> | ||
47 | + {% mural_number subject request.user %} | ||
48 | + </a> | ||
49 | + </div> | ||
50 | + </div> | ||
51 | + </div> | ||
52 | + </div> | ||
53 | + <div id="{{subject.slug}}" class="panel-collapse panel-body in collapse mural-ungeneral"> | ||
54 | + <div class="col-md-12 cards-content mural" data-url="{% url 'mural:subject_view' subject.slug %}" data-pages="{{ paginator.num_pages }}" data-page="{{ page_obj.number }}" data-fav="{{ favorites }}" data-mine="{{ mines }}"> | ||
55 | + <div class="col-md-9 col-sm-9 col-xs-9 mural-list"> | ||
56 | + <div class="post_make panel panel-default"> | ||
57 | + <div class="panel-body"> | ||
58 | + <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 user-img text-center"> | ||
59 | + <img src="{{ request.user.image_url }}" class="img-responsive" /> | ||
60 | + </div> | ||
61 | + <div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 post-field"> | ||
62 | + <div> | ||
63 | + <h4 data-url="{% url 'mural:create_subject' subject.slug %}">{% trans 'Wish to make a new post?' %}</h4> | ||
64 | + </div> | ||
65 | + </div> | ||
66 | + </div> | ||
67 | + </div> | ||
68 | + | ||
69 | + <div class="posts"> | ||
70 | + {% for post in posts %} | ||
71 | + {% include 'mural/_view.html' %} | ||
72 | + {% endfor %} | ||
73 | + </div> | ||
74 | + <div id="loading_posts" class="alert alert-success" role="alert" style="display:none"> | ||
75 | + <center> | ||
76 | + <span class="fa fa-spin fa-circle-o-notch"></span> | ||
77 | + </center> | ||
78 | + </div> | ||
79 | + <div class="text-center no-subjects" {% if posts.count > 0 %} style="display:none" {% endif %}> | ||
80 | + <i class="fa fa-list"></i> | ||
81 | + <h4>{% trans 'There are no posts in this mural yet.' %}</h4> | ||
82 | + </div> | ||
83 | + </div> | ||
84 | + <div class="col-md-3 col-sm-3 col-xs-3 post-filter"> | ||
85 | + <h4>{% trans 'Filter' %}</h4> | ||
86 | + | ||
87 | + <form id="post-filters" action="" method="GET"> | ||
88 | + <div class="checkbox"> | ||
89 | + <label> | ||
90 | + <input name="favorite" type="checkbox" {{ favorites }}> {% trans 'Favorite posts' %} <i class="fa fa-thumb-tack"></i> | ||
91 | + </label> | ||
92 | + </div> | ||
93 | + <div class="checkbox"> | ||
94 | + <label> | ||
95 | + <input name="mine" type="checkbox" {{ mines }}> {% trans 'Only my posts' %} | ||
96 | + </label> | ||
97 | + </div> | ||
98 | + <button type="submit" class="btn btn-success btn-raised btn-block">{% trans 'Filter' %}</button> | ||
99 | + <button type="button" id="clear_filter" class="btn btn-default btn-raised btn-block clear_filter">{% trans 'Clean Filters' %}</button> | ||
100 | + </form> | ||
101 | + </div> | ||
102 | + </div> | ||
103 | + </div> | ||
104 | + | ||
105 | + <div class="modal fade" id="post-modal-form" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div> | ||
106 | + | ||
107 | + <script type="text/javascript" src="{% static 'js/mural.js' %}"></script> | ||
108 | + <script type="text/javascript" src="{% static 'js/mural_general.js' %}"></script> | ||
109 | +{% endblock %} | ||
0 | \ No newline at end of file | 110 | \ No newline at end of file |
mural/urls.py
@@ -14,6 +14,7 @@ urlpatterns = [ | @@ -14,6 +14,7 @@ urlpatterns = [ | ||
14 | url(r'^delete_gen/(?P<pk>[\w_-]+)/$', views.GeneralDelete.as_view(), name='delete_general'), | 14 | url(r'^delete_gen/(?P<pk>[\w_-]+)/$', views.GeneralDelete.as_view(), name='delete_general'), |
15 | url(r'^delete_cat/(?P<pk>[\w_-]+)/$', views.CategoryDelete.as_view(), name='delete_category'), | 15 | url(r'^delete_cat/(?P<pk>[\w_-]+)/$', views.CategoryDelete.as_view(), name='delete_category'), |
16 | url(r'^delete_sub/(?P<pk>[\w_-]+)/$', views.SubjectDelete.as_view(), name='delete_subject'), | 16 | url(r'^delete_sub/(?P<pk>[\w_-]+)/$', views.SubjectDelete.as_view(), name='delete_subject'), |
17 | + url(r'^subject/(?P<slug>[\w_-]+)/$', views.SubjectView.as_view(), name='subject_view'), | ||
17 | url(r'^load_category/([\w_-]+)/$', views.load_category_posts, name='load_category'), | 18 | url(r'^load_category/([\w_-]+)/$', views.load_category_posts, name='load_category'), |
18 | url(r'^load_subject/([\w_-]+)/$', views.load_subject_posts, name='load_subject'), | 19 | url(r'^load_subject/([\w_-]+)/$', views.load_subject_posts, name='load_subject'), |
19 | url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), | 20 | url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), |
mural/views.py
@@ -719,6 +719,71 @@ class SubjectDelete(LoginRequiredMixin, generic.DeleteView): | @@ -719,6 +719,71 @@ class SubjectDelete(LoginRequiredMixin, generic.DeleteView): | ||
719 | 719 | ||
720 | return reverse_lazy('mural:deleted_post') | 720 | return reverse_lazy('mural:deleted_post') |
721 | 721 | ||
722 | +class SubjectView(LoginRequiredMixin, generic.ListView): | ||
723 | + login_url = reverse_lazy("users:login") | ||
724 | + redirect_field_name = 'next' | ||
725 | + | ||
726 | + template_name = 'mural/subject_view.html' | ||
727 | + context_object_name = "posts" | ||
728 | + paginate_by = 10 | ||
729 | + | ||
730 | + def get_queryset(self): | ||
731 | + user = self.request.user | ||
732 | + favorites = self.request.GET.get('favorite', False) | ||
733 | + mines = self.request.GET.get('mine', False) | ||
734 | + showing = self.request.GET.get('showing', False) | ||
735 | + page = self.request.GET.get('page', False) | ||
736 | + slug = self.kwargs.get('slug') | ||
737 | + subject = get_object_or_404(Subject, slug = slug) | ||
738 | + | ||
739 | + if not favorites: | ||
740 | + if mines: | ||
741 | + 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) | ||
742 | + else: | ||
743 | + 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) | ||
744 | + else: | ||
745 | + if mines: | ||
746 | + 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) | ||
747 | + else: | ||
748 | + 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) | ||
749 | + | ||
750 | + if showing: #Exclude ajax creation posts results | ||
751 | + showing = showing.split(',') | ||
752 | + posts = posts.exclude(id__in = showing) | ||
753 | + | ||
754 | + if not page: #Don't need this if is pagination | ||
755 | + MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space = subject) | Q(comment__post__subjectpost__space = subject))).update(viewed = True) | ||
756 | + | ||
757 | + return posts.order_by("-most_recent") | ||
758 | + | ||
759 | + def get_context_data(self, **kwargs): | ||
760 | + context = super(SubjectView, self).get_context_data(**kwargs) | ||
761 | + | ||
762 | + page = self.request.GET.get('page', '') | ||
763 | + | ||
764 | + slug = self.kwargs.get('slug', None) | ||
765 | + subject = get_object_or_404(Subject, slug = slug) | ||
766 | + | ||
767 | + if page: | ||
768 | + self.template_name = "mural/_list_view.html" | ||
769 | + | ||
770 | + context['title'] = _('%s - Mural')%(str(subject)) | ||
771 | + context['subject'] = subject | ||
772 | + context['favorites'] = "" | ||
773 | + context['mines'] = "" | ||
774 | + | ||
775 | + favs = self.request.GET.get('favorite', False) | ||
776 | + | ||
777 | + if favs: | ||
778 | + context['favorites'] = "checked" | ||
779 | + | ||
780 | + mines = self.request.GET.get('mine', False) | ||
781 | + | ||
782 | + if mines: | ||
783 | + context['mines'] = "checked" | ||
784 | + | ||
785 | + return context | ||
786 | + | ||
722 | """ | 787 | """ |
723 | Section for common post functions | 788 | Section for common post functions |
724 | """ | 789 | """ |
subjects/templates/subjects/subject_card.html
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | {% notifies_number subject request.user %} | 40 | {% notifies_number subject request.user %} |
41 | </a> | 41 | </a> |
42 | <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 42 | <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
43 | - <a href="" class="pull-right action_icon"> | 43 | + <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon"> |
44 | <i class="fa fa-list" aria-hidden="true"></i> | 44 | <i class="fa fa-list" aria-hidden="true"></i> |
45 | {% mural_number subject request.user %} | 45 | {% mural_number subject request.user %} |
46 | </a> | 46 | </a> |
subjects/templates/subjects/view.html
@@ -62,7 +62,7 @@ | @@ -62,7 +62,7 @@ | ||
62 | {% notifies_number subject request.user %} | 62 | {% notifies_number subject request.user %} |
63 | </a> | 63 | </a> |
64 | <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 64 | <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
65 | - <a href="" class="pull-right action_icon"> | 65 | + <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon"> |
66 | <i class="fa fa-list" aria-hidden="true"></i> | 66 | <i class="fa fa-list" aria-hidden="true"></i> |
67 | {% mural_number subject request.user %} | 67 | {% mural_number subject request.user %} |
68 | </a> | 68 | </a> |