Compare commits
4 commits
f6c4c732d6
...
1df3b67fa1
Author | SHA1 | Date | |
---|---|---|---|
Casper V. Kristensen | 1df3b67fa1 | ||
Casper V. Kristensen | be63e62637 | ||
Casper V. Kristensen | 0a5be5d2be | ||
Casper V. Kristensen | 006f1c6c45 |
|
@ -13,50 +13,33 @@ class Item(models.Model):
|
|||
max_length=50
|
||||
)
|
||||
|
||||
QUALITY_POOR = 0
|
||||
QUALITY_COMMON = 1
|
||||
QUALITY_UNCOMMON = 2
|
||||
QUALITY_RARE = 3
|
||||
QUALITY_EPIC = 4
|
||||
QUALITY_LEGENDARY = 5
|
||||
QUALITY_ARTIFACT = 6
|
||||
QUALITY_CHOICES = [
|
||||
(QUALITY_POOR, "Poor"),
|
||||
(QUALITY_COMMON, "Common"),
|
||||
(QUALITY_UNCOMMON, "Uncommon"),
|
||||
(QUALITY_RARE, "Rare"),
|
||||
(QUALITY_EPIC, "Epic"),
|
||||
(QUALITY_LEGENDARY, "Legendary"),
|
||||
(QUALITY_ARTIFACT, "Artifact"),
|
||||
]
|
||||
class Quality(models.IntegerChoices):
|
||||
POOR = 0
|
||||
COMMON = 1
|
||||
UNCOMMON = 2
|
||||
RARE = 3
|
||||
EPIC = 4
|
||||
LEGENDARY = 5
|
||||
ARTIFACT = 6
|
||||
|
||||
quality = models.PositiveSmallIntegerField(
|
||||
choices=QUALITY_CHOICES
|
||||
choices=Quality.choices
|
||||
)
|
||||
|
||||
KLASS_CONSUMABLES = 0
|
||||
KLASS_CONTAINERS = 1
|
||||
KLASS_WEAPONS = 2
|
||||
KLASS_ARMOR = 4
|
||||
KLASS_PROJECTILES = 6
|
||||
KLASS_TRADE_GOODS = 7
|
||||
KLASS_RECIPES = 9
|
||||
KLASS_QUIVER = 11
|
||||
KLASS_QUEST_ITEMS = 12
|
||||
KLASS_MISCELLANEOUS = 15
|
||||
KLASS_CHOICES = [
|
||||
(KLASS_CONSUMABLES, "Consumables"),
|
||||
(KLASS_CONTAINERS, "Containers"),
|
||||
(KLASS_WEAPONS, "Weapons"),
|
||||
(KLASS_ARMOR, "Armor"),
|
||||
(KLASS_PROJECTILES, "Projectiles"),
|
||||
(KLASS_TRADE_GOODS, "Trade Goods"),
|
||||
(KLASS_RECIPES, "Recipes"),
|
||||
(KLASS_QUIVER, "Quiver"),
|
||||
(KLASS_QUEST_ITEMS, "Quest Items"),
|
||||
(KLASS_MISCELLANEOUS, "Miscellaneous"),
|
||||
]
|
||||
class Klass(models.IntegerChoices):
|
||||
CONSUMABLES = 0
|
||||
CONTAINERS = 1
|
||||
WEAPONS = 2
|
||||
ARMOR = 4
|
||||
PROJECTILES = 6
|
||||
TRADE_GOODS = 7
|
||||
RECIPES = 9
|
||||
QUIVER = 11
|
||||
QUEST_ITEMS = 12
|
||||
MISCELLANEOUS = 15
|
||||
|
||||
klass = models.PositiveSmallIntegerField(
|
||||
choices=KLASS_CHOICES
|
||||
choices=Klass.choices
|
||||
)
|
||||
|
||||
sub_klass = models.SmallIntegerField(
|
||||
|
|
|
@ -160,11 +160,11 @@ CRISPY_TEMPLATE_PACK = "bootstrap4"
|
|||
|
||||
# Drakul
|
||||
DEFAULT_ATTENDANCE = {
|
||||
"No Response": 0.0,
|
||||
"Signed Off": 0.0,
|
||||
"Signed Up": 1.0,
|
||||
"Stand By": 1.0,
|
||||
"Confirmed": 1.0,
|
||||
"NO_RESPONSE": 0.0,
|
||||
"SIGNED_OFF": 0.0,
|
||||
"SIGNED_UP": 1.0,
|
||||
"STANDBY": 1.0,
|
||||
"CONFIRMED": 1.0,
|
||||
}
|
||||
|
||||
ATTENDANCE_COLORS = [
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -16,16 +16,16 @@ class RaidResponseForm(ModelForm):
|
|||
self.fields["character"].queryset = user.characters
|
||||
self.fields["character"].initial = user.main
|
||||
self.fields["role"].initial = user.main.role
|
||||
self.fields["status"].choices = RaidResponse.USER_STATUS_CHOICES
|
||||
self.fields["status"].choices = RaidResponse.UserStatus.choices
|
||||
|
||||
self.helper = FormHelper()
|
||||
|
||||
if self.instance.status <= RaidResponse.SIGNED_OFF:
|
||||
if self.instance.status <= RaidResponse.Status.SIGNED_OFF:
|
||||
signup_button = StrictButton(
|
||||
"Sign Up",
|
||||
type="submit",
|
||||
name="status",
|
||||
value=RaidResponse.SIGNED_UP,
|
||||
value=RaidResponse.Status.SIGNED_UP,
|
||||
css_class="btn-success btn-block"
|
||||
)
|
||||
else:
|
||||
|
@ -33,7 +33,7 @@ class RaidResponseForm(ModelForm):
|
|||
"Change",
|
||||
type="submit",
|
||||
name="status",
|
||||
value=RaidResponse.SIGNED_UP,
|
||||
value=RaidResponse.Status.SIGNED_UP,
|
||||
css_class="btn-primary btn-block"
|
||||
)
|
||||
self.helper.layout = Layout(
|
||||
|
@ -46,9 +46,9 @@ class RaidResponseForm(ModelForm):
|
|||
"Sign Off",
|
||||
type="submit",
|
||||
name="status",
|
||||
value=RaidResponse.SIGNED_OFF,
|
||||
value=RaidResponse.Status.SIGNED_OFF,
|
||||
css_class="btn-danger btn-block",
|
||||
disabled=self.instance.pk and self.instance.status == RaidResponse.SIGNED_OFF
|
||||
disabled=self.instance.pk and self.instance.status == RaidResponse.Status.SIGNED_OFF
|
||||
),
|
||||
css_class="col-md-3"
|
||||
),
|
||||
|
@ -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"),
|
||||
)
|
||||
|
|
18
drakul/raids/migrations/0007_auto_20200421_0256.py
Normal file
18
drakul/raids/migrations/0007_auto_20200421_0256.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.2 on 2020-04-21 02:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('raids', '0006_auto_20200417_0854'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='raidresponse',
|
||||
name='status',
|
||||
field=models.PositiveSmallIntegerField(choices=[(0, 'No Response'), (1, 'Signed Off'), (2, 'Signed Up'), (3, 'Standby'), (4, 'Confirmed')]),
|
||||
),
|
||||
]
|
22
drakul/raids/migrations/0008_auto_20200421_1753.py
Normal file
22
drakul/raids/migrations/0008_auto_20200421_1753.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -57,38 +57,40 @@ class RaidResponse(models.Model):
|
|||
)
|
||||
|
||||
role = models.PositiveSmallIntegerField(
|
||||
choices=Character.ROLE_CHOICES,
|
||||
choices=Character.Roles.choices,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
class Status(models.IntegerChoices):
|
||||
NO_RESPONSE = 0
|
||||
SIGNED_OFF = 1
|
||||
SIGNED_UP = 2
|
||||
STANDBY = 3
|
||||
CONFIRMED = 4
|
||||
STATUS_CHOICES = [
|
||||
(NO_RESPONSE, "No Response"),
|
||||
(SIGNED_OFF, "Signed Off"),
|
||||
(SIGNED_UP, "Signed Up"),
|
||||
(STANDBY, "Stand By"),
|
||||
(CONFIRMED, "Confirmed"),
|
||||
]
|
||||
USER_STATUS_CHOICES = [
|
||||
(SIGNED_OFF, "Signed Off"),
|
||||
(SIGNED_UP, "Signed Up"),
|
||||
]
|
||||
|
||||
@property
|
||||
def default_attendance(self):
|
||||
return settings.DEFAULT_ATTENDANCE[self.name]
|
||||
|
||||
class UserStatus(models.IntegerChoices):
|
||||
SIGNED_OFF = 1
|
||||
SIGNED_UP = 2
|
||||
|
||||
status = models.PositiveSmallIntegerField(
|
||||
choices=STATUS_CHOICES
|
||||
choices=Status.choices
|
||||
)
|
||||
|
||||
STATUS_DEFAULT_ATTENDANCE = {
|
||||
NO_RESPONSE: settings.DEFAULT_ATTENDANCE["No Response"],
|
||||
SIGNED_OFF: settings.DEFAULT_ATTENDANCE["Signed Off"],
|
||||
SIGNED_UP: settings.DEFAULT_ATTENDANCE["Signed Up"],
|
||||
STANDBY: settings.DEFAULT_ATTENDANCE["Stand By"],
|
||||
CONFIRMED: settings.DEFAULT_ATTENDANCE["Confirmed"],
|
||||
}
|
||||
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,
|
||||
|
@ -102,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")
|
||||
]
|
||||
|
@ -113,14 +115,14 @@ class RaidResponse(models.Model):
|
|||
|
||||
def clean(self):
|
||||
# Make sure no-responses and sign-offs are role-agnostic, but all other responses are not
|
||||
if self.status <= RaidResponse.SIGNED_OFF:
|
||||
if self.status <= RaidResponse.Status.SIGNED_OFF:
|
||||
self.role = None
|
||||
elif self.role is None:
|
||||
raise ValidationError({"role": "This field is required."})
|
||||
|
||||
# Set attendance to one of the default values if status was changed
|
||||
if self.status != self._original_status:
|
||||
self.attendance = RaidResponse.STATUS_DEFAULT_ATTENDANCE[self.status]
|
||||
self.attendance = RaidResponse.Status(self.status).default_attendance
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
|
|
|
@ -11,7 +11,7 @@ User = get_user_model()
|
|||
@receiver(post_save, sender=Raid)
|
||||
def create_raid_no_responses(instance: Raid, **kwargs):
|
||||
# Delete all pre-existing no-responses, in case the deadline was changed
|
||||
instance.responses.filter(status=RaidResponse.NO_RESPONSE).delete()
|
||||
instance.responses.filter(status=RaidResponse.Status.NO_RESPONSE).delete()
|
||||
# Then create them (again)
|
||||
users = User.objects \
|
||||
.exclude(Q(date_joined__gt=instance.date) | Q(characters__raid_responses__raid=instance) | Q(is_active=False)) \
|
||||
|
@ -20,8 +20,8 @@ def create_raid_no_responses(instance: Raid, **kwargs):
|
|||
RaidResponse(
|
||||
raid=instance,
|
||||
character=user.main,
|
||||
status=RaidResponse.NO_RESPONSE,
|
||||
attendance=RaidResponse.STATUS_DEFAULT_ATTENDANCE[RaidResponse.NO_RESPONSE]
|
||||
status=RaidResponse.Status.NO_RESPONSE,
|
||||
attendance=RaidResponse.Status.NO_RESPONSE.default_attendance
|
||||
)
|
||||
for user in users
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ def create_raid_no_responses(instance: Raid, **kwargs):
|
|||
@receiver(post_save, sender=User)
|
||||
def create_user_no_responses(instance: User, **kwargs):
|
||||
# Delete all pre-existing no-responses for this user, in case date_joined or main was changed
|
||||
RaidResponse.objects.filter(character__user=instance, status=RaidResponse.NO_RESPONSE).delete()
|
||||
RaidResponse.objects.filter(character__user=instance, status=RaidResponse.Status.NO_RESPONSE).delete()
|
||||
# Then create them (again)
|
||||
if not instance.is_active:
|
||||
return
|
||||
|
@ -38,8 +38,8 @@ def create_user_no_responses(instance: User, **kwargs):
|
|||
RaidResponse(
|
||||
raid=raid,
|
||||
character=instance.main,
|
||||
status=RaidResponse.NO_RESPONSE,
|
||||
attendance=RaidResponse.STATUS_DEFAULT_ATTENDANCE[RaidResponse.NO_RESPONSE]
|
||||
status=RaidResponse.Status.NO_RESPONSE,
|
||||
attendance=RaidResponse.Status.NO_RESPONSE.default_attendance
|
||||
)
|
||||
for raid in Raid.objects.exclude(
|
||||
Q(date__lt=instance.date_joined) | Q(responses__character__user=instance)
|
||||
|
|
|
@ -54,13 +54,17 @@
|
|||
|
||||
{% regroup raid.responses.all by get_status_display as status_responses_list %}
|
||||
{% for status, status_responses in status_responses_list %}
|
||||
{% 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 }} ({{ status_responses | length }})</span>
|
||||
<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 status_responses by get_role_display as role_responses_list %}
|
||||
{% 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>
|
||||
|
@ -93,6 +97,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
<div id="comments" class="card mt-4 mb-4">
|
||||
<h6 class="card-header">Comments</h6>
|
||||
|
@ -104,7 +109,7 @@
|
|||
<strong>{{ comment.user.main.name }}</strong> <small class="text-muted">· {{ comment.date_created }}</small>
|
||||
</p>
|
||||
<p class="card-text">
|
||||
{{ comment.body }}
|
||||
{{ comment.body | linebreaksbr }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -44,7 +44,9 @@
|
|||
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
|
@ -56,6 +58,10 @@
|
|||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if not forloop.last %}
|
||||
<tr><td class="p-1"></td></tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not forloop.last %}
|
||||
<tr><td class="p-2"></td></tr>
|
||||
{% endif %}
|
||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.db.models import Q, Max, prefetch_related_objects
|
||||
from django.db.models import Q, Max
|
||||
from django.http import Http404
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
|
|
|
@ -93,6 +93,7 @@ class Character(models.Model):
|
|||
unique=True
|
||||
)
|
||||
|
||||
class Klasses(models.IntegerChoices):
|
||||
DRUID = 1
|
||||
HUNTER = 2
|
||||
MAGE = 3
|
||||
|
@ -102,32 +103,19 @@ class Character(models.Model):
|
|||
SHAMAN = 7
|
||||
WARLOCK = 8
|
||||
WARRIOR = 9
|
||||
CLASS_CHOICES = [
|
||||
(DRUID, "Druid"),
|
||||
(HUNTER, "Hunter"),
|
||||
(MAGE, "Mage"),
|
||||
(PALADIN, "Paladin"),
|
||||
(PRIEST, "Priest"),
|
||||
(ROGUE, "Rogue"),
|
||||
(SHAMAN, "Shaman"),
|
||||
(WARLOCK, "Warlock"),
|
||||
(WARRIOR, "Warrior"),
|
||||
]
|
||||
|
||||
klass = models.PositiveSmallIntegerField(
|
||||
"class",
|
||||
choices=CLASS_CHOICES
|
||||
choices=Klasses.choices
|
||||
)
|
||||
|
||||
class Roles(models.IntegerChoices):
|
||||
TANK = 1
|
||||
HEALER = 2
|
||||
DAMAGE = 3
|
||||
ROLE_CHOICES = [
|
||||
(TANK, "Tank"),
|
||||
(HEALER, "Healer"),
|
||||
(DAMAGE, "Damage"),
|
||||
]
|
||||
|
||||
role = models.PositiveSmallIntegerField(
|
||||
choices=ROLE_CHOICES
|
||||
choices=Roles.choices
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -14,7 +14,7 @@ def attendance_cell(response: RaidResponse):
|
|||
if response is None:
|
||||
return ""
|
||||
|
||||
if response.attendance == RaidResponse.STATUS_DEFAULT_ATTENDANCE[response.status]:
|
||||
if response.attendance == RaidResponse.Status(response.status).default_attendance:
|
||||
cell = ""
|
||||
else:
|
||||
cell = response.attendance
|
||||
|
|
Loading…
Reference in a new issue