Compare commits
No commits in common. "e92e5686c3326ed49751cb9fb45556125738bc0c" and "75f53847236cb74308acbadd7f20e2a1c1a62574" have entirely different histories.
e92e5686c3
...
75f5384723
|
@ -9,7 +9,7 @@
|
||||||
<input type="text" name="title" placeholder="Search">
|
<input type="text" name="title" placeholder="Search">
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
<a href="{{ url('quest:index') }}">Quests</a><br>
|
<a href="{{ url('quest:index') }}">Advanced</a><br>
|
||||||
<br>
|
<br>
|
||||||
<a href="./quest/1">Unga Bunga Quest</a><br />
|
<a href="./quest/1">Unga Bunga Quest</a><br />
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
|
|
|
@ -431,11 +431,10 @@ def new_page(socket, data):
|
||||||
else:
|
else:
|
||||||
page_num = 'a'
|
page_num = 'a'
|
||||||
else:
|
else:
|
||||||
last_page = Page.objects.filter(
|
page_num = Page.objects.filter(
|
||||||
quest=quest,
|
quest=quest,
|
||||||
appendix=False
|
appendix=False
|
||||||
).order_by('page_num').last()
|
).order_by('page_num').last().page_num + 1
|
||||||
page_num = int(last_page.page_num) + 1
|
|
||||||
p = Page(
|
p = Page(
|
||||||
quest=quest,
|
quest=quest,
|
||||||
page_num=page_num,
|
page_num=page_num,
|
||||||
|
|
|
@ -56,7 +56,7 @@ class QuestForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Quest
|
model = Quest
|
||||||
fields = ('title', 'description', 'tags')
|
fields = ('title',)
|
||||||
|
|
||||||
|
|
||||||
class PostForm(forms.ModelForm):
|
class PostForm(forms.ModelForm):
|
||||||
|
|
|
@ -5,43 +5,20 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="get" action="{{ url('quest:index') }}">
|
<form method="get" action="{{ url('quest:index') }}">
|
||||||
Search terms: <input type="text" name="search_terms">
|
Author: <input type="text" name="author"><br>
|
||||||
<select name="search_type">
|
Title: <input type="text" name="title"><br>
|
||||||
<option value="title"{% if search_type == 'title' %} selected{% endif %}>Title</option>
|
Tags: <input type="text" name="tags"><br>
|
||||||
<option value="author"{% if search_type == 'author' %} selected{% endif %}>Author</option>
|
<input type="submit">
|
||||||
</select>
|
|
||||||
<br>Tags: <input type="text" name="tags">
|
|
||||||
<br>Order by:
|
|
||||||
<select name="order_by">
|
|
||||||
<option value="creation_date"{% if order_by == 'creation_date' %} selected{% endif %}>Creation date</option>
|
|
||||||
<option value="last_post"{% if order_by == 'last_post' %} selected{% endif %}>Last post</option>
|
|
||||||
<option value="next_live"{% if order_by == 'next_live' %} selected{% endif %}>Next live</option>
|
|
||||||
</select>
|
|
||||||
<select name="order_way">
|
|
||||||
<option value="desc"{% if order_way == 'desc' %} selected{% endif %}>Descending</option>
|
|
||||||
<option value="asc"{% if order_way == 'asc' %} selected{% endif %}>Ascending</option>
|
|
||||||
</select>
|
|
||||||
<br><input type="submit">
|
|
||||||
</form>
|
</form>
|
||||||
<h2>Quests</h2>
|
|
||||||
{% if results %}
|
{% if results %}
|
||||||
<table id="results">
|
<table id="results">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Author</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for quest in results %}
|
{% for quest in results %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="title"><a href="{{ url('quest:quest', args=[quest.id, '0']) }}">{{ quest.title }}</a></td>
|
<td class="title"><a href="{{ url('quest:quest', args=[quest.id, '0']) }}">{{ quest.title }}</a></td>
|
||||||
<td class="description">{{ quest.description or "" }}</td>
|
<td class="summary"></td>
|
||||||
<td class="author"><a href="{{ url('user:profile', args=[quest.owner.id]) }}">{{ quest.owner.username }}</a></td>
|
<td class="author"><a href="{{ url('user:profile', args=[quest.owner.id]) }}">{{ quest.owner.username }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
<h1>New Quest</h1>
|
<h1>New Quest</h1>
|
||||||
<form method="post" action="{{ url('quest:new_quest') }}">
|
<form method="post" action="{{ url('quest:new_quest') }}">
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="text" placeholder="Quest Title" name="title" maxlength="100" required><br>
|
{#
|
||||||
<textarea name="description" maxlength="256"></textarea><br>
|
<input type="text" placeholder="Quest Title" name="quest_title" maxlength="300" required/><br/>
|
||||||
<input type="text" placeholder="Tags" name="tags" id=><br>
|
<textarea id="create_textarea" name="quest_body"></textarea>
|
||||||
<input type="submit" name="submit" value="Submit">
|
#}
|
||||||
|
{{ quest_form.as_p() }}
|
||||||
|
{{ post_form.as_p() }}
|
||||||
|
<input type="submit" name="submit" value="Submit"/>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -162,7 +162,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="QMPage" class="QMPostTabContent" style="display:none;">
|
<div id="QMPage" class="QMPostTabContent" style="display:none;">
|
||||||
<form id="QMPageForm" action="javascript:void(0);" onsubmit="form_post('QMPageForm', 'new_page');">
|
<form id="QMPageForm" action="javascript:void(0);" onsubmit="form_post('QMPageForm', 'new_page');">
|
||||||
New Page: <input type="text" name="page_title" maxlength="200" value="Page {{ pages.last().page_num|int + 1 }}"><br>
|
New Page: <input type="text" name="page_title" maxlength="200" value="Page {{ pages.count() + 1 }}"><br>
|
||||||
Appendix: <input type="checkbox" name="appendix"><br>
|
Appendix: <input type="checkbox" name="appendix"><br>
|
||||||
<input type="submit" name="submit" value="Submit">
|
<input type="submit" name="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
{% block title %}{{ quest.title }}{% endblock %}
|
{% block title %}{{ quest.title }}{% endblock %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<link rel="stylesheet" type="text/css" href="{{ static('quest.css') }}">
|
<link rel="stylesheet" type="text/css" href="{{ static('quest.css') }}">
|
||||||
{% if request.user == quest.owner %}
|
|
||||||
<link rel="stylesheet" type="text/css" href="{{ static('questQM.css') }}">
|
|
||||||
{% endif %}
|
|
||||||
<script>
|
<script>
|
||||||
const quest_id = {{ quest.id }};
|
const quest_id = {{ quest.id }};
|
||||||
const page_num = '{{ page_num }}';
|
const page_num = '{{ page_num }}';
|
||||||
|
@ -12,12 +9,8 @@
|
||||||
const anon_name = '{{ quest.anon_name }}';
|
const anon_name = '{{ quest.anon_name }}';
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="{{ static('quest.js') }}"></script>
|
<script type="text/javascript" src="{{ static('quest.js') }}"></script>
|
||||||
{% if request.user == quest.owner %}
|
|
||||||
<script type="text/javascript" src="{{ static('questQM.js') }}"></script>
|
|
||||||
{% endif %}
|
|
||||||
<script>events = [socket.events['message'], socket.events['new_page']]; socket.events = {'message': events[0], 'new_page': events[1]}; delete events;</script>
|
|
||||||
<!-- We only want the message and new_page events on this page, others will error. Hacky solution, but it will do for now. -->
|
|
||||||
<script>window.onload = load;</script>
|
<script>window.onload = load;</script>
|
||||||
|
<!-- We only want the message event on this page, others will error. Hacky solution, but it will do for now. -->
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if request.user == quest.owner %}
|
{% if request.user == quest.owner %}
|
||||||
|
@ -79,22 +72,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if quest.owner == request.user %}
|
|
||||||
<div id="QMPostPane">
|
|
||||||
<div>
|
|
||||||
<ul id="QMPostTabs">
|
|
||||||
<li><a class="QMPostTab" href="javascript:void(0);" onclick="openPostTab(event, 'QMPage')">Page</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div id="QMPage" class="QMPostTabContent" style="display:initial;">
|
|
||||||
<form id="QMPageForm" action="javascript:void(0);" onsubmit="form_post('QMPageForm', 'new_page');">
|
|
||||||
New Page: <input type="text" name="page_title" maxlength="200" value="Page {{ pages.last().page_num|int + 1 }}"><br>
|
|
||||||
Appendix: <input type="checkbox" name="appendix"><br>
|
|
||||||
<input type="submit" name="submit" value="Submit">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if vars['next_page'] %}
|
{% if vars['next_page'] %}
|
||||||
<div id="nextPageContainer">
|
<div id="nextPageContainer">
|
||||||
<input type="button" id="nextPage" value="Next Page: {{ vars['next_page'].title }}" onclick="window.location.href='{{ url('quest:quest', args=[quest_id, vars['next_page'].page_num]) }}'">
|
<input type="button" id="nextPage" value="Next Page: {{ vars['next_page'].title }}" onclick="window.location.href='{{ url('quest:quest', args=[quest_id, vars['next_page'].page_num]) }}'">
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# 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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# 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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 2.1.1 on 2018-10-05 13:21
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('quest', '0008_auto_20181005_0825'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='quest',
|
|
||||||
name='latest_post_date',
|
|
||||||
field=models.DateTimeField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -16,20 +16,10 @@ class Quest(models.Model):
|
||||||
settings.AUTH_USER_MODEL,
|
settings.AUTH_USER_MODEL,
|
||||||
on_delete=models.CASCADE)
|
on_delete=models.CASCADE)
|
||||||
anon_name = models.CharField(max_length=20, default="Anonymous")
|
anon_name = models.CharField(max_length=20, default="Anonymous")
|
||||||
live = models.BooleanField(default=False)
|
live = models.BooleanField()
|
||||||
live_time = models.DateTimeField(blank=True, null=True)
|
live_time = models.DateTimeField(blank=True, null=True)
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
anonymize = models.BooleanField(default=True)
|
anonymize = models.BooleanField(default=True)
|
||||||
description = models.CharField(max_length=256, blank=True, null=True)
|
|
||||||
latest_post_date = models.DateTimeField(null=True, blank=True)
|
|
||||||
|
|
||||||
def update_post_date(self):
|
|
||||||
try:
|
|
||||||
latest_post = self.post_set.order_by('-timestamp')[0]
|
|
||||||
self.latest_post_date = latest_post.timestamp
|
|
||||||
self.save()
|
|
||||||
except:
|
|
||||||
pass # no posts yet
|
|
||||||
|
|
||||||
|
|
||||||
class Message(models.Model):
|
class Message(models.Model):
|
||||||
|
@ -74,14 +64,6 @@ class Post(models.Model):
|
||||||
post_text = models.TextField()
|
post_text = models.TextField()
|
||||||
timestamp = models.DateTimeField(auto_now=True)
|
timestamp = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def save(self, **kwargs):
|
|
||||||
super(Post, self).save(**kwargs)
|
|
||||||
self.quest.update_post_date()
|
|
||||||
|
|
||||||
def delete(self):
|
|
||||||
super(Post, self).delete()
|
|
||||||
self.quest.update_post_date()
|
|
||||||
|
|
||||||
|
|
||||||
class DiceCall(models.Model):
|
class DiceCall(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -157,7 +157,7 @@ socket.events['set_option_box'] = function(data) {
|
||||||
}
|
}
|
||||||
socket.events['new_page'] = function(data) {
|
socket.events['new_page'] = function(data) {
|
||||||
if (page_num != data.page_num-1) { return; }
|
if (page_num != data.page_num-1) { return; }
|
||||||
let html_str = '<div id="nextPageContainer"><input type="button" id="nextPage" value="Next Page: ' + data.title + '" onclick="window.location.href=\'' + SCRIPT_NAME + data.url + '\'"></div>';
|
let html_str = '<div id="nextPageContainer"><input type="button" id="nextPage" value="Next Page: ' + data.title + '" onclick="window.location.href=\'' + data.url + '\'"></div>';
|
||||||
document.getElementById('questPane').innerHTML = document.getElementById('questPane').innerHTML + html_str;
|
document.getElementById('questPane').innerHTML = document.getElementById('questPane').innerHTML + html_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,24 +10,14 @@
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
thead {
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:nth-child(even) {
|
tr:nth-child(even) {
|
||||||
background-color: #DDDDDD;
|
background-color: #DDDDDD;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
padding-left: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.description {
|
|
||||||
padding-left: 1em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.author {
|
.author {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
text-align: center;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import bleach
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.db.models import F
|
|
||||||
|
|
||||||
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
|
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
|
||||||
from .forms import EditQuestForm, QuestForm, PostForm
|
from .forms import EditQuestForm, QuestForm, PostForm
|
||||||
|
@ -16,33 +15,19 @@ from user.models import User
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
"""The quest page index."""
|
"""The quest page index."""
|
||||||
search_terms = request.GET.get('search_terms')
|
author = request.GET.get('author')
|
||||||
search_type = request.GET.get('search_type')
|
title = request.GET.get('title')
|
||||||
tags = request.GET.get('tags')
|
tags = request.GET.get('tags')
|
||||||
order_by = request.GET.get('order_by')
|
|
||||||
order_way = request.GET.get('order_way', 'desc')
|
|
||||||
|
|
||||||
order_keys = {
|
|
||||||
'ceation_date': 'id',
|
|
||||||
'last_post': 'latest_post_date',
|
|
||||||
'next_live': 'live_time',
|
|
||||||
}
|
|
||||||
order_by = order_keys.get(order_by, 'id')
|
|
||||||
|
|
||||||
results = Quest.objects.all()
|
results = Quest.objects.all()
|
||||||
if search_terms:
|
if author:
|
||||||
if search_type == 'title':
|
|
||||||
results = results.filter(title__unaccent__icontains=search_terms)
|
|
||||||
elif search_type == 'author':
|
|
||||||
results = results.filter(
|
results = results.filter(
|
||||||
owner__username__unaccent__icontains=search_terms)
|
owner__username__unaccent__icontains=author)
|
||||||
|
if title:
|
||||||
|
results = results.filter(title__unaccent__icontains=title)
|
||||||
if tags:
|
if tags:
|
||||||
results = results.filter(tags__name__in=tags.split()).distinct()
|
results = results.filter(tags__name__in=tags.split())
|
||||||
|
results = results.distinct().order_by('-id')
|
||||||
if order_way == 'asc':
|
|
||||||
results = results.order_by(F(order_by).asc(nulls_last=True))
|
|
||||||
elif order_way == 'desc':
|
|
||||||
results = results.order_by(F(order_by).desc(nulls_last=True))
|
|
||||||
|
|
||||||
context = locals()
|
context = locals()
|
||||||
return render(request, 'quest/index.html', context)
|
return render(request, 'quest/index.html', context)
|
||||||
|
@ -121,24 +106,35 @@ def new_quest(request):
|
||||||
return redirect('login:index')
|
return redirect('login:index')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# TODO: clean the post body
|
# TODO: clean the post body
|
||||||
quest_form = QuestForm(request.POST)
|
quest = Quest(owner=request.user)
|
||||||
if quest_form.is_valid():
|
quest_form = QuestForm(request.POST, instance=quest)
|
||||||
quest = quest_form.save(commit=False)
|
post = Post(post_type='text')
|
||||||
quest.owner = request.user
|
post_form = PostForm(request.POST, instance=post)
|
||||||
|
if all((quest_form.is_valid(), post_form.is_valid())):
|
||||||
|
quest.live = False
|
||||||
quest.save()
|
quest.save()
|
||||||
quest_form.save_m2m()
|
page0 = Page(
|
||||||
print(quest.tags.names())
|
|
||||||
page = Page(
|
|
||||||
quest=quest,
|
quest=quest,
|
||||||
page_num=0,
|
page_num=0,
|
||||||
title="Homepage",
|
title="Homepage",
|
||||||
appendix=False,
|
appendix=False,
|
||||||
)
|
)
|
||||||
page.save()
|
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)
|
return redirect('quest:quest', quest_id=quest.id)
|
||||||
else:
|
else:
|
||||||
quest_form = QuestForm()
|
quest_form = QuestForm()
|
||||||
context = locals()
|
post_form = PostForm()
|
||||||
|
context = {'quest_form': quest_form, 'post_form': post_form}
|
||||||
return render(request, 'quest/new_quest.html', context)
|
return render(request, 'quest/new_quest.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user