-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement individual students stickying
Closes #1719
- Loading branch information
1 parent
129cfbc
commit 49de27c
Showing
17 changed files
with
282 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django import forms | ||
from django.contrib.auth import get_user_model | ||
from django.core.validators import ValidationError | ||
|
||
|
||
class UserMultipleChoiceField(forms.ModelMultipleChoiceField): | ||
"""Choose any user from the database.""" | ||
|
||
def clean(self, value): | ||
if not value and not self.required: | ||
return self.queryset.none() | ||
elif self.required: | ||
raise ValidationError(self.error_messages["required"], code="required") | ||
|
||
try: | ||
users = get_user_model().objects.filter(id__in=value) | ||
if len(users) != len(value): | ||
raise ValidationError(self.error_messages["invalid_choice"], code="invalid_choice") | ||
except (ValueError, TypeError) as e: | ||
raise ValidationError(self.error_messages["invalid_choice"], code="invalid_choice") from e | ||
return users | ||
|
||
def label_from_instance(self, obj): | ||
if isinstance(obj, get_user_model()): | ||
return f"{obj.get_full_name()} ({obj.username})" | ||
return super().label_from_instance(obj) |
20 changes: 20 additions & 0 deletions
20
intranet/apps/eighth/migrations/0071_eighthscheduledactivity_sticky_students.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 3.2.25 on 2024-10-12 21:12 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('eighth', '0070_eighthactivity_club_sponsors'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='eighthscheduledactivity', | ||
name='sticky_students', | ||
field=models.ManyToManyField(blank=True, related_name='sticky_scheduledactivity_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.