refining adventure

This commit is contained in:
Niko Abeler 2023-06-11 20:01:36 +02:00
parent fc748f8596
commit 765cb98e13
12 changed files with 122 additions and 42 deletions

View File

@ -83,9 +83,9 @@ class PlaySession(models.Model):
def get_absolute_url(self):
return reverse(
"guild:playsession_detail",
kwargs={"pk": self.adventure.pk, "playsession_pk": self.pk}
)
"guild:adventure_detail",
kwargs={"pk": self.adventure.pk}
) + "#playsession" + str(self.pk)
class ResourceEarned(models.Model):

View File

@ -3,25 +3,63 @@
{% load guild_extras %}
{% block content %}
<h1>Adventure: {{ adventure.name }}</h1>
<div class="row">
<div class="column column-75">
<h1>Adventure: {{ adventure.name }}</h1>
</div>
<div class="column">
<a class="button button-outline" href="{% url 'guild:adventure_update' adventure.id %}">Edit</a>
</div>
<div class="column">
<a class="button button-clear" href="{% url 'guild:adventure_delete' adventure.id %}">Delete</a>
</div>
</div>
<p>{{adventure.description|md|safe}}</p>
<a href="{% url 'guild:create_playsession' adventure.id %}">Add new Session</a>
<div class="row">
<div class="column column-75">
<h2>Sessions</h2>
</div>
<div class="column">
<a class="button" href="{% url 'guild:create_playsession' adventure.id %}">Add new Session</a>
</div>
</div>
{% if not adventure.playsession_set.count %}
<p>No sessions found.</p>
<p>No sessions yet.</p>
{% else %}
<ul>
{% for playsession in adventure.playsession_set.all %}
<li>
<a href="{% url 'guild:playsession_detail' adventure.id playsession.id %}">
{{ playsession.date }}
</a>
</li>
<div class="row">
<div class="column column-75">
<h3>{{ playsession.date }}</h3>
</div>
<div class="column">
<a class="button button-outline" href="{% url 'guild:playsession_update' adventure.id playsession.id %}">Edit</a>
</div>
<div class="column">
<a class="button button-clear" href="{% url 'guild:playsession_delete' adventure.id playsession.id %}">Delete</a>
</div>
</div>
<h4>Characters</h4>
<ul>
{% for character in playsession.characters.all %}
<li>{{character.name}}</li>
{% endfor %}
</ul>
<h4>Summary</h4>
<p>{{playsession.summary|md|safe}}</p>
<hr>
{% endfor %}
</ul>
{% endif %}

View File

@ -4,6 +4,10 @@
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create Adventure">
{% if object %}
<input type="submit" value="Update Adventure">
{% else %}
<input type="submit" value="Create Adventure">
{% endif %}
</form>
{% endblock content %}

View File

@ -15,5 +15,15 @@
</li>
</ul>
<h2>Adventures</h2>
<ul>
{% for adventure in adventures %}
<li>
<a href="{% url 'guild:adventure_detail' adventure.id %}">{{ adventure.name }}</a>
</li>
{% endfor %}
</ul>
{% endblock content %}

View File

@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block content %}
<h1>Session Delete</h1>
<p>Are you sure you want to delete <strong>"{{ playsession.date }}"</strong> of the adventure <strong>{{ playsession.adventure.name}}</strong>?</p>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Delete Session">
</form>
{% endblock content %}

View File

@ -1,17 +0,0 @@
{% extends 'base.html' %}
{% load guild_extras %}
{% block content %}
<h1>Session: {{ playsession.name }}</h1>
<h2>
Adventure:
<a href="{% url 'guild:adventure_detail' playsession.adventure.id %}">
{{ playsession.adventure.name }}
</a>
</h2>
<p>{{playsession.summary|md|safe}}</p>
{% endblock content %}

View File

@ -4,6 +4,6 @@
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create Adventure">
<input type="submit" value="Create Session">
</form>
{% endblock content %}

View File

@ -13,6 +13,9 @@ urlpatterns = [
path("characters/<int:pk>/", character_views.CharacterDetailView.as_view(), name="character_detail"),
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>/playsession/create/", adventure_views.CreatePlaySessionView.as_view(), name="create_playsession"),
path("adventures/<int:pk>/playsession/<int:playsession_pk>/", adventure_views.PlaySessionDetailView.as_view(), name="playsession_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

@ -2,9 +2,15 @@ from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Player
from guild.models import Adventure, Player
# Create your views here.
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "guild/home.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["adventures"] = Adventure.objects.all()
return context

View File

@ -4,7 +4,7 @@ from django.forms.models import BaseModelForm
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
from guild.forms import PlaySessionForm
@ -18,7 +18,15 @@ class CreateAdventureView(LoginRequiredMixin, CreateView):
class AdventureDetailView(LoginRequiredMixin, DetailView):
model = Adventure
class CreatePlaySessionView(LoginRequiredMixin, CreateView):
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
@ -30,10 +38,21 @@ class CreatePlaySessionView(LoginRequiredMixin, CreateView):
form.instance.adventure = self.adventure
return super().form_valid(form)
class PlaySessionDetailView(LoginRequiredMixin, DetailView):
class PlaySessionUpdateView(LoginRequiredMixin, UpdateView):
model = PlaySession
form_class = PlaySessionForm
def dispatch(self, request, *args, **kwargs):
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"
def get_queryset(self):
return super().get_queryset().filter(adventure_id=self.kwargs["pk"])
def dispatch(self, request, *args, **kwargs):
self.adventure = get_object_or_404(Adventure, pk=kwargs["pk"])
return super().dispatch(request, *args, **kwargs)
def get_success_url(self) -> str:
return self.adventure.get_absolute_url()

3
static/milligram.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'pico.min.css' %}">
<link rel="stylesheet" href="{% static 'milligram.min.css' %}">
<title>Guild Journal</title>
</head>
<body>