Introduce optional raids.

This commit is contained in:
Casper V. Kristensen 2019-11-20 22:53:38 +01:00
parent 9e4cdd3ec1
commit d4341e5d0b
Signed by: caspervk
GPG key ID: 289CA03790535054
5 changed files with 54 additions and 1 deletions

View file

@ -63,7 +63,7 @@ class RaidResponseForm(ModelForm):
class RaidForm(ModelForm):
class Meta:
model = Raid
fields = ["title", "description", "date", "response_deadline"]
fields = ["title", "description", "is_optional", "date", "response_deadline"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -76,6 +76,7 @@ class RaidForm(ModelForm):
self.helper.layout = Layout(
Field("title"),
Field("description"),
Field("is_optional"),
Row(
Column("date", css_class="form-group col-md-6"),
Column("response_deadline", css_class="form-group col-md-6"),

View file

@ -0,0 +1,18 @@
# Generated by Django 2.2.6 on 2019-11-20 22:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('raids', '0003_auto_20191119_0412'),
]
operations = [
migrations.AddField(
model_name='raid',
name='is_optional',
field=models.BooleanField(default=False, help_text='Designates whether this raid is optional. Optional raids are not included in attendance calculations.'),
),
]

View file

@ -23,6 +23,13 @@ class Raid(models.Model):
help_text="Defaults to 24 hours before date and time of raid if not set."
)
is_optional = models.BooleanField(
default=False,
help_text=(
"Designates whether this raid is optional. Optional raids are not included in attendance calculations."
)
)
class Meta:
ordering = ["-date"]

View file

@ -15,6 +15,9 @@
</h4>
<div class="card-body">
<p class="card-text">{{ raid.description | urlize | linebreaksbr | default:"<em>No description</em>" }}</p>
{% if raid.is_optional %}
<p class="card-text mb-0"><small class="text-muted">This raid is optional.</small></p>
{% endif %}
<p class="card-text"><small class="text-muted">Response deadline: {{ raid.response_deadline }}.</small></p>
</div>
</div>

24
migrate.py Normal file
View file

@ -0,0 +1,24 @@
import json
with open("data.json", "r") as file:
data = json.load(file)
for o in data:
print(o)
if o["model"] == "raids.raidresponse":
if o["fields"]["status"] >= 2: # SIGNED_UP
o["fields"]["attendance"] = 1.0
else:
o["fields"]["attendance"] = 0.0
if o["model"] == "users.user":
o["fields"]["rank"] = 3 # veteran
print("=============================================")
print("=============================================")
print("=============================================")
with open("new.json", "w") as file:
skip = ["contenttypes.contenttype", "auth.permission", "admin.logentry"]
thedump = [d for d in data if d["model"] not in skip]
for d in thedump:
print(d)
json.dump(thedump, file)