Compare commits
No commits in common. "b3ba6caa07dae14a41a0ddfd9623149da8d5c1fe" and "7c7ffee1f3f292bd96d42891af30ebe965f44e46" have entirely different histories.
b3ba6caa07
...
7c7ffee1f3
|
@ -18,7 +18,7 @@ class RaidCommentInline(admin.TabularInline):
|
|||
|
||||
@admin.register(Raid)
|
||||
class RaidAdmin(admin.ModelAdmin):
|
||||
list_display = ["title", "date", "response_deadline"]
|
||||
list_display = ["title", "date", "signup_deadline"]
|
||||
search_fields = ["title"]
|
||||
inlines = [RaidResponseInline, RaidCommentInline]
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class RaidResponseForm(ModelForm):
|
|||
class RaidForm(ModelForm):
|
||||
class Meta:
|
||||
model = Raid
|
||||
fields = ["title", "description", "date", "response_deadline"]
|
||||
fields = ["title", "description", "date", "signup_deadline"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -78,7 +78,7 @@ class RaidForm(ModelForm):
|
|||
Field("description"),
|
||||
Row(
|
||||
Column("date", css_class="form-group col-md-6"),
|
||||
Column("response_deadline", css_class="form-group col-md-6"),
|
||||
Column("signup_deadline", css_class="form-group col-md-6"),
|
||||
),
|
||||
submit_button
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.2.6 on 2019-10-25 13:23
|
||||
# Generated by Django 2.2.6 on 2019-10-25 01:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Migration(migrations.Migration):
|
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100, unique=True)),
|
||||
('date', models.DateField(help_text='Some date where the instance was reset in the past.')),
|
||||
('time', models.TimeField(help_text='The time of day where the instance resets.')),
|
||||
('time', models.TimeField()),
|
||||
('duration', models.DurationField(help_text='Resets are calculated from the given date in intervals of this duration.', verbose_name='lockout duration')),
|
||||
],
|
||||
options={
|
||||
|
@ -31,7 +31,7 @@ class Migration(migrations.Migration):
|
|||
('title', models.CharField(max_length=40)),
|
||||
('description', models.TextField(blank=True, null=True)),
|
||||
('date', models.DateTimeField()),
|
||||
('response_deadline', models.DateTimeField(blank=True, help_text='Defaults to 24 hours before date and time of raid if not set.')),
|
||||
('signup_deadline', models.DateTimeField(blank=True, help_text='Defaults to date and time of raid if not set.')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-date'],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.2.6 on 2019-10-25 13:23
|
||||
# Generated by Django 2.2.6 on 2019-10-25 01:58
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
|
@ -1,5 +1,3 @@
|
|||
from datetime import timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
|
@ -18,19 +16,18 @@ class Raid(models.Model):
|
|||
)
|
||||
|
||||
date = models.DateTimeField()
|
||||
response_deadline = models.DateTimeField(
|
||||
signup_deadline = models.DateTimeField(
|
||||
blank=True,
|
||||
help_text="Defaults to 24 hours before date and time of raid if not set."
|
||||
help_text="Defaults to date and time of raid if not set."
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-date"]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.response_deadline is None:
|
||||
self.response_deadline = self.date - timedelta(hours=24)
|
||||
|
||||
return super().save(*args, **kwargs)
|
||||
def clean(self):
|
||||
# Set the signup deadline to the date/time of the raid if it hasn't been set already
|
||||
if self.signup_deadline is None:
|
||||
self.signup_deadline = self.date
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} on {self.date}"
|
||||
|
@ -144,9 +141,7 @@ class InstanceReset(models.Model):
|
|||
date = models.DateField(
|
||||
help_text="Some date where the instance was reset in the past."
|
||||
)
|
||||
time = models.TimeField(
|
||||
help_text="The time of day where the instance resets."
|
||||
)
|
||||
time = models.TimeField()
|
||||
duration = models.DurationField(
|
||||
"lockout duration",
|
||||
help_text="Resets are calculated from the given date in intervals of this duration."
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</h4>
|
||||
<div class="card-body">
|
||||
<p class="card-text">{{ raid.description | linebreaksbr | default:"<em>No description</em>" }}</p>
|
||||
<p class="card-text"><small class="text-muted">Response deadline: {{ raid.response_deadline }}</small></p>
|
||||
<p class="card-text"><small class="text-muted">Sign up deadline: {{ raid.signup_deadline }}</small></p>
|
||||
</div>
|
||||
</div>
|
||||
{% if response_form %}
|
||||
|
|
|
@ -83,7 +83,7 @@ class RaidDetailView(SingleObjectMixin, MultiModelFormView):
|
|||
classes = {
|
||||
"comment_form": RaidCommentForm
|
||||
}
|
||||
if self.object.response_deadline > timezone.now():
|
||||
if self.object.signup_deadline > timezone.now():
|
||||
classes["response_form"] = RaidResponseForm
|
||||
return classes
|
||||
|
||||
|
|
|
@ -8,3 +8,5 @@ class CharacterForm(ModelForm):
|
|||
model = Character
|
||||
fields = ["name", "klass", "role"]
|
||||
|
||||
def clean_name(self):
|
||||
return self.cleaned_data["name"].capitalize()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.2.6 on 2019-10-25 13:23
|
||||
# Generated by Django 2.2.6 on 2019-10-25 01:58
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.validators
|
||||
|
@ -55,7 +55,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='main',
|
||||
field=models.OneToOneField(blank=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='users.Character'),
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='users.Character'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
|
|
|
@ -12,6 +12,22 @@ class UserManager(DjangoUserManager):
|
|||
avg_attendance=Avg("characters__raid_responses__attendance")
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def _create_user(self, username, email, password, **extra_fields):
|
||||
if "main" not in extra_fields:
|
||||
main = Character.objects.create(
|
||||
user=None,
|
||||
name=username,
|
||||
klass=Character.WARRIOR,
|
||||
role=Character.DAMAGE
|
||||
)
|
||||
main.save()
|
||||
extra_fields["main"] = main
|
||||
user = super()._create_user(username, email, password, **extra_fields)
|
||||
extra_fields["main"].user = user
|
||||
extra_fields["main"].save()
|
||||
return user
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
objects = UserManager()
|
||||
|
@ -22,8 +38,7 @@ class User(AbstractUser):
|
|||
main = models.OneToOneField(
|
||||
"Character",
|
||||
related_name="+",
|
||||
on_delete=models.PROTECT,
|
||||
blank=True
|
||||
on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -33,22 +48,6 @@ class User(AbstractUser):
|
|||
if hasattr(self, "main") and self.main.user != self:
|
||||
raise ValidationError({"main": "Main character must be owned by user."})
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, *args, **kwargs):
|
||||
if not hasattr(self, "main"):
|
||||
self.main = Character.objects.create(
|
||||
user=None,
|
||||
name=self.username,
|
||||
klass=Character.WARRIOR,
|
||||
role=Character.DAMAGE
|
||||
)
|
||||
self.main.save()
|
||||
|
||||
user = super().save(*args, **kwargs)
|
||||
self.main.user = self
|
||||
self.main.save()
|
||||
return user
|
||||
|
||||
def avg_attendance(self):
|
||||
return self.avg_attendance
|
||||
|
||||
|
@ -108,8 +107,5 @@ class Character(models.Model):
|
|||
class Meta:
|
||||
ordering = ["name"]
|
||||
|
||||
def clean(self):
|
||||
self.name = self.name.capitalize()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
Loading…
Reference in a new issue