Commit 9b77857e authored by Felix Schlösser / TinTin's avatar Felix Schlösser / TinTin
Browse files

made sure agenda item sort order and motion are uniqure per meeting

parent d8f028cc
Pipeline #145388 failed with stages
in 9 seconds
......@@ -9,7 +9,6 @@ class AstaDecisionAdmin(admin.ModelAdmin):
pass
@admin.register(BoardDecision)
class BoardDecisionAdmin(admin.ModelAdmin):
pass
......
......@@ -13,14 +13,14 @@ from datetime import datetime, timedelta
class DecisionManager(models.Manager):
def create_decision(self, meeting, motion, has_passed, note=None):
def create_decision(self, agenda_item, has_passed, note=None):
if has_passed:
voting_result = AbstractDecision.VOTING_RESULT_CHOICES["ACCEPTED"]
else:
voting_result = AbstractDecision.VOTING_RESULT_CHOICES["REJECTED"]
decision = self.create(
underlying_motion=motion, voting_result=voting_result, note=note
agenda_item=agenda_item, voting_result=voting_result, note=note
)
return decision
......@@ -49,7 +49,7 @@ class AbstractDecision(TimeStampedModel):
abstract = True
def __str__(self):
return f"{ self.created.strftime('%x') }: { self.underlying_motion.title } "
return f"{ self.created.strftime('%x') }: { self.motion.title } "
@property
def motion(self):
......
......@@ -3,17 +3,18 @@ from django.contrib import admin
from .models import *
# Register your models here.
@admin.register(AstaMeeting)
class AStAMeetingAdmin(admin.ModelAdmin):
pass
list_display = ("date", "legislative_period")
@admin.register(BoardMeeting)
class BoardMeetingAdmin(admin.ModelAdmin):
pass
list_display = ("date", "legislative_period")
@admin.register(ExtendedBoardMeeting)
class ExtendedBoardMeetingAdmin(admin.ModelAdmin):
pass
list_display = ("date", "legislative_period")
@admin.register(AgendaItem)
......@@ -39,9 +40,9 @@ class RoomAdmin(admin.ModelAdmin):
@admin.register(Format)
class FormatAdmin(admin.ModelAdmin):
pass
list_display = ('room', 'video_conference_room', 'is_favorite')
@admin.register(VideoConferenceRoom)
class VideoConferenceRoomAdmin(admin.ModelAdmin):
pass
......@@ -10,7 +10,7 @@ from model_utils.models import TimeStampedModel
from model_utils.managers import InheritanceManager
from datetime import datetime, timedelta, date, time
import logging
from meeting_transparency.motions.models import Motion
from meeting_transparency.decisions.models import (
......@@ -197,7 +197,7 @@ class LegislativePeriod(models.Model):
ordering = ["begin"]
constraints = [
models.CheckConstraint(
name="begin_befor_end",
name="period_begin_befor_end",
check=models.Q(begin__lte=models.F("end")),
),
]
......@@ -326,6 +326,9 @@ class AbstractMeeting(TimeStampedModel):
verbose_name=_("Legislaturperiode"),
default=LegislativePeriod.get_current,
)
minutes_link = models.URLField(
blank=True, null=True, verbose_name=_("Link zum Protokoll")
)
format = models.ForeignKey(
Format,
......@@ -360,7 +363,17 @@ class AbstractMeeting(TimeStampedModel):
"legislative_period": "",
}
)
motion_list = []
motion_set = set()
for item in self.agenda_items.all():
motion_set.add(item.motion)
motion_list.append(item.motion)
if len(motion_set) != len(motion_list):
raise ValidationError(
_(f"Die einzelnen Tagesordnungspunkt müssen verschieden sein."),
code="agenda-items-unique",
)
@property
def begin_time(self):
......@@ -429,10 +442,13 @@ class AstaMeeting(AbstractMeeting):
next_meeting = AstaMeeting.objects.filter(date__lte=today).first()
return next_meeting
@property
def agenda_items(self):
return self._agendaitems
class BoardMeeting(AbstractMeeting):
pass
pass
class Meta(AbstractMeeting.Meta):
verbose_name = _("Vorstandssitzung")
......@@ -462,6 +478,9 @@ class BoardMeeting(AbstractMeeting):
next_meeting = BoardMeeting.objects.filter(date__lte=today).first()
return next_meeting
@property
def agenda_items(self):
return self._boardmeetingagedaitems
class ExtendedBoardMeeting(AbstractMeeting):
......@@ -495,34 +514,28 @@ class ExtendedBoardMeeting(AbstractMeeting):
next_meeting = ExtendedBoardMeeting.objects.filter(date__lte=today).first()
return next_meeting
@property
def agenda_items(self):
return self._extendedboardmeetingagendaitems
class AgendaItem(TimeStampedModel):
class AbstractAgendaItem(TimeStampedModel):
sort_order = models.IntegerField(
default=0,
verbose_name=_("Stelle in der Reihenfolge"),
)
meeting = models.ForeignKey(
AstaMeeting,
default=AstaMeeting.get_next,
related_name="%(class)ss",
on_delete=models.CASCADE,
verbose_name=_("Sitzung"),
verbose_name=_("Reihenfolge"),
)
motion = models.ForeignKey(
'motions.Motion',
"motions.Motion",
related_name="%(class)ss",
on_delete=models.PROTECT,
limit_choices_to=(models.Q(_status="OPEN") | models.Q(_status="CHANGED")),
verbose_name=_("Antrag")
verbose_name=_("Antrag"),
)
objects = InheritanceManager()
class Meta:
ordering = ["meeting", "sort_order"]
verbose_name = _("Tagesordnungspunkt")
verbose_name_plural = _("Tagesordnungspunkte")
abstract = True
def __str__(self):
return f"TOP { self.sort_order }: { self.motion.title }"
......@@ -532,40 +545,90 @@ class AgendaItem(TimeStampedModel):
return self.motion
def vote(self, has_passed, note=None):
decision = AstaDecision.objects.create_decision(
self.meeting, self.motion, has_passed, note
)
return decision
def clean(self):
motion_list = []
for item in self.meeting.agenda_items.all():
motion_list.append(item.motion)
old_motion_list = motion_list.copy()
previous_motion = self.meeting.agenda_items.filter(id=self.id).get().motion
motion_list.remove(previous_motion)
motion_list.append(self.motion)
motion_set = set(motion_list)
if len(motion_set) != len(old_motion_list):
# dublicate = [motion for motion in motion_list if motion_list.count(motion) > 1][0]
raise ValidationError(
{'motion': _("Die einzelnen Tagesordnungspunkte einer Sitzung müssen verschieden sein.")}
)
sort_order_list = []
for item in self.meeting.agenda_items.all():
sort_order_list.append(item.sort_order)
old_sort_order_list = sort_order_list.copy()
previous_sort_order = self.meeting.agenda_items.filter(id=self.id).get().sort_order
sort_order_list.remove(previous_sort_order)
sort_order_list.append(self.sort_order)
sort_order_set = set(sort_order_list)
if len(sort_order_set) != len(sort_order_list):
# dublicate = [motion for motion in motion_list if motion_list.count(motion) > 1][0]
logging.error(sort_order_list)
raise ValidationError(
{'sort_order': _("Die Orginalzahlen der Tagesordnungspunkte einer Sitzung müssen verschieden sein.")}
)
class AgendaItem(AbstractAgendaItem):
meeting = models.ForeignKey(
AstaMeeting,
default=AstaMeeting.get_next,
related_name="_%(class)ss",
on_delete=models.CASCADE,
verbose_name=_("Sitzung"),
)
class Meta(AbstractAgendaItem.Meta):
verbose_name = _("Tagesordnungspunkt")
verbose_name_plural = _("Tagesordnungspunkte")
def vote(self, has_passed, note=None):
decision = AstaDecision.objects.create_decision(self, has_passed, note)
return decision
class BoardMeetingAgendaItem(AgendaItem):
pass
class BoardMeetingAgendaItem(AbstractAgendaItem):
meeting = models.ForeignKey(
BoardMeeting,
default=BoardMeeting.get_next,
related_name="_%(class)ss",
on_delete=models.CASCADE,
verbose_name=_("Sitzung"),
)
class Meta(AgendaItem.Meta):
class Meta(AbstractAgendaItem.Meta):
verbose_name = _("Tagesordnungspunkt (Vorstandssitzung)")
verbose_name_plural = _("Tagesordnungspunkte (Vorstandssitzung)")
def vote(self, has_passed, note=None):
decision = AstaDecision.objects.create_decision(
self.meeting, self.motion, has_passed, note
)
decision = BoardDecision.objects.create_decision(self, has_passed, note)
return decision
class ExtendedBoardMeetingAgendaItem(AgendaItem):
pass
class ExtendedBoardMeetingAgendaItem(AbstractAgendaItem):
meeting = models.ForeignKey(
ExtendedBoardMeeting,
default=BoardMeeting.get_next,
related_name="_%(class)ss",
on_delete=models.CASCADE,
verbose_name=_("Sitzung"),
)
class Meta(AgendaItem.Meta):
class Meta(AbstractAgendaItem.Meta):
verbose_name = _("Tagesordnungspunkt (erweiterte Vorstandssitzung)")
verbose_name_plural = _("Tagesordnungspunkte (erweiterte Vorstandssitzung)")
def vote(self, has_passed, note=None):
decision = AstaDecision.objects.create_decision(
self.meeting, self.motion, has_passed, note
)
decision = ExtendedBoardDecision.objects.create_decision(self, has_passed, note)
return decision
......@@ -7,3 +7,8 @@ from .models import *
@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
pass
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
pass
from django.db import models
from django.utils.translation import gettext_lazy as _
# Create your models here.
class Group(models.Model):
name = models.CharField(max_length=64)
class Meta:
ordering = ['name']
verbose_name = _("Gruppe")
verbose_name_plural = _("Gruppen")
def __str__(self):
return self.name
class Person(models.Model):
name = models.CharField(max_length=256)
is_asta_member = models.BooleanField()
is_asta_board_member = models.BooleanField()
name = models.CharField(max_length=256)
email = models.EmailField(max_length=256)
groups = models.ManyToManyField(Group, verbose_name="Gruppe(n)")
is_asta_member = models.BooleanField(default=False)
is_asta_board_member = models.BooleanField(default=False)
class Meta:
ordering = ['is_asta_board_member', 'is_asta_member', 'name']
verbose_name = _("Person")
verbose_name_plural = _("Personen")
def __str__(self):
return self.name
class Meta:
ordering = ['is_asta_board_member', 'is_asta_member']
verbose_name = _("Person")
verbose_name_plural = _("Personen")
def __str__(self):
return self.name
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment