refactored search engine, added new options
This commit is contained in:
parent
518ea259cd
commit
e92e5686c3
|
@ -9,7 +9,7 @@
|
|||
<input type="text" name="title" placeholder="Search">
|
||||
<input type="submit">
|
||||
</form>
|
||||
<a href="{{ url('quest:index') }}">Advanced</a><br>
|
||||
<a href="{{ url('quest:index') }}">Quests</a><br>
|
||||
<br>
|
||||
<a href="./quest/1">Unga Bunga Quest</a><br />
|
||||
{% if request.user.is_authenticated %}
|
||||
|
|
|
@ -431,10 +431,11 @@ def new_page(socket, data):
|
|||
else:
|
||||
page_num = 'a'
|
||||
else:
|
||||
page_num = Page.objects.filter(
|
||||
last_page = Page.objects.filter(
|
||||
quest=quest,
|
||||
appendix=False
|
||||
).order_by('page_num').last().page_num + 1
|
||||
).order_by('page_num').last()
|
||||
page_num = int(last_page.page_num) + 1
|
||||
p = Page(
|
||||
quest=quest,
|
||||
page_num=page_num,
|
||||
|
|
|
@ -5,20 +5,43 @@
|
|||
{% endblock %}
|
||||
{% block content %}
|
||||
<form method="get" action="{{ url('quest:index') }}">
|
||||
Author: <input type="text" name="author"><br>
|
||||
Title: <input type="text" name="title"><br>
|
||||
Tags: <input type="text" name="tags"><br>
|
||||
<input type="submit">
|
||||
Search terms: <input type="text" name="search_terms">
|
||||
<select name="search_type">
|
||||
<option value="title"{% if search_type == 'title' %} selected{% endif %}>Title</option>
|
||||
<option value="author"{% if search_type == 'author' %} selected{% endif %}>Author</option>
|
||||
</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>
|
||||
<h2>Quests</h2>
|
||||
{% if results %}
|
||||
<table id="results">
|
||||
{% for quest in results %}
|
||||
<tr>
|
||||
<td class="title"><a href="{{ url('quest:quest', args=[quest.id, '0']) }}">{{ quest.title }}</a></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 %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Description</th>
|
||||
<th>Author</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for quest in results %}
|
||||
<tr>
|
||||
<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="author"><a href="{{ url('user:profile', args=[quest.owner.id]) }}">{{ quest.owner.username }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -162,7 +162,7 @@
|
|||
</div>
|
||||
<div id="QMPage" class="QMPostTabContent" style="display:none;">
|
||||
<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.count() + 1 }}"><br>
|
||||
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>
|
||||
|
|
18
quest/migrations/0009_quest_latest_post_date.py
Normal file
18
quest/migrations/0009_quest_latest_post_date.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# 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),
|
||||
),
|
||||
]
|
|
@ -21,6 +21,15 @@ class Quest(models.Model):
|
|||
tags = TaggableManager()
|
||||
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):
|
||||
|
@ -65,6 +74,14 @@ class Post(models.Model):
|
|||
post_text = models.TextField()
|
||||
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):
|
||||
"""
|
||||
|
|
|
@ -10,14 +10,24 @@
|
|||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
thead {
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: #DDDDDD;
|
||||
}
|
||||
|
||||
.title {
|
||||
width: 20%;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.description {
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.author {
|
||||
width: 20%;
|
||||
text-align: center;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import bleach
|
|||
from django.views.decorators.http import require_POST
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import render, redirect
|
||||
from django.db.models import F
|
||||
|
||||
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
|
||||
from .forms import EditQuestForm, QuestForm, PostForm
|
||||
|
@ -15,19 +16,33 @@ from user.models import User
|
|||
|
||||
def index(request):
|
||||
"""The quest page index."""
|
||||
author = request.GET.get('author')
|
||||
title = request.GET.get('title')
|
||||
search_terms = request.GET.get('search_terms')
|
||||
search_type = request.GET.get('search_type')
|
||||
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()
|
||||
if author:
|
||||
results = results.filter(
|
||||
owner__username__unaccent__icontains=author)
|
||||
if title:
|
||||
results = results.filter(title__unaccent__icontains=title)
|
||||
if search_terms:
|
||||
if search_type == 'title':
|
||||
results = results.filter(title__unaccent__icontains=search_terms)
|
||||
elif search_type == 'author':
|
||||
results = results.filter(
|
||||
owner__username__unaccent__icontains=search_terms)
|
||||
if tags:
|
||||
results = results.filter(tags__name__in=tags.split())
|
||||
results = results.distinct().order_by('-id')
|
||||
results = results.filter(tags__name__in=tags.split()).distinct()
|
||||
|
||||
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()
|
||||
return render(request, 'quest/index.html', context)
|
||||
|
|
Loading…
Reference in New Issue
Block a user