Add support for raid groups.

This commit is contained in:
Casper V. Kristensen 2020-04-21 17:58:41 +02:00
parent be63e62637
commit 1df3b67fa1
Signed by: caspervk
GPG key ID: 289CA03790535054
6 changed files with 90 additions and 45 deletions

View file

@ -5,7 +5,7 @@ from .models import Raid, RaidResponse, RaidComment, InstanceReset
class RaidResponseInline(admin.TabularInline):
model = RaidResponse
fields = ["character", "role", "status", "attendance", "note"]
fields = ["character", "role", "status", "group", "attendance", "note"]
extra = 0

View file

@ -109,7 +109,7 @@ class RaidCommentForm(ModelForm):
RaidResponseFormSet = inlineformset_factory(
Raid, # parent model
RaidResponse,
fields=["character", "role", "status", "note", "attendance"],
fields=["character", "role", "status", "group", "note", "attendance"],
can_delete=False,
extra=1
)
@ -124,6 +124,7 @@ class RaidResponseFormSetHelper(FormHelper):
Field("character", css_class="character-select"),
Field("role", css_class="role-select"),
Field("status", css_class="status-select"),
Field("group", css_class="group-select"),
Field("note"),
Field("attendance", css_class="attendance-input"),
)

View file

@ -0,0 +1,22 @@
# Generated by Django 3.0.2 on 2020-04-21 17:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('raids', '0007_auto_20200421_0256'),
]
operations = [
migrations.AlterModelOptions(
name='raidresponse',
options={'ordering': ['-status', 'group', 'role', 'character__klass', 'character__user__rank', 'character__name']},
),
migrations.AddField(
model_name='raidresponse',
name='group',
field=models.PositiveSmallIntegerField(choices=[(1, 'Group 1'), (2, 'Group 2'), (3, 'Group 3'), (4, 'Group 4')], default=1),
),
]

View file

@ -81,6 +81,17 @@ class RaidResponse(models.Model):
choices=Status.choices
)
class Groups(models.IntegerChoices):
GROUP_1 = 1
GROUP_2 = 2
GROUP_3 = 3
GROUP_4 = 4
group = models.PositiveSmallIntegerField(
choices=Groups.choices,
default=Groups.GROUP_1
)
attendance = models.DecimalField(
max_digits=3,
decimal_places=2,
@ -93,7 +104,7 @@ class RaidResponse(models.Model):
)
class Meta:
ordering = ["-status", "role", "character__klass", "character__user__rank", "character__name"]
ordering = ["-status", "group", "role", "character__klass", "character__user__rank", "character__name"]
constraints = [
models.UniqueConstraint(fields=["raid", "character"], name="unique_character_raid_signup")
]

View file

@ -54,44 +54,49 @@
{% regroup raid.responses.all by get_status_display as status_responses_list %}
{% for status, status_responses in status_responses_list %}
<div class="card mb-2">
<h6 class="card-header d-flex response-status-{{ status | slugify }}-bg">
<span class="mr-auto">{{ status }} ({{ status_responses | length }})</span>
<span type="button" class="badge badge-dark" data-toggle="modal" data-target="#exportModal">Export</span>
</h6>
<div class="card-body mb-n4">
{% regroup status_responses by get_role_display as role_responses_list %}
{% for role, role_responses in role_responses_list %}
{% if role is not None %}
<h6 class="card-title border-bottom pb-2">{{ role }} ({{ role_responses | length }})</h6>
{% endif %}
<div class="d-flex flex-wrap">
{% regroup role_responses by character.klass as class_responses_list %}
{% for class, class_responses in class_responses_list %}
<div class="d-flex flex-column mr-2 mb-4">
{% regroup class_responses by character.user.rank as rank_responses_list %}
{% for rank, rank_responses in rank_responses_list %}
<div class="d-flex justify-content-center align-items-center">
<hr class="flex-grow-1 my-0">
<div class="mx-2 my-0 font-weight-light text-muted small">{{ rank }}</div>
<hr class="flex-grow-1 my-0">
</div>
{% for response in rank_responses %}
<a class="btn response-character-button mb-1 btn-class-{{ response.character.klass }}" role="button" href="#">
{% if response.character != response.character.user.main %}
<abbr title="{{ response.character.user.main }}">{{ response.character.name }}</abbr>
{% else %}
{{ response.character.name }}
{% endif %}
</a>
{% regroup status_responses by get_group_display as group_responses_list %}
{% for group, group_responses in group_responses_list %}
<div class="card mb-2">
<h6 class="card-header d-flex response-status-{{ status | slugify }}-bg">
<span class="mr-auto">
{{ status }}{% if group_responses_list|length > 1 %}: {{ group }}{% endif %} ({{ status_responses | length }})
</span>
<span type="button" class="badge badge-dark" data-toggle="modal" data-target="#exportModal">Export</span>
</h6>
<div class="card-body mb-n4">
{% regroup group_responses by get_role_display as role_responses_list %}
{% for role, role_responses in role_responses_list %}
{% if role is not None %}
<h6 class="card-title border-bottom pb-2">{{ role }} ({{ role_responses | length }})</h6>
{% endif %}
<div class="d-flex flex-wrap">
{% regroup role_responses by character.klass as class_responses_list %}
{% for class, class_responses in class_responses_list %}
<div class="d-flex flex-column mr-2 mb-4">
{% regroup class_responses by character.user.rank as rank_responses_list %}
{% for rank, rank_responses in rank_responses_list %}
<div class="d-flex justify-content-center align-items-center">
<hr class="flex-grow-1 my-0">
<div class="mx-2 my-0 font-weight-light text-muted small">{{ rank }}</div>
<hr class="flex-grow-1 my-0">
</div>
{% for response in rank_responses %}
<a class="btn response-character-button mb-1 btn-class-{{ response.character.klass }}" role="button" href="#">
{% if response.character != response.character.user.main %}
<abbr title="{{ response.character.user.main }}">{{ response.character.name }}</abbr>
{% else %}
{{ response.character.name }}
{% endif %}
</a>
{% endfor %}
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
{% endfor %}
{% endfor %}
<div id="comments" class="card mt-4 mb-4">

View file

@ -44,17 +44,23 @@
{% regroup formset by status.value as status_forms_list %}
{% for status, status_forms in status_forms_list %}
{% regroup status_forms by role.value as role_forms_list %}
{% for role, role_forms in role_forms_list %}
{% for form in role_forms %}
{% if form_show_errors and not form.is_extra %}
{% include "bootstrap4/errors.html" %}
{% regroup status_forms by group.value as group_forms_list %}
{% for group, group_forms in group_forms_list %}
{% regroup group_forms by role.value as role_forms_list %}
{% for role, role_forms in role_forms_list %}
{% for form in role_forms %}
{% if form_show_errors and not form.is_extra %}
{% include "bootstrap4/errors.html" %}
{% endif %}
<tr>
{% for field in form %}
{% include 'bootstrap4/field.html' with tag="td" form_show_labels=False %}
{% endfor %}
</tr>
{% endfor %}
{% if not forloop.last %}
<tr><td class="p-1"></td></tr>
{% endif %}
<tr>
{% for field in form %}
{% include 'bootstrap4/field.html' with tag="td" form_show_labels=False %}
{% endfor %}
</tr>
{% endfor %}
{% if not forloop.last %}
<tr><td class="p-2"></td></tr>