예제 #1
0
파일: models.py 프로젝트: swilde/OpenSlides
 def add(self, user, list_of_speakers, skip_autoupdate=False):
     """
     Customized manager method to prevent anonymous users to be on the
     list of speakers and that someone is twice on one list (off coming
     speakers). Cares also initial sorting of the coming speakers.
     """
     if isinstance(user, AnonymousUser):
         raise OpenSlidesError(
             "An anonymous user can not be on lists of speakers.")
     if self.filter(user=user,
                    list_of_speakers=list_of_speakers,
                    begin_time=None).exists():
         raise OpenSlidesError(
             f"{user} is already on the list of speakers.")
     if config["agenda_present_speakers_only"] and not user.is_present:
         raise OpenSlidesError(
             "Only present users can be on the lists of speakers.")
     weight = (self.filter(list_of_speakers=list_of_speakers).aggregate(
         models.Max("weight"))["weight__max"] or 0)
     speaker = self.model(list_of_speakers=list_of_speakers,
                          user=user,
                          weight=weight + 1)
     speaker.save(
         force_insert=True,
         skip_autoupdate=skip_autoupdate,
         no_delete_on_restriction=True,
     )
     return speaker
예제 #2
0
    def add(self, user, list_of_speakers, skip_autoupdate=False, point_of_order=False):
        """
        Customized manager method to prevent anonymous users to be on the
        list of speakers and that someone is twice on one list (off coming
        speakers). Cares also initial sorting of the coming speakers.
        """
        if isinstance(user, AnonymousUser):
            raise OpenSlidesError("An anonymous user can not be on lists of speakers.")

        if point_of_order and not config["agenda_enable_point_of_order_speakers"]:
            raise OpenSlidesError("Point of order speakers are not enabled.")

        if self.filter(
            user=user,
            list_of_speakers=list_of_speakers,
            begin_time=None,
            point_of_order=point_of_order,
        ).exists():
            raise OpenSlidesError(f"{user} is already on the list of speakers.")
        if config["agenda_present_speakers_only"] and not user.is_present:
            raise OpenSlidesError("Only present users can be on the lists of speakers.")

        weight = self._get_new_speaker_weight(list_of_speakers, point_of_order)

        speaker = self.model(
            list_of_speakers=list_of_speakers,
            user=user,
            weight=weight,
            point_of_order=point_of_order,
        )
        speaker.save(
            force_insert=True,
            skip_autoupdate=skip_autoupdate,
        )
        return speaker
예제 #3
0
 def add(self, person, item):
     if self.filter(person=person, item=item, begin_time=None).exists():
         raise OpenSlidesError(_(
             '%(person)s is already on the list of speakers of item %(id)s.')
             % {'person': person, 'id': item.id})
     if isinstance(person, AnonymousUser):
         raise OpenSlidesError(
             _('An anonymous user can not be on lists of speakers.'))
     weight = (self.filter(item=item).aggregate(
         models.Max('weight'))['weight__max'] or 0)
     return self.create(item=item, person=person, weight=weight + 1)
예제 #4
0
 def add(self, user, motion, skip_autoupdate=False):
     """
     Customized manager method to prevent anonymous users to be a
     submitter and that someone is not twice a submitter. Cares also
     for the initial sorting of the submitters.
     """
     if self.filter(user=user, motion=motion).exists():
         raise OpenSlidesError(f"{user} is already a submitter.")
     if isinstance(user, AnonymousUser):
         raise OpenSlidesError("An anonymous user can not be a submitter.")
     weight = (self.filter(motion=motion).aggregate(
         models.Max("weight"))["weight__max"] or 0)
     submitter = self.model(user=user, motion=motion, weight=weight + 1)
     submitter.save(force_insert=True, skip_autoupdate=skip_autoupdate)
     return submitter
예제 #5
0
 def add(self, user, item):
     """
     Customized manager method to prevent anonymous users to be on the
     list of speakers and that someone is twice on one list (off coming
     speakers). Cares also initial sorting of the coming speakers.
     """
     if self.filter(user=user, item=item, begin_time=None).exists():
         raise OpenSlidesError(
             _('{user} is already on the list of speakers.').format(user=user))
     if isinstance(user, AnonymousUser):
         raise OpenSlidesError(
             _('An anonymous user can not be on lists of speakers.'))
     weight = (self.filter(item=item).aggregate(
         models.Max('weight'))['weight__max'] or 0)
     return self.create(item=item, user=user, weight=weight + 1)
예제 #6
0
    def __init__(self,
                 request,
                 name,
                 html=None,
                 template=None,
                 context={},
                 permission_required=None,
                 display_name=None,
                 default_column=1):
        self.name = name
        if display_name is None:
            self.display_name = name.capitalize()
        else:
            self.display_name = display_name

        if html is not None:
            self.html = html
        elif template is not None:
            self.html = render_to_string(
                template_name=template,
                dictionary=context,
                context_instance=RequestContext(request))
        else:
            raise OpenSlidesError(
                'A Widget must have either a html or a template argument.')

        self.permission_required = permission_required
        self.default_column = default_column
예제 #7
0
 def add(self, user, item, skip_autoupdate=False):
     """
     Customized manager method to prevent anonymous users to be on the
     list of speakers and that someone is twice on one list (off coming
     speakers). Cares also initial sorting of the coming speakers.
     """
     if self.filter(user=user, item=item, begin_time=None).exists():
         raise OpenSlidesError(
             f"{user} is already on the list of speakers.")
     if isinstance(user, AnonymousUser):
         raise OpenSlidesError(
             "An anonymous user can not be on lists of speakers.")
     weight = (self.filter(item=item).aggregate(
         models.Max("weight"))["weight__max"] or 0)
     speaker = self.model(item=item, user=user, weight=weight + 1)
     speaker.save(force_insert=True, skip_autoupdate=skip_autoupdate)
     return speaker
예제 #8
0
    def get_prep_value(self, value):
        """
        Convert a person object to a string, to store it in the database.
        """
        if value is None:
            # For Fields with null=True
            return None
        elif isinstance(value, basestring):
            # The object is already a a person_id
            return value

        elif hasattr(value, 'person_id'):
            # The object is a person
            return value.person_id
        else:
            OpenSlidesError('%s (%s) is no person' % (value, type(value)))
예제 #9
0
 def delete(self, *args, **kwargs):
     raise OpenSlidesError('The VotingController object cannot be deleted.')
예제 #10
0
 def delete(self, *args, **kwargs):
     raise OpenSlidesError('The AuthorizedVoters object cannot be deleted.')