From 452d6f22beb40f599de0b7ed5d4fc55177102d10 Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 2 Oct 2018 12:38:17 -0400 Subject: [PATCH] merged /create_quest into /quest/new --- create_quest/__init__.py | 0 create_quest/admin.py | 3 -- create_quest/apps.py | 5 --- create_quest/forms.py | 24 ----------- create_quest/migrations/__init__.py | 0 create_quest/models.py | 3 -- create_quest/tests.py | 3 -- create_quest/urls.py | 12 ------ create_quest/views.py | 43 ------------------- homepage/jinja2/homepage/index.html | 2 +- quest/forms.py | 20 +++++++++ .../jinja2/quest/new_quest.html | 2 +- quest/urls.py | 1 + quest/views.py | 42 +++++++++++++++++- titivillus/settings.py | 1 - 15 files changed, 63 insertions(+), 98 deletions(-) delete mode 100644 create_quest/__init__.py delete mode 100644 create_quest/admin.py delete mode 100644 create_quest/apps.py delete mode 100644 create_quest/forms.py delete mode 100644 create_quest/migrations/__init__.py delete mode 100644 create_quest/models.py delete mode 100644 create_quest/tests.py delete mode 100644 create_quest/urls.py delete mode 100644 create_quest/views.py rename create_quest/jinja2/create_quest/index.html => quest/jinja2/quest/new_quest.html (87%) diff --git a/create_quest/__init__.py b/create_quest/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/create_quest/admin.py b/create_quest/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/create_quest/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/create_quest/apps.py b/create_quest/apps.py deleted file mode 100644 index 04b930c..0000000 --- a/create_quest/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class CreateQuestConfig(AppConfig): - name = 'create_quest' diff --git a/create_quest/forms.py b/create_quest/forms.py deleted file mode 100644 index 8cdc7e2..0000000 --- a/create_quest/forms.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 -""" -Form(s) for the create_quest page. -""" -from django import forms - -from quest.models import Quest, Post - -class QuestForm(forms.ModelForm): - """ - The main create_quest form. - """ - class Meta: - model = Quest - fields = ('title',) - - -class PostForm(forms.ModelForm): - """ - The form for beginning the first post of the quest. - """ - class Meta: - model = Post - fields = ('post_text',) diff --git a/create_quest/migrations/__init__.py b/create_quest/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/create_quest/models.py b/create_quest/models.py deleted file mode 100644 index 71a8362..0000000 --- a/create_quest/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/create_quest/tests.py b/create_quest/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/create_quest/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/create_quest/urls.py b/create_quest/urls.py deleted file mode 100644 index 54df747..0000000 --- a/create_quest/urls.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python3 -""" -create_quest app URL configuration. -""" -from django.urls import path - -from . import views - -app_name = 'create_quest' -urlpatterns = [ - path('', views.index, name='index'), -] diff --git a/create_quest/views.py b/create_quest/views.py deleted file mode 100644 index d3a9ee9..0000000 --- a/create_quest/views.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 -""" -/create_quest app views. -""" -from django.contrib import messages -from django.shortcuts import redirect, render - -from .forms import QuestForm, PostForm -from quest.models import Quest, Post, Page - -def index(request): - """ - The index page for creating new quests. - """ - if request.method == 'POST': - # TODO: clean the post body - quest = Quest(owner=request.user) - quest_form = QuestForm(request.POST, instance=quest) - post = Post(post_type='text') - post_form = PostForm(request.POST, instance=post) - if all((quest_form.is_valid(), post_form.is_valid())): - quest.save() - page0 = Page( - quest=quest, - page_num=0, - title="Homepage" - ) - page0.save() - page1 = Page( - quest=quest, - page_num=1, - title="Page 1" - ) - page1.save() - post.quest = quest - post.page = page1 - post.save() - return redirect('quest:quest', quest_id=quest.id) - else: - quest_form = QuestForm() - post_form = PostForm() - context = {'quest_form': quest_form, 'post_form': post_form} - return render(request, 'create_quest/index.html', context) diff --git a/homepage/jinja2/homepage/index.html b/homepage/jinja2/homepage/index.html index 0c2b2bc..6eb4013 100644 --- a/homepage/jinja2/homepage/index.html +++ b/homepage/jinja2/homepage/index.html @@ -10,7 +10,7 @@
Unga Bunga Quest
{% if request.user.is_authenticated %} - Create New Quest
+ Create New Quest
Logout
{% else %} Sign up
diff --git a/quest/forms.py b/quest/forms.py index d236af9..a9f42d7 100644 --- a/quest/forms.py +++ b/quest/forms.py @@ -4,6 +4,8 @@ Form(s) for the quest page. """ from django import forms +from .models import Quest, Post + class DiceCallForm(forms.Form): """ The form for the QM making dice calls. @@ -46,3 +48,21 @@ class EditQuestForm(forms.Form): live_date = forms.DateField(required=False) live_time = forms.TimeField(required=False) timezone = forms.IntegerField() + + +class QuestForm(forms.ModelForm): + """ + The main create_quest form. + """ + class Meta: + model = Quest + fields = ('title',) + + +class PostForm(forms.ModelForm): + """ + The form for beginning the first post of the quest. + """ + class Meta: + model = Post + fields = ('post_text',) diff --git a/create_quest/jinja2/create_quest/index.html b/quest/jinja2/quest/new_quest.html similarity index 87% rename from create_quest/jinja2/create_quest/index.html rename to quest/jinja2/quest/new_quest.html index 911537f..f5cfe10 100644 --- a/create_quest/jinja2/create_quest/index.html +++ b/quest/jinja2/quest/new_quest.html @@ -2,7 +2,7 @@ {% block title %}Start a new quest{% endblock %} {% block content %}

