This commit is contained in:
Niko Abeler 2023-06-11 21:25:30 +02:00
parent 10d81cb447
commit 30b00b35e4
17 changed files with 330 additions and 145 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"python.formatting.provider": "none",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
}

View File

@ -2,5 +2,5 @@ from django.apps import AppConfig
class GuildConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'guild'
default_auto_field = "django.db.models.BigAutoField"
name = "guild"

View File

@ -1,17 +1,12 @@
from django import forms
from guild.models import PlaySession
class PlaySessionForm(forms.ModelForm):
class Meta:
model = PlaySession
fields = ["date", "characters", "summary"]
# set date wideget to type="date"
widgets = {
"date": forms.DateInput(attrs={"type": "date"}),
}

View File

@ -5,70 +5,124 @@ import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
dependencies = []
operations = [
migrations.CreateModel(
name='Adventure',
name="Adventure",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("description", models.TextField()),
],
options={
'verbose_name': 'Adventure',
'verbose_name_plural': 'Adventures',
"verbose_name": "Adventure",
"verbose_name_plural": "Adventures",
},
),
migrations.CreateModel(
name='Character',
name="Character",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("description", models.TextField()),
],
options={
'verbose_name': 'character',
'verbose_name_plural': 'characters',
"verbose_name": "character",
"verbose_name_plural": "characters",
},
),
migrations.CreateModel(
name='Player',
name="Player",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
],
options={
'verbose_name': 'player',
'verbose_name_plural': 'players',
"verbose_name": "player",
"verbose_name_plural": "players",
},
),
migrations.CreateModel(
name='PlaySession',
name="PlaySession",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField()),
('summary', models.TextField()),
('adventure', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='guild.adventure', verbose_name='adventure')),
('characters', models.ManyToManyField(to='guild.character', verbose_name='characters')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("date", models.DateField()),
("summary", models.TextField()),
(
"adventure",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="guild.adventure",
verbose_name="adventure",
),
),
(
"characters",
models.ManyToManyField(
to="guild.character", verbose_name="characters"
),
),
],
options={
'verbose_name': 'playsession',
'verbose_name_plural': 'playsessions',
"verbose_name": "playsession",
"verbose_name_plural": "playsessions",
},
),
migrations.AddField(
model_name='character',
name='player',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='guild.player', verbose_name='player'),
model_name="character",
name="player",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="guild.player",
verbose_name="player",
),
),
migrations.AddField(
model_name='adventure',
name='master',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='guild.player', verbose_name='master'),
model_name="adventure",
name="master",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="guild.player",
verbose_name="master",
),
),
]

View File

@ -5,40 +5,71 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('guild', '0001_initial'),
("guild", "0001_initial"),
]
operations = [
migrations.CreateModel(
name='Resource',
name="Resource",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("description", models.TextField()),
],
options={
'verbose_name': 'resource',
'verbose_name_plural': 'resources',
"verbose_name": "resource",
"verbose_name_plural": "resources",
},
),
migrations.AlterField(
model_name='player',
name='name',
model_name="player",
name="name",
field=models.CharField(max_length=255, unique=True),
),
migrations.CreateModel(
name='ResourceEarned',
name="ResourceEarned",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.IntegerField()),
('character', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='guild.character', verbose_name='character')),
('resource', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='guild.resource', verbose_name='resource')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("amount", models.IntegerField()),
(
"character",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="guild.character",
verbose_name="character",
),
),
(
"resource",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="guild.resource",
verbose_name="resource",
),
),
],
options={
'verbose_name': 'resourceearned',
'verbose_name_plural': 'resourceearneds',
"verbose_name": "resourceearned",
"verbose_name_plural": "resourceearneds",
},
),
]

View File

@ -2,8 +2,8 @@ from django.db import models
from django.urls import reverse
from django.utils.translation import gettext as _
class Player(models.Model):
class Player(models.Model):
name = models.CharField(max_length=255, unique=True)
class Meta:
@ -16,8 +16,8 @@ class Player(models.Model):
def get_absolute_url(self):
return reverse("guild:player_detail", kwargs={"pk": self.pk})
class Resource(models.Model):
class Resource(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
@ -33,11 +33,16 @@ class Resource(models.Model):
class Adventure(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
master = models.ForeignKey("Player", verbose_name=_("master"), on_delete=models.SET_NULL, null=True, blank=True)
master = models.ForeignKey(
"Player",
verbose_name=_("master"),
on_delete=models.SET_NULL,
null=True,
blank=True,
)
class Meta:
verbose_name = _("Adventure")
@ -54,7 +59,13 @@ class Character(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
player = models.ForeignKey("Player", verbose_name=_("player"), on_delete=models.SET_NULL, null=True, blank=True)
player = models.ForeignKey(
"Player",
verbose_name=_("player"),
on_delete=models.SET_NULL,
null=True,
blank=True,
)
class Meta:
verbose_name = _("character")
@ -66,10 +77,12 @@ class Character(models.Model):
def get_absolute_url(self):
return reverse("guild:character_detail", kwargs={"pk": self.pk})
class PlaySession(models.Model):
class PlaySession(models.Model):
date = models.DateField()
adventure = models.ForeignKey("Adventure", verbose_name=_("adventure"), on_delete=models.CASCADE)
adventure = models.ForeignKey(
"Adventure", verbose_name=_("adventure"), on_delete=models.CASCADE
)
characters = models.ManyToManyField("Character", verbose_name=_("characters"))
summary = models.TextField()
@ -82,16 +95,24 @@ class PlaySession(models.Model):
return self.name
def get_absolute_url(self):
return reverse(
"guild:adventure_detail",
kwargs={"pk": self.adventure.pk}
) + "#playsession" + str(self.pk)
return (
reverse("guild:adventure_detail", kwargs={"pk": self.adventure.pk})
+ "#playsession"
+ str(self.pk)
)
class ResourceEarned(models.Model):
resource = models.ForeignKey("Resource", verbose_name=_("resource"), on_delete=models.CASCADE)
character = models.ForeignKey("Character", verbose_name=_("character"), on_delete=models.CASCADE, null=True, blank=True)
resource = models.ForeignKey(
"Resource", verbose_name=_("resource"), on_delete=models.CASCADE
)
character = models.ForeignKey(
"Character",
verbose_name=_("character"),
on_delete=models.CASCADE,
null=True,
blank=True,
)
amount = models.IntegerField()
class Meta:

View File

@ -4,7 +4,8 @@ from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter(name='md')
@register.filter(name="md")
@stringfilter
def md(value):
return markdown.markdown(value)

View File

@ -7,21 +7,87 @@ import guild.views.adventure as adventure_views
urlpatterns = [
path("", views.HomeView.as_view(), name="home"),
# path("players/", views.PlayerListView.as_view(), name="player_list"),
path("players/create/", player_views.CreatePlayerView.as_view(), name="create_player"),
path("players/<int:pk>/", player_views.PlayerDetailView.as_view(), name="player_detail"),
path("players/<int:pk>/update/", player_views.PlayerUpdateView.as_view(), name="player_update"),
path("players/<int:pk>/delete/", player_views.PlayerDeleteView.as_view(), name="player_delete"),
path("characters/", character_views.CharacterListView.as_view(), name="character_list"),
path("characters/create/", character_views.CreateCharacterView.as_view(), name="create_character"),
path("characters/<int:pk>/", character_views.CharacterDetailView.as_view(), name="character_detail"),
path("characters/<int:pk>/update/", character_views.CharacterUpdateView.as_view(), name="character_update"),
path("characters/<int:pk>/delete/", character_views.CharacterDeleteView.as_view(), name="character_delete"),
path("adventures/", adventure_views.AdventureListView.as_view(), name="adventure_list"),
path("adventures/create/", adventure_views.CreateAdventureView.as_view(), name="create_adventure"),
path("adventures/<int:pk>/", adventure_views.AdventureDetailView.as_view(), name="adventure_detail"),
path("adventures/<int:pk>/update/", adventure_views.AdventureUpdateView.as_view(), name="adventure_update"),
path("adventures/<int:pk>/delete/", adventure_views.AdventureDeleteView.as_view(), name="adventure_delete"),
path("adventures/<int:pk>/playsession/create/", adventure_views.PlaySessionCreateView.as_view(), name="create_playsession"),
path("adventures/<int:pk>/playsession/<int:playsession_pk>/update/", adventure_views.PlaySessionUpdateView.as_view(), name="playsession_update"),
path("adventures/<int:pk>/playsession/<int:playsession_pk>/delete/", adventure_views.PlaySessionDeleteView.as_view(), name="playsession_delete"),
path(
"players/create/", player_views.CreatePlayerView.as_view(), name="create_player"
),
path(
"players/<int:pk>/",
player_views.PlayerDetailView.as_view(),
name="player_detail",
),
path(
"players/<int:pk>/update/",
player_views.PlayerUpdateView.as_view(),
name="player_update",
),
path(
"players/<int:pk>/delete/",
player_views.PlayerDeleteView.as_view(),
name="player_delete",
),
path(
"characters/",
character_views.CharacterListView.as_view(),
name="character_list",
),
path(
"characters/create/",
character_views.CreateCharacterView.as_view(),
name="create_character",
),
path(
"characters/<int:pk>/",
character_views.CharacterDetailView.as_view(),
name="character_detail",
),
path(
"characters/<int:pk>/update/",
character_views.CharacterUpdateView.as_view(),
name="character_update",
),
path(
"characters/<int:pk>/delete/",
character_views.CharacterDeleteView.as_view(),
name="character_delete",
),
path(
"adventures/",
adventure_views.AdventureListView.as_view(),
name="adventure_list",
),
path(
"adventures/create/",
adventure_views.CreateAdventureView.as_view(),
name="create_adventure",
),
path(
"adventures/<int:pk>/",
adventure_views.AdventureDetailView.as_view(),
name="adventure_detail",
),
path(
"adventures/<int:pk>/update/",
adventure_views.AdventureUpdateView.as_view(),
name="adventure_update",
),
path(
"adventures/<int:pk>/delete/",
adventure_views.AdventureDeleteView.as_view(),
name="adventure_delete",
),
path(
"adventures/<int:pk>/playsession/create/",
adventure_views.PlaySessionCreateView.as_view(),
name="create_playsession",
),
path(
"adventures/<int:pk>/playsession/<int:playsession_pk>/update/",
adventure_views.PlaySessionUpdateView.as_view(),
name="playsession_update",
),
path(
"adventures/<int:pk>/playsession/<int:playsession_pk>/delete/",
adventure_views.PlaySessionDeleteView.as_view(),
name="playsession_delete",
),
]

View File

@ -4,6 +4,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Adventure, Character, Player
# Create your views here.
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "guild/home.html"
@ -14,5 +15,3 @@ class HomeView(LoginRequiredMixin, TemplateView):
context["players"] = Player.objects.all()
context["characters"] = Character.objects.all()
return context

View File

@ -1,4 +1,3 @@
from typing import Any, Dict, Optional, Type
from django.forms.models import BaseModelForm
from django.http import HttpResponse
@ -15,21 +14,26 @@ class AdventureListView(LoginRequiredMixin, ListView):
model = Adventure
context_object_name = "adventures"
class CreateAdventureView(LoginRequiredMixin, CreateView):
model = Adventure
fields = ["name", "description", "master"]
class AdventureDetailView(LoginRequiredMixin, DetailView):
model = Adventure
class AdventureUpdateView(LoginRequiredMixin, UpdateView):
model = Adventure
fields = ["name", "description", "master"]
class AdventureDeleteView(LoginRequiredMixin, DeleteView):
model = Adventure
success_url = "/"
class PlaySessionCreateView(LoginRequiredMixin, CreateView):
model = PlaySession
form_class = PlaySessionForm
@ -42,6 +46,7 @@ class PlaySessionCreateView(LoginRequiredMixin, CreateView):
form.instance.adventure = self.adventure
return super().form_valid(form)
class PlaySessionUpdateView(LoginRequiredMixin, UpdateView):
model = PlaySession
form_class = PlaySessionForm
@ -50,6 +55,7 @@ class PlaySessionUpdateView(LoginRequiredMixin, UpdateView):
self.adventure = get_object_or_404(Adventure, pk=kwargs["pk"])
return super().dispatch(request, *args, **kwargs)
class PlaySessionDeleteView(LoginRequiredMixin, DeleteView):
model = PlaySession
pk_url_kwarg = "playsession_pk"

View File

@ -1,4 +1,3 @@
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
@ -10,17 +9,21 @@ class CharacterListView(LoginRequiredMixin, ListView):
model = Character
context_object_name = "characters"
class CreateCharacterView(LoginRequiredMixin, CreateView):
model = Character
fields = ["name", "description", "player"]
class CharacterDetailView(LoginRequiredMixin, DetailView):
model = Character
class CharacterUpdateView(LoginRequiredMixin, UpdateView):
model = Character
fields = ["name", "description", "player"]
class CharacterDeleteView(LoginRequiredMixin, DeleteView):
model = Character
success_url = "/"

View File

@ -1,4 +1,3 @@
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
@ -10,13 +9,16 @@ class CreatePlayerView(LoginRequiredMixin, CreateView):
model = Player
fields = ["name"]
class PlayerDetailView(LoginRequiredMixin, DetailView):
model = Player
class PlayerUpdateView(LoginRequiredMixin, UpdateView):
model = Player
fields = ["name"]
class PlayerDeleteView(LoginRequiredMixin, DeleteView):
model = Player
success_url = "/"

View File

@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'guild_journal.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guild_journal.settings")
application = get_asgi_application()

View File

@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-e*p%e)pwf+-ntt4wpn-^^7-0yq)!cjo*om18vy77-=*c0jjfqa'
SECRET_KEY = "django-insecure-e*p%e)pwf+-ntt4wpn-^^7-0yq)!cjo*om18vy77-=*c0jjfqa"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@ -31,55 +31,55 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"guild"
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"guild",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = 'guild_journal.urls'
ROOT_URLCONF = "guild_journal.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
BASE_DIR / "templates",
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = 'guild_journal.wsgi.application'
WSGI_APPLICATION = "guild_journal.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
@ -89,16 +89,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
@ -106,9 +106,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"
USE_I18N = True
@ -118,7 +118,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
STATIC_URL = "static/"
STATICFILES_DIRS = [
BASE_DIR / "static",
@ -127,4 +127,4 @@ STATICFILES_DIRS = [
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

View File

@ -18,7 +18,7 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
path("accounts/", include("django.contrib.auth.urls")),
path("", include(("guild.urls", "guild"), namespace="guild")),
]

View File

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'guild_journal.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guild_journal.settings")
application = get_wsgi_application()

View File

@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'guild_journal.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guild_journal.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()