diff --git a/src/teams/admin.py b/src/teams/admin.py index 0539b6d0..59646a99 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Team, TeamMember, TeamTask +from .models import Team, TeamMember, TeamTask, TeamShift from .email import add_added_membership_email, add_removed_membership_email from camps.utils import CampPropertyListFilter @@ -90,3 +90,10 @@ class TeamMemberAdmin(admin.ModelAdmin): ) remove_member.description = 'Remove a user from the team.' + + +@admin.register(TeamShift) +class TeamShiftAdmin(admin.ModelAdmin): + list_filter = [ + 'team', + ] diff --git a/src/teams/migrations/0043_auto_20180702_1338.py b/src/teams/migrations/0043_auto_20180702_1338.py new file mode 100644 index 00000000..ad64e0dc --- /dev/null +++ b/src/teams/migrations/0043_auto_20180702_1338.py @@ -0,0 +1,43 @@ +# Generated by Django 2.0.4 on 2018-07-02 18:38 + +import django.contrib.postgres.fields.ranges +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0042_auto_20180413_1933'), + ] + + operations = [ + migrations.CreateModel( + name='TeamShift', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('shift_range', django.contrib.postgres.fields.ranges.DateTimeRangeField()), + ('people_required', models.IntegerField(default=1)), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='team', + name='shifts_enabled', + field=models.BooleanField(default=False, help_text='Does this team have shifts? This enables defining shifts for this team.'), + ), + migrations.AddField( + model_name='teamshift', + name='team', + field=models.ForeignKey(help_text='The team this shift belongs to', on_delete=django.db.models.deletion.PROTECT, related_name='shifts', to='teams.Team'), + ), + migrations.AddField( + model_name='teamshift', + name='team_members', + field=models.ManyToManyField(to='teams.TeamMember'), + ), + ] diff --git a/src/teams/migrations/0044_auto_20180702_1507.py b/src/teams/migrations/0044_auto_20180702_1507.py new file mode 100644 index 00000000..cb19b4ac --- /dev/null +++ b/src/teams/migrations/0044_auto_20180702_1507.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.4 on 2018-07-02 20:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0043_auto_20180702_1338'), + ] + + operations = [ + migrations.AlterField( + model_name='teamshift', + name='team_members', + field=models.ManyToManyField(blank=True, to='teams.TeamMember'), + ), + ] diff --git a/src/teams/models.py b/src/teams/models.py index b145c44b..5d445508 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -1,13 +1,14 @@ +import logging + from django.db import models -from django.db.models.signals import post_save -from django.dispatch import receiver from django.utils.text import slugify -from utils.models import CampRelatedModel from django.core.exceptions import ValidationError -from django.contrib.auth.models import User from django.urls import reverse_lazy from django.conf import settings -import logging +from django.contrib.postgres.fields import DateTimeRangeField + +from utils.models import CampRelatedModel + logger = logging.getLogger("bornhack.%s" % __name__) @@ -102,6 +103,11 @@ class Team(CampRelatedModel): help_text='Used to indicate to the IRC bot that this teams private IRC channel is in need of a permissions and ACL fix.' ) + shifts_enabled = models.BooleanField( + default=False, + help_text="Does this team have shifts? This enables defining shifts for this team." + ) + class Meta: ordering = ['name'] unique_together = (('name', 'camp'), ('slug', 'camp')) @@ -301,3 +307,29 @@ class TeamTask(CampRelatedModel): self.slug = slugify(self.name) super().save(**kwargs) + +class TeamShift(CampRelatedModel): + team = models.ForeignKey( + 'teams.Team', + related_name='shifts', + on_delete=models.PROTECT, + help_text='The team this shift belongs to', + ) + + shift_range = DateTimeRangeField() + + team_members = models.ManyToManyField( + TeamMember, + blank=True, + ) + + people_required = models.IntegerField( + default=1 + ) + + @property + def camp(self): + """ All CampRelatedModels must have a camp FK or a camp property """ + return self.team.camp + + camp_filter = 'team__camp' diff --git a/src/teams/templates/shifts/shift_form.html b/src/teams/templates/shifts/shift_form.html new file mode 100644 index 00000000..b4bbb7fa --- /dev/null +++ b/src/teams/templates/shifts/shift_form.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% load commonmark %} +{% load bootstrap3 %} + + +{% block content %} + +{% if form.errors %} +{{ form.errors }} +{% endif %} + +
+ +{% endblock %} diff --git a/src/teams/templates/shifts/shift_list.html b/src/teams/templates/shifts/shift_list.html new file mode 100644 index 00000000..41aa1ac7 --- /dev/null +++ b/src/teams/templates/shifts/shift_list.html @@ -0,0 +1,53 @@ +{% extends 'base.html' %} +{% load commonmark %} +{% load bootstrap3 %} + + +{% block content %} + + + Back to team detail + + +
+ + {{ shift.shift_range.lower|date:'Y-m-d l' }} ++ | |||
+ From + | + To + | + People required + | + People + {% endifchanged %} + + |
---|---|---|---|
+ {{ shift.shift_range.lower|date:'H:i' }} + | + {{ shift.shift_range.upper|date:'H:i' }} + | + {{ shift.people_required }} + | + {{ shift.team_members}} + {% endfor %} + |