more basic setup
This commit is contained in:
parent
36e2ee216d
commit
fc748f8596
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
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"}),
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -82,7 +82,10 @@ class PlaySession(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("guild:playsession_detail", kwargs={"pk": self.pk})
|
return reverse(
|
||||||
|
"guild:playsession_detail",
|
||||||
|
kwargs={"pk": self.adventure.pk, "playsession_pk": self.pk}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ResourceEarned(models.Model):
|
class ResourceEarned(models.Model):
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load guild_extras %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Adventure: {{ adventure.name }}</h1>
|
||||||
|
|
||||||
|
<p>{{adventure.description|md|safe}}</p>
|
||||||
|
|
||||||
|
<a href="{% url 'guild:create_playsession' adventure.id %}">Add new Session</a>
|
||||||
|
|
||||||
|
|
||||||
|
{% if not adventure.playsession_set.count %}
|
||||||
|
<p>No sessions found.</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>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock content %}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Create Adventure">
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load guild_extras %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Character: {{ character.name }}</h1>
|
<h1>Character: {{ character.name }}</h1>
|
||||||
|
|
||||||
|
@ -10,6 +12,6 @@
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<p>{{character.description}}</p>
|
<p>{{character.description|md|safe}}</p>
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
|
@ -3,8 +3,17 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
<a href="{% url 'guild:create_player' %}">Create New Player</a>
|
<a href="{% url 'guild:create_player' %}">Create New Player</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
<a href="{% url 'guild:create_character' %}">Create New Character</a>
|
<a href="{% url 'guild:create_character' %}">Create New Character</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'guild:create_adventure' %}">Create New Adventure</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<h2>Characters</h2>
|
<h2>Characters</h2>
|
||||||
|
|
||||||
{% if not player.character_set %}
|
{% if not player.character_set.count %}
|
||||||
<p>No characters found.</p>
|
<p>No characters found.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
{% 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 %}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Create Adventure">
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import markdown
|
||||||
|
from django import template
|
||||||
|
from django.template.defaultfilters import stringfilter
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.filter(name='md')
|
||||||
|
@stringfilter
|
||||||
|
def md(value):
|
||||||
|
return markdown.markdown(value)
|
|
@ -2,6 +2,7 @@ from django.urls import path
|
||||||
import guild.views as views
|
import guild.views as views
|
||||||
import guild.views.player as player_views
|
import guild.views.player as player_views
|
||||||
import guild.views.character as character_views
|
import guild.views.character as character_views
|
||||||
|
import guild.views.adventure as adventure_views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.HomeView.as_view(), name="home"),
|
path("", views.HomeView.as_view(), name="home"),
|
||||||
|
@ -10,4 +11,8 @@ urlpatterns = [
|
||||||
path("players/<int:pk>/", player_views.PlayerDetailView.as_view(), name="player_detail"),
|
path("players/<int:pk>/", player_views.PlayerDetailView.as_view(), name="player_detail"),
|
||||||
path("characters/create/", character_views.CreateCharacterView.as_view(), name="create_character"),
|
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>/", 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"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
from typing import Any, Dict, Optional, Type
|
||||||
|
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.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from guild.forms import PlaySessionForm
|
||||||
|
|
||||||
|
from guild.models import Adventure, PlaySession
|
||||||
|
|
||||||
|
|
||||||
|
class CreateAdventureView(LoginRequiredMixin, CreateView):
|
||||||
|
model = Adventure
|
||||||
|
fields = ["name", "description", "master"]
|
||||||
|
|
||||||
|
class AdventureDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
model = Adventure
|
||||||
|
|
||||||
|
class CreatePlaySessionView(LoginRequiredMixin, CreateView):
|
||||||
|
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)
|
||||||
|
|
||||||
|
def form_valid(self, form: BaseModelForm) -> HttpResponse:
|
||||||
|
form.instance.adventure = self.adventure
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
class PlaySessionDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
model = PlaySession
|
||||||
|
pk_url_kwarg = "playsession_pk"
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return super().get_queryset().filter(adventure_id=self.kwargs["pk"])
|
Loading…
Reference in New Issue