From 23f487b49b26a4062db9f5075056e6a268021b97 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Mon, 1 Apr 2019 09:22:43 +0200 Subject: [PATCH] Temp command to transfer old motions to new forums-based ones. --- forums/templates/forums/forum_detail.html | 52 +++++++++++-------- forums/templates/forums/post_card.html | 2 +- .../commands/transfer_old_motion_to_new.py | 40 ++++++++++++++ 3 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 virtualmeetings/management/commands/transfer_old_motion_to_new.py diff --git a/forums/templates/forums/forum_detail.html b/forums/templates/forums/forum_detail.html index 6b1be878e..2d3d0626f 100644 --- a/forums/templates/forums/forum_detail.html +++ b/forums/templates/forums/forum_detail.html @@ -19,7 +19,7 @@ <div class="row"> <div class="col-12"> - <h3 class="highlight"> + <h2 class="highlight"> {% if forum.meeting %} {% with context_colors=forum.meeting.context_colors %} <span class="badge badge-{{ context_colors.bg }} mx-0 mb-2 p-2 text-{{ context_colors.text }}"> @@ -34,7 +34,7 @@ <a href="{{ forum.get_absolute_url }}">{{ forum }}</a> <span class="badge badge-primary badge-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span> </span> - </h3> + </h2> {% if forum.parent %} <p>Parent: <a href="{{ forum.parent.get_absolute_url }}">{{ forum.parent }}</a></p> @@ -92,39 +92,45 @@ {% endif %} - <h3>Table of Contents</h3> - <ul> - <li><a href="#Description">Description</a></li> - {% if forum.meeting %} - <li><a href="#Preamble">Preamble</a></li> - <li><a href="#Motions">Motions</a></li> - {% endif %} - <li><a href="#Posts">Posts</a></li> - {% if forum.meeting %} - <li><a href="#Minutes">Minutes</a></li> - {% endif %} - </ul> + <h2>Table of Contents</h2> + <div class="m-2"> + <ul> + <li><a href="#Description">Description</a></li> + {% if forum.meeting %} + <li><a href="#Preamble">Preamble</a></li> + <li><a href="#Motions">Motions</a></li> + {% endif %} + <li><a href="#Posts">Posts</a></li> + {% if forum.meeting %} + <li><a href="#Minutes">Minutes</a></li> + {% endif %} + </ul> + </div> </div> </div> <div class="row"> <div class="col-12"> - <h3 class="highlight" id="Description">Description</h3> - {{ forum.description|restructuredtext }} + <h2 class="highlight" id="Description">Description</h2> + <div class="m-2"> + {{ forum.descripteion|restructuredtext }} + </div> </div> </div> {% if forum.meeting %} <div class="row"> <div class="col-12"> - <h3 class="highlight" id="Preamble">Preamble</h3> - {{ forum.meeting.preamble|restructuredtext }} + <h2 class="highlight" id="Preamble">Preamble</h2> + <div class="m-2"> + {{ forum.meeting.preamble|restructuredtext }} + </div> </div> </div> <div class="row"> <div class="col-12"> - <h3 class="highlight" id="Motions">Motions</h3> + <h2 class="highlight" id="Motions">Motions</h2> <ul> {% if forum.meeting.future %} <li>Adding Motions will be activated once the meeting starts</li> @@ -143,7 +149,7 @@ <div class="row"> <div class="col-12"> - <h3 class="highlight" id="Posts">Posts</h3> + <h2 class="highlight" id="Posts">Posts</h2> <ul> <li><a href="{% url 'forums:post_create' slug=forum.slug parent_model='forum' parent_id=forum.id %}">Add a new Post</a></li> </ul> @@ -158,8 +164,10 @@ {% if forum.meeting %} <div class="row"> <div class="col-12"> - <h3 class="highlight" id="Minutes">Minutes</h3> - {{ forum.meeting.minutes|restructuredtext }} + <h2 class="highlight" id="Minutes">Minutes</h2> + <div class="m-2"> + {{ forum.meeting.minutes|restructuredtext }} + </div> </div> </div> {% endif %} diff --git a/forums/templates/forums/post_card.html b/forums/templates/forums/post_card.html index bafd6c12a..6abd15a0b 100644 --- a/forums/templates/forums/post_card.html +++ b/forums/templates/forums/post_card.html @@ -1,6 +1,6 @@ {% load restructuredtext %} -<div class="card m-1 {% if post.motion %}text-white bg-dark{% else %}text-body{% endif %}" id="post{{ post.id }}"> +<div class="card m-2 {% if post.motion %}text-white bg-dark{% else %}text-body{% endif %}" id="post{{ post.id }}"> <div class="card-header"> {{ post.subject }} <div class="postInfo"> diff --git a/virtualmeetings/management/commands/transfer_old_motion_to_new.py b/virtualmeetings/management/commands/transfer_old_motion_to_new.py new file mode 100644 index 000000000..e65b27169 --- /dev/null +++ b/virtualmeetings/management/commands/transfer_old_motion_to_new.py @@ -0,0 +1,40 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django.core.management.base import BaseCommand +from django.contrib.contenttypes.models import ContentType + +from virtualmeetings.models import Motion as deprec_Motion +from forums.models import Post, Motion + +class Command(BaseCommand): + help = ('Temporary method to transfer old virtualmeetings.Motions ' + 'to new forums.Motion ones.') + + def add_arguments(self, parser): + parser.add_argument( + '--old_pk', action='store', default=0, type=int, dest='old_pk', help='Old Motion id') + parser.add_argument( + '--new_pk', action='store', default=0, type=int, dest='new_pk', help='New Motion id') + + def handle(self, *args, **kwargs): + old_motion = deprec_Motion.objects.get(pk=kwargs['old_pk']) + new_motion = Motion.objects.get(pk=kwargs['new_pk']) + # Transfer the votes + for voter in old_motion.in_agreement.all(): + new_motion.in_agreement.add(voter.user) + for voter in old_motion.in_notsure.all(): + new_motion.in_doubt.add(voter.user) + for voter in old_motion.in_disagreement.all(): + new_motion.in_disagreement.add(voter.user) + # Transfer the old remarks to Post objects + type_motion = ContentType.objects.get_by_natural_key('forums', 'post') + for remark in old_motion.remarks.all(): + Post.objects.get_or_create( + posted_by=remark.contributor.user, + posted_on=remark.date, + parent_content_type=type_motion, + parent_object_id=new_motion.id, + subject='Remark', + text=remark.remark) -- GitLab