diff --git a/comments/models.py b/comments/models.py index 08f03ec210edd4f2af2e593a0f76d4625712c3b8..f79e1b5269837ee86aa53f1b256a917bd02f99a7 100644 --- a/comments/models.py +++ b/comments/models.py @@ -243,13 +243,32 @@ class Comment(models.Model): # for Lists header = '<li><div class="flex-container">' header += '<div class="flex-whitebox0">' - header += 'Nr {{ id }}' - context = Context({'id': self.id}) + context = Context({}) text_cut = self.comment_text[:30] if len(self.comment_text) > 30: text_cut += '...' - context['id'] = self.id context['text_cut'] = text_cut + if self.submission is not None: + header += '<a href="/submission/{{ submission_id }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' + header += (' in submission on <a href="/submission/{{ submission_id }}" class="pubtitleli">' + + '{{ submission_title }}</a> by {{ submission_author_list }}</p>') + context['submission_id'] = self.submission.id + context['submission_title'] = self.submission.title + context['submission_author_list'] = self.submission.author_list + if self.commentary is not None: + header += '<a href="/commentary/{{ commentary_url }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' + header += (' in commentary on <a href="/commentary/{{ commentary_url }}" class="pubtitleli">' + + '{{ commentary_pub_title }}</a> by {{ commentary_author_list }}</p>') + context['commentary_url'] = self.commentary.arxiv_or_DOI_string + context['commentary_pub_title'] = self.commentary.pub_title + context['commentary_author_list'] = self.commentary.author_list + if self.thesislink is not None: + header += '<a href="/thesis/{{ thesislink_id }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' + header += (' in thesislink on <a href="/thesis/{{ thesislink_id }}" class="pubtitleli">' + + '{{ thesislink_title }}</a> by {{ thesislink_author }}</p>') + context['thesislink_id'] = self.thesis.link.id + context['thesislink_title'] = self.thesislink.title + context['thesislink_author'] = self.thesislink.author header += '</div></div></li>' template = Template(header) return template.render(context) diff --git a/scipost/forms.py b/scipost/forms.py index ebc730a16f56c16ab154177c887f3e324bac9d57..4948e85e87054cc9c59e25434b51c9415ab7aa83 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -150,12 +150,12 @@ class CreateGraphForm(forms.ModelForm): self.fields['description'].widget.attrs.update({'placeholder': 'Detailed description'}) -class GiveTeamGraphAccessForm(forms.Form): +class ManageTeamsForm(forms.Form): teams_with_access = forms.ModelMultipleChoiceField(queryset=None) def __init__(self, *args, **kwargs): contributor = kwargs.pop('contributor') - super(CreateGraphForm, self).__init__(*args, **kwargs) + super(ManageTeamsForm, self).__init__(*args, **kwargs) self.fields['teams_with_access'].queryset=Team.objects.filter(Q(leader=contributor) | Q(members__in=[contributor])) self.fields['teams_with_access'].widget.attrs.update({'placeholder': 'Team(s) to be given access rights:'}) diff --git a/scipost/models.py b/scipost/models.py index 677d17e8bba1a9dc08f22af92733ea4b4069b524..74a5071b1b121cf01bb600382b4b7f30d09905eb 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -302,6 +302,7 @@ class List(models.Model): def contents(self): context = Context({}) output = self.description + output += '<hr class="hr6"/>' emptylist = True if self.submissions.exists(): emptylist = False diff --git a/scipost/templates/scipost/graph.html b/scipost/templates/scipost/graph.html index 60a518c879ec099d996d70be62195ceab03db559..60406c2e988bb085256afaac226fffa95cde798a 100644 --- a/scipost/templates/scipost/graph.html +++ b/scipost/templates/scipost/graph.html @@ -33,22 +33,23 @@ text { <script> $(document).ready(function(){ + +$("#ManageTeamsForm").hide(); +$("#ManageTeamsFormButton").click(function(){ +$("#ManageTeamsForm").toggle(); +}); + $(".node_contents").hide(); $("#NodeForm").hide(); $("#LinkForm").hide(); + $("#NodeFormButton").click(function(){ $("#NodeForm").toggle(); -//$("#EditNodeForm").hide(); $("#LinkForm").hide(); }); -//$("#EditNodeFormButton").click(function(){ -//$("#NodeForm").hide(); -//$("#EditNodeForm").toggle(); -//$("#LinkForm").hide(); -//}); + $("#LinkFormButton").click(function(){ $("#NodeForm").hide(); -//$("#EditNodeForm").hide(); $("#LinkForm").toggle(); }); }); @@ -159,16 +160,19 @@ function transform(d) { <section> - <div id="graphic"></div> + <h1>Graph</h1> + {{ graph }} <div class="row"> - <div class="col-8"> - <h1>Graph</h1> - {{ graph }} - <br/> - {{ graph.contents }} - </div> - <div class="col-2"> + <div class="col-3"> + {% if graph.private %} + <button id="ManageTeamsFormButton"><h1>Manage Team(s)</h1> (show/hide form)</button> + <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="ManageTeamsForm"> + {% csrf_token %} + {{ attach_teams_form }} + <input type="submit" value="Submit" /> + </form> + {% endif %} <button id="NodeFormButton"><h1>Add a Node</h1> (show/hide form)</button> <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="NodeForm"> {% csrf_token %} @@ -177,8 +181,6 @@ function transform(d) { </table> <input type="submit" value="Create Node" /> </form> - </div> - <div class="col-2"> <button id="LinkFormButton"><h1>Add a Link</h1> (show/hide form)</button> <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="LinkForm"> {% csrf_token %} @@ -188,12 +190,18 @@ function transform(d) { <input type="submit" value="Create Link" /> </form> </div> + <div class="col-9"> + <div id="graphic"></div> + </div> </div> <hr class="hr6"/> + <br/> + {{ graph.contents }} + {% for node in nodes %} {{ node.contents }} - <a href="{% url 'scipost:edit_graph_node' node_id=node.id %}" class="node_contents node_id{{ node.id}}">Edit this Node</a> + <a href="{% url 'scipost:edit_graph_node' node_id=node.id %}" class="node_contents node_id{{ node.id}}">Edit this Node's contents</a> {% endfor %} diff --git a/scipost/templates/scipost/list.html b/scipost/templates/scipost/list.html index 3396466bdb7df219046591fe10045f8ad49a1237..65859053e808b7927c596d9bae53f1e645781c34 100644 --- a/scipost/templates/scipost/list.html +++ b/scipost/templates/scipost/list.html @@ -14,9 +14,84 @@ {{ list.header }} + <hr class="hr6"/> <br/> {{ list.contents }} + <hr class="hr6"/> + + <h3>Add elements to this List</h3> + <form action="{% url 'scipost:list' list_id=list.id %}" method="post"> + {% csrf_token %} + <table> + {{ search_for_list_form.as_table }} + </table> + <input type="submit" name="Submit"> + </form> + + {% if search_for_list_form.has_changed %} + <h1>Search results</h1> + {% endif %} + + {% if commentary_search_list %} + <br /> + <hr class="hr12"> + <h3>Commentaries:</h3> + <ul> + {% for commentary in commentary_search_list %} + {{ commentary.header_as_li }} + <form action="{% url 'scipost:list_add_element' list_id=list.id type='C' element_id=commentary.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Add to List"/> + </form> + {% endfor %} + </ul> + {% endif %} + + {% if submission_search_list %} + <br /> + <hr class="hr12"> + <h3>Submissions:</h3> + <ul> + {% for submission in submission_search_list %} + {{ submission.header_as_li }} + <form action="{% url 'scipost:list_add_element' list_id=list.id type='S' element_id=submission.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Add to List"/> + </form> + {% endfor %} + </ul> + {% endif %} + + {% if thesislink_search_list %} + <br /> + <hr class="hr12"> + <h3>Theses:</h3> + <ul> + {% for thesislink in thesislink_search_list %} + {{ thesislink.header_as_li }} + <form action="{% url 'scipost:list_add_element' list_id=list.id type='T' element_id=thesislink.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Add to List"/> + </form> + {% endfor %} + </ul> + {% endif %} + + {% if comment_search_list %} + <br /> + <hr class="hr12"> + <h3>Comments:</h3> + <ul> + {% for comment in comment_search_list %} + {{ comment.header_as_li }} + <form action="{% url 'scipost:list_add_element' list_id=list.id type='c' element_id=comment.id %}" method="post"> + {% csrf_token %} + <input type="submit" value="Add to List"/> + </form> + {% endfor %} + </ul> + {% endif %} </section> diff --git a/scipost/templates/scipost/navbar.html b/scipost/templates/scipost/navbar.html index f38ed374531ebfe85475e3efa9eccc1effa533fe..5ae37434c4ae71682e3168b200b3c16d4a2421e5 100644 --- a/scipost/templates/scipost/navbar.html +++ b/scipost/templates/scipost/navbar.html @@ -20,11 +20,14 @@ {% endif %} </div> <div class="col-3"> + <!-- Temporary strip for online version --> + {% if user.is_authenticated %} <form action="{% url 'scipost:search' %}" method="post"> {% csrf_token %} {{ search_form }} <input type="submit" value="Search"/> </form> + {% endif %} </div> </div> </nav> diff --git a/scipost/urls.py b/scipost/urls.py index 5cc396ffc5e9cdc84c3530538b1249bb00c49042..50ed36f3069d04fb9c6fb89ea063b54a518c6b10 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -65,6 +65,7 @@ urlpatterns = [ # Lists 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'), # Feeds url(r'^latest_comment/feed/$', LatestCommentFeed()), diff --git a/scipost/views.py b/scipost/views.py index 70cb014e346d9315836b3ec82fc149c3441bb8e8..b0701f440c1b56a92086e1a9784cc164a159ee5b 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -64,23 +64,23 @@ def documentsSearchResults(query): author = query abstract_keyword = query commentary_search_list = Commentary.objects.filter( - pub_title__icontains=title_keyword, - author_list__icontains=author, - pub_abstract__icontains=abstract_keyword, + Q(pub_title__icontains=title_keyword) | + Q(author_list__icontains=author) | + Q(pub_abstract__icontains=abstract_keyword), vetted=True, ) commentary_search_list.order_by('-pub_date') submission_search_list = Submission.objects.filter( - title__icontains=title_keyword, - author_list__icontains=author, - abstract__icontains=abstract_keyword, + Q(title__icontains=title_keyword) | + Q(author_list__icontains=author) | + Q(abstract__icontains=abstract_keyword), status__gte=1, ) submission_search_list.order_by('-pub_date') thesislink_search_list = ThesisLink.objects.filter( - title__icontains=title_keyword, - author__icontains=author, - abstract__icontains=abstract_keyword, + Q(title__icontains=title_keyword) | + Q(author__icontains=author) | + Q(abstract__icontains=abstract_keyword), # supervisor__icontains=supervisor, vetted=True, ) @@ -677,13 +677,32 @@ def create_list(request): def list(request, list_id): list = get_object_or_404(List, pk=list_id) context = {'list': list} + if request.method == "POST": + search_for_list_form = SearchForm(request.POST) + if search_for_list_form.is_valid(): + context.update(documentsSearchResults(search_for_list_form.cleaned_data['query'])) + else: + search_for_list_form = SearchForm() + context.update({'search_for_list_form': search_for_list_form}) return render(request, 'scipost/list.html', context) @permission_required('scipost.can_create_list', raise_exception=True) -def add_list_element(request, list_id): +def list_add_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.add(commentary) + elif type == 'S': + submission = get_object_or_404(Submission, pk=element_id) + list.submissions.add(submission) + elif type == 'T': + thesislink = get_object_or_404(ThesisLink, pk=element_id) + list.thesislinks.add(thesislink) + elif type == 'c': + comment = get_object_or_404(Comment, pk=element_id) + list.comments.add(comment) + return redirect(reverse('scipost:list', kwargs={'list_id': list_id})) ######### @@ -758,27 +777,38 @@ def graph(request, graph_id): graph = get_object_or_404(Graph, pk=graph_id) nodes = Node.objects.filter(graph=graph) if request.method == "POST": + attach_teams_form = ManageTeamsForm(request.POST, + contributor=request.user.contributor, + initial={'teams_with_access': graph.teams_with_access.all()} + ) create_node_form = CreateNodeForm(request.POST) create_link_form = CreateLinkForm(request.POST, graph=graph) - if create_node_form.has_changed() and create_node_form.is_valid(): + if attach_teams_form.has_changed() and attach_teams_form.is_valid(): + graph.teams_with_access = attach_teams_form.cleaned_data['teams_with_access'] + graph.save() + elif create_node_form.has_changed() and create_node_form.is_valid(): newnode = Node(graph=graph, added_by=request.user.contributor, created=timezone.now(), name=create_node_form.cleaned_data['name'], description=create_node_form.cleaned_data['description']) newnode.save() - context = {'create_node_form': create_node_form, - 'create_link_form': create_link_form} - return redirect(reverse('scipost:graph', kwargs={'graph_id': graph.id}), context) +# context = {'create_node_form': create_node_form, +# 'create_link_form': create_link_form} +# return redirect(reverse('scipost:graph', kwargs={'graph_id': graph.id}), context) elif create_link_form.has_changed() and create_link_form.is_valid(): sourcenode = create_link_form.cleaned_data['source'] targetnode = create_link_form.cleaned_data['target'] targetnode.arcs_in.add(sourcenode) targetnode.save() else: + attach_teams_form = ManageTeamsForm(contributor=request.user.contributor, + initial={'teams_with_access': graph.teams_with_access.all()} + ) create_node_form = CreateNodeForm() create_link_form = CreateLinkForm(graph=graph) context = {'graph': graph, 'nodes': nodes, + 'attach_teams_form': attach_teams_form, 'create_node_form': create_node_form, 'create_link_form': create_link_form} return render(request, 'scipost/graph.html', context)