Compare commits
3 Commits
7b4df14bee
...
23001a3de3
Author | SHA1 | Date |
---|---|---|
Luca | 23001a3de3 | |
Luca | 2d90662e4c | |
Luca | 15475e2eec |
|
@ -26,7 +26,6 @@ class RegisterForm(forms.Form):
|
|||
name = forms.CharField(
|
||||
max_length=Helper.name.field.max_length, label="Name", widget=text_input()
|
||||
)
|
||||
# actually verify phone number, lol
|
||||
phone = PhoneNumberField(
|
||||
max_length=Helper.phone.field.max_length,
|
||||
label="Handynummer für Benachrichtigungen",
|
||||
|
|
|
@ -29,9 +29,9 @@ class FallbackAssignmentInline(admin.TabularInline):
|
|||
|
||||
@admin.register(TeamMember)
|
||||
class TeamMemberAdmin(admin.ModelAdmin):
|
||||
fields = ("id", "name", "url")
|
||||
fields = ("id", "name", "comment", "url")
|
||||
readonly_fields = ("id", "url")
|
||||
list_display = ("name", "shift_count")
|
||||
list_display = ("name", "comment", "shift_count")
|
||||
ordering = ("name",)
|
||||
inlines = (FallbackAssignmentInline,)
|
||||
actions = (assign_random_shifts, clear_shifts) # , reshuffle_shifts)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import sys
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from ...models import TeamMember
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Import a list of team members, optionally including their affiliations (stored in the comment field)"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--delimiter",
|
||||
default=":",
|
||||
help="character separating name from affiliations",
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
self._handle(*args, **options)
|
||||
except KeyboardInterrupt:
|
||||
self.stderr.write()
|
||||
except Exception as e:
|
||||
raise CommandError(e)
|
||||
|
||||
def _handle(self, *args, **options):
|
||||
team_members = []
|
||||
for line in sys.stdin.readlines():
|
||||
line = line.strip()
|
||||
if line == "" or line.startswith("#"):
|
||||
continue
|
||||
|
||||
match line.split(options["delimiter"], maxsplit=1):
|
||||
case [name, affiliations]:
|
||||
team_members.append(
|
||||
TeamMember(name=name, comment=affiliations.strip())
|
||||
)
|
||||
case [name]:
|
||||
team_members.append(TeamMember(name=name))
|
||||
|
||||
TeamMember.objects.bulk_create(team_members)
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.0.4 on 2024-05-19 21:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("fallback", "0006_fallbackassignment_was_full"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="teammember",
|
||||
name="comment",
|
||||
field=models.CharField(default="", max_length=100),
|
||||
),
|
||||
]
|
|
@ -18,6 +18,7 @@ def generate_id():
|
|||
class TeamMember(models.Model):
|
||||
id = models.IntegerField(default=generate_id, editable=False, primary_key=True)
|
||||
name = models.CharField(max_length=100)
|
||||
comment = models.CharField(max_length=100, default="")
|
||||
fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")
|
||||
|
||||
def url(self):
|
||||
|
@ -165,7 +166,7 @@ class TeamMember(models.Model):
|
|||
assignment.delete()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
return f"{self.name}{f': {self.comment}' if self.comment else ''}"
|
||||
|
||||
|
||||
class FallbackAssignment(models.Model):
|
||||
|
|
Loading…
Reference in New Issue