Skip to content
Snippets Groups Projects
Verified Commit 819d1e4c authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add optional school year relation to group model

parent d75341a5
No related branches found
No related tags found
1 merge request!299Resolve "Link data to school term"
Pipeline #2582 failed
......@@ -121,10 +121,11 @@ class EditPersonForm(ExtensibleForm):
return PersonAccountForm.clean(self)
class EditGroupForm(ExtensibleForm):
class EditGroupForm(SchoolYearRelatedExtensibleForm):
"""Form to edit an existing group in the frontend."""
layout = Layout(
Fieldset(_("School year"), "school_year"),
Fieldset(_("Common data"), "name", "short_name", "group_type"),
Fieldset(_("Persons"), "members", "owners", "parent_groups"),
Fieldset(_("Additional fields"), "additional_fields"),
......@@ -169,7 +170,9 @@ class AnnouncementForm(ExtensibleForm):
persons = forms.ModelMultipleChoiceField(
Person.objects.all(), label=_("Persons"), required=False
)
groups = forms.ModelMultipleChoiceField(Group.objects.all(), label=_("Groups"), required=False)
groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.for_current_school_year_or_all(), label=_("Groups"), required=False
)
layout = Layout(
Fieldset(
......@@ -204,6 +207,8 @@ class AnnouncementForm(ExtensibleForm):
super().__init__(*args, **kwargs)
self.fields["groups"].queryset = Group.objects.for_current_school_year_or_all()
def clean(self):
data = super().clean()
......
# Generated by Django 3.0.6 on 2020-06-04 15:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0002_school_year'),
]
operations = [
migrations.AlterModelManagers(
name='group',
managers=[
],
),
migrations.AddField(
model_name='group',
name='school_year',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='core.SchoolYear', verbose_name='Linked school year'),
),
migrations.AlterField(
model_name='group',
name='name',
field=models.CharField(max_length=255, verbose_name='Long name'),
),
migrations.AlterField(
model_name='group',
name='short_name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Short name'),
),
migrations.AddConstraint(
model_name='group',
constraint=models.UniqueConstraint(fields=('school_year', 'name'), name='unique_school_year_name'),
),
migrations.AddConstraint(
model_name='group',
constraint=models.UniqueConstraint(fields=('school_year', 'short_name'),
name='unique_school_year_short_name'),
),
]
......@@ -305,7 +305,7 @@ class AdditionalField(ExtensibleModel):
verbose_name_plural = _("Addtitional fields for groups")
class Group(ExtensibleModel):
class Group(SchoolYearRelatedExtensibleModel):
"""Group model.
Any kind of group of persons in a school, including, but not limited
......@@ -317,10 +317,16 @@ class Group(ExtensibleModel):
verbose_name = _("Group")
verbose_name_plural = _("Groups")
permissions = (("assign_child_groups_to_groups", _("Can assign child groups to groups")),)
constraints = [
models.UniqueConstraint(fields=["school_year", "name"], name="unique_school_year_name"),
models.UniqueConstraint(
fields=["school_year", "short_name"], name="unique_school_year_short_name"
),
]
icon_ = "group"
name = models.CharField(verbose_name=_("Long name"), max_length=255, unique=True)
name = models.CharField(verbose_name=_("Long name"), max_length=255)
short_name = models.CharField(
verbose_name=_("Short name"), max_length=255, blank=True, null=True # noqa
)
......@@ -363,7 +369,10 @@ class Group(ExtensibleModel):
return list(self.members.all()) + list(self.owners.all())
def __str__(self) -> str:
return f"{self.name} ({self.short_name})"
if self.school_year:
return f"{self.name} ({self.short_name}) ({self.school_year})"
else:
return f"{self.name} ({self.short_name})"
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
......
......@@ -40,6 +40,7 @@ class GroupsTable(tables.Table):
name = tables.LinkColumn("group_by_id", args=[A("id")])
short_name = tables.LinkColumn("group_by_id", args=[A("id")])
school_year = tables.Column()
class GroupTypesTable(tables.Table):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment