diff --git a/guild/forms.py b/guild/forms.py index feb8b33..04eec4f 100644 --- a/guild/forms.py +++ b/guild/forms.py @@ -1,5 +1,6 @@ from django import forms -from guild.models import PlaySession, Character +from guild.models import PlaySession, Character, Reward +from django.utils.translation import gettext as _ class PlaySessionCharacterForm(forms.ModelMultipleChoiceField): @@ -23,3 +24,15 @@ class PlaySessionForm(forms.ModelForm): "date": forms.DateInput(attrs={"type": "date"}), "summary": forms.Textarea(attrs={"rows": 32}), } + + +class RewardForm(forms.ModelForm): + character = forms.ModelChoiceField( + queryset=Character.objects.all(), + empty_label="All Guild Members", + required=False, + ) + + class Meta: + model = Reward + fields = ["amount", "resource", "character"] diff --git a/guild/migrations/0005_adventure_created_at_adventure_updated_at_and_more.py b/guild/migrations/0005_adventure_created_at_adventure_updated_at_and_more.py new file mode 100644 index 0000000..fd0b911 --- /dev/null +++ b/guild/migrations/0005_adventure_created_at_adventure_updated_at_and_more.py @@ -0,0 +1,115 @@ +# Generated by Django 4.2.1 on 2023-06-20 18:10 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0004_alter_playsession_options_player_address"), + ] + + operations = [ + migrations.AddField( + model_name="adventure", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="adventure", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AddField( + model_name="character", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="character", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AddField( + model_name="player", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="player", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AddField( + model_name="playsession", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="playsession", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AddField( + model_name="resource", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="resource", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AddField( + model_name="resourceearned", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, + default=django.utils.timezone.now, + verbose_name="created at", + ), + preserve_default=False, + ), + migrations.AddField( + model_name="resourceearned", + name="updated_at", + field=models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + migrations.AlterField( + model_name="resourceearned", + name="character", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="guild.character", + verbose_name="character", + ), + ), + ] diff --git a/guild/migrations/0006_alter_resource_name.py b/guild/migrations/0006_alter_resource_name.py new file mode 100644 index 0000000..8f7d1fd --- /dev/null +++ b/guild/migrations/0006_alter_resource_name.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.1 on 2023-06-20 18:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0005_adventure_created_at_adventure_updated_at_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="resource", + name="name", + field=models.CharField(max_length=255, unique=True), + ), + ] diff --git a/guild/migrations/0007_resourceearned_playsession.py b/guild/migrations/0007_resourceearned_playsession.py new file mode 100644 index 0000000..3b12043 --- /dev/null +++ b/guild/migrations/0007_resourceearned_playsession.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.1 on 2023-06-20 18:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0006_alter_resource_name"), + ] + + operations = [ + migrations.AddField( + model_name="resourceearned", + name="playsession", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="guild.playsession", + verbose_name="playsession", + ), + ), + ] diff --git a/guild/migrations/0008_alter_resourceearned_playsession.py b/guild/migrations/0008_alter_resourceearned_playsession.py new file mode 100644 index 0000000..20a6fdd --- /dev/null +++ b/guild/migrations/0008_alter_resourceearned_playsession.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.1 on 2023-06-20 18:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0007_resourceearned_playsession"), + ] + + operations = [ + migrations.AlterField( + model_name="resourceearned", + name="playsession", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="guild.playsession", + verbose_name="playsession", + ), + ), + ] diff --git a/guild/migrations/0009_rename_resourceearned_reward_alter_reward_options.py b/guild/migrations/0009_rename_resourceearned_reward_alter_reward_options.py new file mode 100644 index 0000000..22502db --- /dev/null +++ b/guild/migrations/0009_rename_resourceearned_reward_alter_reward_options.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.1 on 2023-06-20 18:48 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0008_alter_resourceearned_playsession"), + ] + + operations = [ + migrations.RenameModel( + old_name="ResourceEarned", + new_name="Reward", + ), + migrations.AlterModelOptions( + name="reward", + options={"verbose_name": "reward", "verbose_name_plural": "rewards"}, + ), + ] diff --git a/guild/models.py b/guild/models.py index 411a201..24e9db3 100644 --- a/guild/models.py +++ b/guild/models.py @@ -8,6 +8,9 @@ class Player(models.Model): address = models.TextField(_("address"), blank=True) + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + class Meta: verbose_name = _("player") verbose_name_plural = _("players") @@ -20,9 +23,12 @@ class Player(models.Model): class Resource(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) description = models.TextField() + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + class Meta: verbose_name = _("resource") verbose_name_plural = _("resources") @@ -46,6 +52,9 @@ class Adventure(models.Model): blank=True, ) + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + @property def last_session(self): return self.playsession_set.order_by("-date").first() @@ -82,6 +91,9 @@ class Character(models.Model): blank=True, ) + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + class Meta: verbose_name = _("character") verbose_name_plural = _("characters") @@ -102,6 +114,9 @@ class PlaySession(models.Model): summary = models.TextField() + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + class Meta: verbose_name = _("playsession") verbose_name_plural = _("playsessions") @@ -118,25 +133,34 @@ class PlaySession(models.Model): ) -class ResourceEarned(models.Model): +class Reward(models.Model): resource = models.ForeignKey( "Resource", verbose_name=_("resource"), on_delete=models.CASCADE ) character = models.ForeignKey( "Character", verbose_name=_("character"), - on_delete=models.CASCADE, + on_delete=models.SET_NULL, null=True, blank=True, ) + playsession = models.ForeignKey( + "PlaySession", + verbose_name=_("playsession"), + on_delete=models.CASCADE, + null=False, + ) amount = models.IntegerField() + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + class Meta: - verbose_name = _("resourceearned") - verbose_name_plural = _("resourceearneds") + verbose_name = _("reward") + verbose_name_plural = _("rewards") def __str__(self): - return self.name + return f"{self.resource.name} ({self.amount}) - {self.character}" def get_absolute_url(self): - return reverse("guild:resourceearned_detail", kwargs={"pk": self.pk}) + return reverse("guild:reward_detail", kwargs={"pk": self.pk}) diff --git a/guild/templates/guild/adventure_detail.html b/guild/templates/guild/adventure_detail.html index 6027039..a336661 100644 --- a/guild/templates/guild/adventure_detail.html +++ b/guild/templates/guild/adventure_detail.html @@ -42,7 +42,9 @@ {% else %} {% for playsession in adventure.playsession_set.all %}
@@ -51,7 +53,7 @@No rewards.
+{% else %} +Amount | +Resource | +Character | ++ |
---|---|---|---|
{{ reward.amount }} | +{{ reward.resource.name }} | ++ {% if reward.character %} + {{ reward.character.name }} + {% else %} + Every Guild Member + {% endif %} + | ++ Remove + | +
No rewards earned.
+{% endif %} + +{{playsession.summary|md|safe}}
+ +{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/resource_detail.html b/guild/templates/guild/resource_detail.html new file mode 100644 index 0000000..7d860ae --- /dev/null +++ b/guild/templates/guild/resource_detail.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} + +{% block content %} ++ {{ resource.description|linebreaks }} +
+{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/resource_form.html b/guild/templates/guild/resource_form.html new file mode 100644 index 0000000..20792ba --- /dev/null +++ b/guild/templates/guild/resource_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} + +{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/reward_confirm_delete.html b/guild/templates/guild/reward_confirm_delete.html new file mode 100644 index 0000000..44cf3a2 --- /dev/null +++ b/guild/templates/guild/reward_confirm_delete.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block content %} + +Are you sure you want to delete + + {{ reward.amount }} {{ reward.resource.name }} - + {% if reward.character %} + {{ reward.character.name }} + {% else %} + Every Guild Member + {% endif %} +? +
+ + +{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/reward_form.html b/guild/templates/guild/reward_form.html new file mode 100644 index 0000000..a273132 --- /dev/null +++ b/guild/templates/guild/reward_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} + +{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/settings.html b/guild/templates/guild/settings.html new file mode 100644 index 0000000..3c11f91 --- /dev/null +++ b/guild/templates/guild/settings.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + +{% block content %} +