add first views, a bit html and urls
This commit is contained in:
parent
8aa459d2ef
commit
76b81d230a
|
@ -14,8 +14,9 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('writing/', include('writingtogether.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,31 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Geschichten!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Geschichten!</h1>
|
||||||
|
|
||||||
|
{% if latest_story_round_list %}
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for question in latest_story_round_list %}
|
||||||
|
<li><a href="/polls/{{ story.id }}"></a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<p>Noch keine Geschichten vorhanden.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form action="{% url 'writing:create_story_round' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Neue Runde">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form action="{% url 'writing:create_story_round' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,12 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = 'writing'
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.IndexView.as_view(), name='index'),
|
||||||
|
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
|
||||||
|
path('create', views.StoryRoundCreate.as_view(), name='create_story_round'),
|
||||||
|
path('<int:pk>/<int:previous>/', views.StoryPartCreate, name='create_story_part'),
|
||||||
|
]
|
|
@ -1,3 +1,60 @@
|
||||||
|
from django import forms
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from django.views import generic
|
||||||
|
from django.views.generic import CreateView, UpdateView
|
||||||
|
|
||||||
|
from writingtogether.models import Story, StoryPart, StoryRound, Participant
|
||||||
|
|
||||||
|
|
||||||
|
class IndexView(generic.ListView):
|
||||||
|
template_name = 'writingtogether/index.html'
|
||||||
|
context_object_name = 'latest_story_round_list'
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return StoryRound.objects.order_by('-created')[:5]
|
||||||
|
|
||||||
|
|
||||||
|
class DetailView(generic.DetailView):
|
||||||
|
model = StoryRound
|
||||||
|
template_name = 'writingtogether/detail.html'
|
||||||
|
|
||||||
|
|
||||||
|
class StoryRoundCreate(CreateView):
|
||||||
|
model = StoryRound
|
||||||
|
fields = ['name', 'participants', 'number_of_rounds']
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
self.object = form.save()
|
||||||
|
|
||||||
|
for user in form.cleaned_data['participants']:
|
||||||
|
participant = Participant.objects.create(
|
||||||
|
user=user,
|
||||||
|
order_by=1, # TODO: get order by from form
|
||||||
|
story_round=self.object
|
||||||
|
)
|
||||||
|
|
||||||
|
Story.objects.create(
|
||||||
|
part_of_round=self.object,
|
||||||
|
started_by=participant
|
||||||
|
)
|
||||||
|
|
||||||
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
||||||
|
class StoryUpdate(UpdateView):
|
||||||
|
model = Story
|
||||||
|
fields = ['name']
|
||||||
|
|
||||||
|
|
||||||
|
class StoryPartCreate(CreateView):
|
||||||
|
model = StoryPart
|
||||||
|
fields = ['text']
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.created_by = self.request.user
|
||||||
|
form.instance.previous_part_id = self.kwargs['previous']
|
||||||
|
form.instance.part_of_id = self.kwargs['pk']
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
Loading…
Reference in New Issue