New Quest

-
+ {{ csrf_input }} {#
diff --git a/quest/urls.py b/quest/urls.py index 14d7db4..100753c 100644 --- a/quest/urls.py +++ b/quest/urls.py @@ -13,4 +13,5 @@ urlpatterns = [ path('//edit_quest', views.edit_quest, name='edit_quest'), path('', views.quest, name='quest'), path('/', views.quest, name='quest'), + path('new', views.new_quest, name='new_quest'), ] diff --git a/quest/views.py b/quest/views.py index c6a7196..15056a1 100644 --- a/quest/views.py +++ b/quest/views.py @@ -8,8 +8,8 @@ from django.contrib import messages from django.http import HttpResponse from django.shortcuts import render, redirect -from .models import Quest, DiceRoll, PollOption, PollVote, Page -from .forms import EditQuestForm +from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post +from .forms import EditQuestForm, QuestForm, PostForm def index(request): """ @@ -81,3 +81,41 @@ def edit_quest(request, quest_id, page_num=1): pass context = locals() return render(request, 'quest/edit_quest.html', context) + + +def new_quest(request): + """ + The page for creating new quests. + """ + if request.method == 'POST': + # TODO: clean the post body + quest = Quest(owner=request.user) + quest_form = QuestForm(request.POST, instance=quest) + post = Post(post_type='text') + post_form = PostForm(request.POST, instance=post) + if all((quest_form.is_valid(), post_form.is_valid())): + quest.live = False + quest.save() + page0 = Page( + quest=quest, + page_num=0, + title="Homepage", + appendix=False, + ) + page0.save() + page1 = Page( + quest=quest, + page_num=1, + title="Page 1", + appendix=False, + ) + page1.save() + post.quest = quest + post.page = page1 + post.save() + return redirect('quest:quest', quest_id=quest.id) + else: + quest_form = QuestForm() + post_form = PostForm() + context = {'quest_form': quest_form, 'post_form': post_form} + return render(request, 'quest/new_quest.html', context) diff --git a/titivillus/settings.py b/titivillus/settings.py index 1523bdb..c96a5c1 100644 --- a/titivillus/settings.py +++ b/titivillus/settings.py @@ -36,7 +36,6 @@ INSTALLED_APPS = [ 'taggit', 'user.apps.UserConfig', 'homepage.apps.HomepageConfig', - 'create_quest.apps.CreateQuestConfig', 'quest.apps.QuestConfig', 'login.apps.LoginConfig', 'signup.apps.SignupConfig',