revamped new_quest page, added description field

This commit is contained in:
iou1name 2018-10-05 08:48:07 -04:00
parent 75f5384723
commit e7d73023eb
7 changed files with 53 additions and 30 deletions

View File

@ -56,7 +56,7 @@ class QuestForm(forms.ModelForm):
"""
class Meta:
model = Quest
fields = ('title',)
fields = ('title', 'description', 'tags')
class PostForm(forms.ModelForm):

View File

@ -15,7 +15,7 @@
{% for quest in results %}
<tr>
<td class="title"><a href="{{ url('quest:quest', args=[quest.id, '0']) }}">{{ quest.title }}</a></td>
<td class="summary"></td>
<td class="summary">{{ quest.description or "" }}</td>
<td class="author"><a href="{{ url('user:profile', args=[quest.owner.id]) }}">{{ quest.owner.username }}</a></td>
</tr>
{% endfor %}

View File

@ -4,12 +4,9 @@
<h1>New Quest</h1>
<form method="post" action="{{ url('quest:new_quest') }}">
{{ csrf_input }}
{#
<input type="text" placeholder="Quest Title" name="quest_title" maxlength="300" required/><br/>
<textarea id="create_textarea" name="quest_body"></textarea>
#}
{{ quest_form.as_p() }}
{{ post_form.as_p() }}
<input type="submit" name="submit" value="Submit"/>
<input type="text" placeholder="Quest Title" name="title" maxlength="100" required><br>
<textarea name="description" maxlength="256"></textarea><br>
<input type="text" placeholder="Tags" name="tags" id=><br>
<input type="submit" name="submit" value="Submit">
</form>
{% endblock %}

View File

@ -0,0 +1,18 @@
# Generated by Django 2.1.1 on 2018-10-05 11:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('quest', '0006_quest_anonymize'),
]
operations = [
migrations.AddField(
model_name='quest',
name='description',
field=models.CharField(blank=True, max_length=256, null=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 2.1.1 on 2018-10-05 12:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('quest', '0007_quest_description'),
]
operations = [
migrations.AlterField(
model_name='quest',
name='live',
field=models.BooleanField(default=False),
),
]

View File

@ -16,10 +16,11 @@ class Quest(models.Model):
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
anon_name = models.CharField(max_length=20, default="Anonymous")
live = models.BooleanField()
live = models.BooleanField(default=False)
live_time = models.DateTimeField(blank=True, null=True)
tags = TaggableManager()
anonymize = models.BooleanField(default=True)
description = models.CharField(max_length=256, blank=True, null=True)
class Message(models.Model):

View File

@ -106,35 +106,24 @@ def new_quest(request):
return redirect('login:index')
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_form = QuestForm(request.POST)
if quest_form.is_valid():
quest = quest_form.save(commit=False)
quest.owner = request.user
quest.save()
page0 = Page(
quest_form.save_m2m()
print(quest.tags.names())
page = 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()
page.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}
context = locals()
return render(request, 'quest/new_quest.html', context)