From 66ca3380ecdf4a04fc69ef8d4f90bd1af4b144a6 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sat, 21 Jan 2017 19:39:07 +0100 Subject: [PATCH] DO MIGRATE: add feedback to remark --- scipost/migrations/0037_remark_feedback.py | 21 ++++++++++ scipost/models.py | 2 + scipost/templates/scipost/VGM_detail.html | 48 ++++++++++++++-------- scipost/urls.py | 2 + scipost/views.py | 22 ++++++++++ 5 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 scipost/migrations/0037_remark_feedback.py diff --git a/scipost/migrations/0037_remark_feedback.py b/scipost/migrations/0037_remark_feedback.py new file mode 100644 index 000000000..2c07b7f72 --- /dev/null +++ b/scipost/migrations/0037_remark_feedback.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-01-21 18:22 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('scipost', '0036_feedback'), + ] + + operations = [ + migrations.AddField( + model_name='remark', + name='feedback', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='scipost.Feedback'), + ), + ] diff --git a/scipost/models.py b/scipost/models.py index ed76709b1..21e846774 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -349,6 +349,8 @@ class UnavailabilityPeriod(models.Model): class Remark(models.Model): contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) + feedback = models.ForeignKey('scipost.Feedback', on_delete=models.CASCADE, + blank=True, null=True) nomination = models.ForeignKey('scipost.Nomination', on_delete=models.CASCADE, blank=True, null=True) motion = models.ForeignKey('scipost.Motion', on_delete=models.CASCADE, diff --git a/scipost/templates/scipost/VGM_detail.html b/scipost/templates/scipost/VGM_detail.html index a1e423d0f..c0ea0e248 100644 --- a/scipost/templates/scipost/VGM_detail.html +++ b/scipost/templates/scipost/VGM_detail.html @@ -76,6 +76,22 @@ $(document).ready(function(){ <ul> {% for feedback in feedback_received %} <li>{{ feedback.as_li }}</li> + <button class="submitRemarkButton" id="remarkButton{{ nomination.id }}">Add a remark on this Feedback</button> + <div class="submitRemarkForm" id="remarkForm{{ feedback.id }}"> + <form action="{% url 'scipost:add_remark_on_feedback' VGM_id=VGM.id feedback_id=feedback.id %}" method="post"> + {% csrf_token %} + {{ remark_form.as_p }} + <input type="submit" value="Submit" /> + </form> + </div> + {% if feedback.remark_set.all %} + <h3>Remarks on this feedback:</h3> + <ul> + {% for rem in feedback.remark_set.all %} + {{ rem.as_li }} + {% endfor %} + </ul> + {% endif %} {% endfor %} </ul> </div> @@ -144,14 +160,6 @@ $(document).ready(function(){ {% endif %} </div> <br/><br/> - {% if nomination.remark_set.all %} - <h3>Remarks on this nomination:</h3> - <ul> - {% for rem in nomination.remark_set.all %} - {{ rem.as_li }} - {% endfor %} - </ul> - {% endif %} <button class="submitRemarkButton" id="remarkButton{{ nomination.id }}">Add a remark on this Nomination</button> <div class="submitRemarkForm" id="remarkForm{{ nomination.id }}"> <form action="{% url 'scipost:add_remark_on_nomination' VGM_id=VGM.id nomination_id=nomination.id %}" method="post"> @@ -160,6 +168,14 @@ $(document).ready(function(){ <input type="submit" value="Submit" /> </form> </div> + {% if nomination.remark_set.all %} + <h3>Remarks on this nomination:</h3> + <ul> + {% for rem in nomination.remark_set.all %} + {{ rem.as_li }} + {% endfor %} + </ul> + {% endif %} <hr class="hr6"/> <br/> </li> @@ -232,14 +248,6 @@ $(document).ready(function(){ {% endif %} </div> <br/><br/> - {% if motion.remark_set.all %} - <h3>Remarks on this motion:</h3> - <ul> - {% for rem in motion.remark_set.all %} - {{ rem.as_li }} - {% endfor %} - </ul> - {% endif %} <button class="submitRemarkButton" id="remarkButton{{ motion.id }}">Add a remark on this Motion</button> <div class="submitRemarkForm" id="remarkForm{{ motion.id }}"> <form action="{% url 'scipost:add_remark_on_motion' motion_id=motion.id %}" method="post"> @@ -248,6 +256,14 @@ $(document).ready(function(){ <input type="submit" value="Submit" /> </form> </div> + {% if motion.remark_set.all %} + <h3>Remarks on this motion:</h3> + <ul> + {% for rem in motion.remark_set.all %} + {{ rem.as_li }} + {% endfor %} + </ul> + {% endif %} <hr class="hr6"/> <br/> </li> diff --git a/scipost/urls.py b/scipost/urls.py index 7e50c2ed9..e3b8c5731 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -179,6 +179,8 @@ urlpatterns = [ url(r'^VGM/(?P<VGM_id>[0-9]+)/$', views.VGM_detail, name='VGM_detail'), url(r'^feedback/(?P<VGM_id>[0-9]+)$', views.feedback, name='feedback'), + url(r'^add_remark_on_feedback/(?P<VGM_id>[0-9]+)/(?P<feedback_id>[0-9]+)$', + views.add_remark_on_feedback, name='add_remark_on_feedback'), url(r'^nominate_Fellow/(?P<VGM_id>[0-9]+)$', views.nominate_Fellow, name='nominate_Fellow'), url(r'^add_remark_on_nomination/(?P<VGM_id>[0-9]+)/(?P<nomination_id>[0-9]+)$', diff --git a/scipost/views.py b/scipost/views.py index 3e93b6948..da161739f 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -1530,6 +1530,28 @@ def feedback(request, VGM_id=None): return render(request, 'scipost/error.html', {'errormessage': errormessage}) +@permission_required('scipost.can_attend_VGMs', raise_exception=True) +def add_remark_on_feedback(request, VGM_id, feedback_id): + contributor = request.user.contributor + feedback = get_object_or_404(Feedback, pk=feedback_id) + if request.method == 'POST': + remark_form = RemarkForm(request.POST) + if remark_form.is_valid(): + remark = Remark(contributor=request.user.contributor, + feedback=feedback, + date=timezone.now(), + remark=remark_form.cleaned_data['remark']) + remark.save() + return HttpResponseRedirect('/VGM/' + str(VGM_id) + + '/#feedback_id' + str(feedback.id)) + else: + errormessage = 'The form was invalidly filled.' + return render(request, 'scipost/error.html', {'errormessage': errormessage}) + else: + errormessage = 'This view can only be posted to.' + return render(request, 'scipost/error.html', {'errormessage': errormessage}) + + @permission_required('scipost.can_attend_VGMs', return_403=True) def nominate_Fellow(request, VGM_id): VGM_instance = get_object_or_404(VGM, id=VGM_id) -- GitLab