From 35aa36f88e3c1ed2fac88a29e3ea6ad1a1ef3a4e Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Mon, 22 Jun 2015 14:23:42 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"Added=20view=20to=20create=20related?= =?UTF-8?q?=20assignment=20and=20motion=20items.=20Updated=20ser=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openslides/assignments/serializers.py | 19 +++---------------- openslides/assignments/views.py | 20 -------------------- openslides/motions/serializers.py | 13 ------------- openslides/motions/views.py | 23 ----------------------- 4 files changed, 3 insertions(+), 72 deletions(-) diff --git a/openslides/assignments/serializers.py b/openslides/assignments/serializers.py index 72a776852..3effc730b 100644 --- a/openslides/assignments/serializers.py +++ b/openslides/assignments/serializers.py @@ -1,15 +1,12 @@ -from django.contrib.contenttypes.models import ContentType from django.db import transaction from django.utils.translation import ugettext as _ -from openslides.agenda.models import Item from openslides.utils.rest_api import ( DictField, IntegerField, ListField, ListSerializer, ModelSerializer, - SerializerMethodField, ValidationError, ) @@ -159,7 +156,6 @@ class AssignmentFullSerializer(ModelSerializer): """ Serializer for assignment.models.Assignment objects. With all polls. """ - agenda_items = SerializerMethodField() assignment_related_users = AssignmentRelatedUserSerializer(many=True, read_only=True) polls = AssignmentAllPollSerializer(many=True, read_only=True) @@ -174,22 +170,14 @@ class AssignmentFullSerializer(ModelSerializer): 'assignment_related_users', 'poll_description_default', 'polls', - 'tags', - 'agenda_items',) - - def get_agenda_items(self, obj): - """ - Returns a list of ids of all agenda items that are related to this - assignment. - """ - assignment_content_type = ContentType.objects.get_for_model(obj) - return (item.pk for item in Item.objects.filter(content_type=assignment_content_type, object_id=obj.pk)) + 'tags',) class AssignmentShortSerializer(AssignmentFullSerializer): """ Serializer for assignment.models.Assignment objects. Without unpublished poll. """ + assignment_related_users = AssignmentRelatedUserSerializer(many=True, read_only=True) polls = AssignmentShortPollSerializer(many=True, read_only=True) class Meta: @@ -203,5 +191,4 @@ class AssignmentShortSerializer(AssignmentFullSerializer): 'assignment_related_users', 'poll_description_default', 'polls', - 'tags', - 'agenda_items',) + 'tags',) diff --git a/openslides/assignments/views.py b/openslides/assignments/views.py index e53d5f6e5..f249df58e 100644 --- a/openslides/assignments/views.py +++ b/openslides/assignments/views.py @@ -15,7 +15,6 @@ from reportlab.platypus import ( TableStyle, ) -from openslides.agenda.models import Item from openslides.config.api import config from openslides.users.models import Group, User # TODO: remove this from openslides.utils.pdf import stylesheet @@ -214,25 +213,6 @@ class AssignmentViewSet(ModelViewSet): assignment.create_poll() return Response({'detail': _(' Poll created successfully.')}) - @detail_route(methods=['post']) - def create_agenda_item(self, request, pk=None): - """ - Speacial view endpoint to create an agenda item that is related to - this assignment. - """ - # Check permission. - if not request.user.has_perm('assignments.can_manage'): - self.permission_denied(request) - - # Retrieve motion. - assignment = self.get_object() - - # Create agenda item. - Item.objects.create(content_object=assignment) - - # Initiate response. - return Response({'detail': _('Agenda item successfully created.')}) - class AssignmentPollViewSet(UpdateModelMixin, DestroyModelMixin, GenericViewSet): """ diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index b78194004..e5ff3ccd5 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -1,15 +1,12 @@ -from django.contrib.contenttypes.models import ContentType from django.db import transaction from django.utils.translation import ugettext as _ -from openslides.agenda.models import Item from openslides.config.api import config from openslides.utils.rest_api import ( CharField, IntegerField, ModelSerializer, PrimaryKeyRelatedField, - SerializerMethodField, ValidationError, ) @@ -141,7 +138,6 @@ class MotionSerializer(ModelSerializer): Serializer for motion.models.Motion objects. """ active_version = PrimaryKeyRelatedField(read_only=True) - agenda_items = SerializerMethodField() log_messages = MotionLogSerializer(many=True, read_only=True) polls = MotionPollSerializer(many=True, read_only=True) reason = CharField(allow_blank=True, required=False, write_only=True) @@ -169,7 +165,6 @@ class MotionSerializer(ModelSerializer): 'workflow', 'tags', 'attachments', - 'agenda_items', 'polls', 'log_messages',) read_only_fields = ('parent',) # Some other fields are also read_only. See definitions above. @@ -233,11 +228,3 @@ class MotionSerializer(ModelSerializer): attr.add(*validated_data[key]) return motion - - def get_agenda_items(self, obj): - """ - Returns a list of ids of all agenda items that are related to this - motion. - """ - motion_content_type = ContentType.objects.get_for_model(obj) - return (item.pk for item in Item.objects.filter(content_type=motion_content_type, object_id=obj.pk)) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 22406fdad..8c8e06128 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -6,7 +6,6 @@ from django.utils.translation import ugettext_noop from reportlab.platypus import SimpleDocTemplate from rest_framework import status -from openslides.agenda.models import Item from openslides.config.api import config from openslides.utils.rest_api import ( ModelViewSet, @@ -245,28 +244,6 @@ class MotionViewSet(ModelViewSet): person=request.user) return Response({'detail': message}) - @detail_route(methods=['post']) - def create_agenda_item(self, request, pk=None): - """ - Speacial view endpoint to create an agenda item that is related to - this motion. - """ - # Check permission. - if not request.user.has_perm('motions.can_manage'): - self.permission_denied(request) - - # Retrieve motion. - motion = self.get_object() - - # Create agenda item. - Item.objects.create(content_object=motion) - - # Write the log message and initiate response. - motion.write_log( - message_list=[ugettext_noop('Agenda item created')], - person=request.user) - return Response({'detail': _('Agenda item successfully created.')}) - class PollPDFView(PDFView): """