From 26a7514668776263c30b28f02338e423f4016901 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Thu, 21 Apr 2016 08:38:57 +0200 Subject: [PATCH] Quick tour now visible; allow removing items from Lists --- scipost/models.py | 2 +- scipost/templates/scipost/list.html | 6 +- scipost/templates/scipost/list_contents.html | 85 ++++++++++++++++++++ scipost/templates/scipost/quick_tour.html | 6 -- scipost/urls.py | 1 + scipost/views.py | 18 +++++ 6 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 scipost/templates/scipost/list_contents.html diff --git a/scipost/models.py b/scipost/models.py index 70043eb9e..b11f9dfa1 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -304,7 +304,7 @@ class List(models.Model): def contents(self): context = Context({}) - output = self.description + output = '<p>' + self.description + '</p>' output += '<hr class="hr6"/>' emptylist = True if self.submissions.exists(): diff --git a/scipost/templates/scipost/list.html b/scipost/templates/scipost/list.html index 61a2d56fa..64ce0dcf0 100644 --- a/scipost/templates/scipost/list.html +++ b/scipost/templates/scipost/list.html @@ -12,14 +12,14 @@ <section> <h1>List detail</h1> - {{ list.header }} - <hr class="hr6"/> <br/> - {{ list.contents }} {% load guardian_tags %} {% get_obj_perms request.user for list as "list_perms" %} + + {% include 'scipost/list_contents.html' %} + {% if "change_list" in list_perms %} <hr class="hr6"/> diff --git a/scipost/templates/scipost/list_contents.html b/scipost/templates/scipost/list_contents.html new file mode 100644 index 000000000..b508f95cd --- /dev/null +++ b/scipost/templates/scipost/list_contents.html @@ -0,0 +1,85 @@ + +{% if not "change_list" in list_perms %} + +{{ list.contents }} + +{% else %} + +<p>Description: +<p>{{ list.description }}</p> +</p> + + +<hr class="hr6"/> + +{% if list.submissions.exists or list.commentaries.exists or list.thesislinks.exists or list.comments.exists %} + +{% if list.submissions.exists %} +<p>Submissions: + <ul> + {% for sub in list.submissions.all %} + {{ sub.simple_header_as_li }} + {% if "change_list" in list_perms %} + <form action="{% url 'scipost:list_remove_element' list_id=list.id type='S' element_id=sub.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Remove from List"/> + </form> + {% endif %} + {% endfor %} + </ul> +</p> +{% endif %} + +{% if list.commentaries.exists %} +<p>Commentaries: + <ul> + {% for com in list.commentaries.all %} + {{ com.simple_header_as_li }} + {% if "change_list" in list_perms %} + <form action="{% url 'scipost:list_remove_element' list_id=list.id type='C' element_id=com.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Remove from List"/> + </form> + {% endif %} + {% endfor %} + </ul> +</p> +{% endif %} + +{% if list.thesislinks.exists %} +<p>Thesis links: + <ul> + {% for tl in list.thesislinks.all %} + {{ tl.simple_header_as_li }} + {% if "change_list" in list_perms %} + <form action="{% url 'scipost:list_remove_element' list_id=list.id type='T' element_id=tl.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Remove from List"/> + </form> + {% endif %} + {% endfor %} + </ul> +</p> +{% endif %} + +{% if list.comments.exists %} +<p>Comments: + <ul> + {% for comment in list.comments.all %} + {{ comment.simple_header_as_li }} + {% if "change_list" in list_perms %} + <form action="{% url 'scipost:list_remove_element' list_id=list.id type='c' element_id=comment.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Remove from List"/> + </form> + {% endif %} + {% endfor %} + </ul> +</p> +{% endif %} + +{% else %} +<br/><h3>This List is empty.</h3> +{% endif %} + +{% endif %} diff --git a/scipost/templates/scipost/quick_tour.html b/scipost/templates/scipost/quick_tour.html index 495aee0d7..5ed6ad75b 100644 --- a/scipost/templates/scipost/quick_tour.html +++ b/scipost/templates/scipost/quick_tour.html @@ -6,9 +6,6 @@ {% block bodysup %} -<!-- Temporary strip for online version --> -{% if user.is_authenticated %} - <section> <div class="flex-greybox"> @@ -48,7 +45,4 @@ </section> - -{% endif %} <!-- temporary strip --> - {% endblock bodysup %} diff --git a/scipost/urls.py b/scipost/urls.py index 768db3895..9a64dc3c5 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -64,6 +64,7 @@ urlpatterns = [ url(r'^create_list$', views.create_list, name='create_list'), url(r'^list/(?P<list_id>[0-9]+)$', views.list, name='list'), url(r'^list_add_element/(?P<list_id>[0-9]+)/(?P<type>[SCTc])/(?P<element_id>[0-9]+)$', views.list_add_element, name='list_add_element'), + url(r'^list_remove_element/(?P<list_id>[0-9]+)/(?P<type>[SCTc])/(?P<element_id>[0-9]+)$', views.list_remove_element, name='list_remove_element'), # Feeds url(r'^latest_comment/feed/$', LatestCommentFeed()), diff --git a/scipost/views.py b/scipost/views.py index a9291fae5..33d687c15 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -767,6 +767,24 @@ def list_add_element(request, list_id, type, element_id): return redirect(reverse('scipost:list', kwargs={'list_id': list_id})) +@permission_required_or_403('scipost.change_list', (List, 'id', 'list_id')) +def list_remove_element(request, list_id, type, element_id): + list = get_object_or_404(List, pk=list_id) + if type == 'C': + commentary = get_object_or_404(Commentary, pk=element_id) + list.commentaries.remove(commentary) + elif type == 'S': + submission = get_object_or_404(Submission, pk=element_id) + list.submissions.remove(submission) + elif type == 'T': + thesislink = get_object_or_404(ThesisLink, pk=element_id) + list.thesislinks.remove(thesislink) + elif type == 'c': + comment = get_object_or_404(Comment, pk=element_id) + list.comments.remove(comment) + return redirect(reverse('scipost:list', kwargs={'list_id': list_id})) + + ######### # Teams # ######### -- GitLab