basic search added
This commit is contained in:
parent
7a2f74c86e
commit
4f70d10ea8
|
@ -5,7 +5,7 @@ By popular demand, I'm building a better anonkun. It doesn't do much right now t
|
|||
Python 3.6+
|
||||
PostgreSQL 10.4+
|
||||
Redis 4.0.10+
|
||||
Python packages: `django psycopg2 channels channels_redis jinja2 argon2-cffi bleach requests python-magic`
|
||||
Python packages: `django psycopg2 channels channels_redis jinja2 argon2-cffi bleach requests python-magic django-taggit`
|
||||
|
||||
## Install
|
||||
```
|
||||
|
@ -17,6 +17,9 @@ postgres=# ALTER ROLE "titivillus" SET default_transaction_isolation TO 'read co
|
|||
postgres=# ALTER ROLE "titivillus" SET timezone TO 'UTC';
|
||||
postgres=# GRANT ALL PRIVILEGES ON DATABASE "titivillus" TO "titivillus";
|
||||
postgres=# \q
|
||||
$ psql titivillus
|
||||
titivillus=# CREATE EXTENSION unaccent;
|
||||
titivillus=# \q
|
||||
```
|
||||
1. Get on the floor
|
||||
2. Walk the dinosaur
|
||||
|
|
|
@ -20,14 +20,20 @@ def index(request):
|
|||
post_form = PostForm(request.POST, instance=post)
|
||||
if all((quest_form.is_valid(), post_form.is_valid())):
|
||||
quest.save()
|
||||
page = Page(
|
||||
page0 = Page(
|
||||
quest=quest,
|
||||
page_num=0,
|
||||
title="Homepage"
|
||||
)
|
||||
page0.save()
|
||||
page1 = Page(
|
||||
quest=quest,
|
||||
page_num=1,
|
||||
title="Page 1"
|
||||
)
|
||||
page.save()
|
||||
page1.save()
|
||||
post.quest = quest
|
||||
post.page = page
|
||||
post.page = page1
|
||||
post.save()
|
||||
return redirect('quest:quest', quest_id=quest.id)
|
||||
else:
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
{% block title %}Index{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Quests 'n Shiet</h1>
|
||||
<form method="get" action="{{ url('search:index') }}">
|
||||
<input type="text" name="title" placeholder="Search">
|
||||
<input type="submit">
|
||||
</form>
|
||||
<a href="{{ url('search:index') }}">Advanced</a><br>
|
||||
<br>
|
||||
<a href="./quest/1">Unga Bunga Quest</a><br />
|
||||
{% if request.user.is_authenticated %}
|
||||
<a href="{{ url('create_quest:index') }}">Create New Quest</a><br />
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<span><a href="{{ url('homepage:index') }}">Home</a></span>
|
||||
{% block header %}{% endblock %}
|
||||
</div>
|
||||
<div id="headerHidden" class="header" style="{% if request.session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}">
|
||||
<div id="headerHidden" class="header" style="{% if request.session.get("hide_header") == True %}display:flex;{% else %}display:none;{% endif %}">
|
||||
<span><a onclick="toggle_header();" href="javascript:void(0);">↓</a></span>
|
||||
</div>
|
||||
<ul id="alerts">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}{{ quest.title }}: Home{% endblock %}
|
||||
{% block title %}{{ quest.title }}{% endblock %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" type="text/css" href="{{ static('quest.css') }}">
|
||||
{% endblock %}
|
||||
|
@ -46,6 +46,7 @@
|
|||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};">
|
||||
<center><h1>{{ quest.title }}</h1></center>
|
||||
<h3>Pages</h3>
|
||||
<ul>
|
||||
{% for page in pages %}
|
||||
|
|
20
quest/migrations/0004_quest_tags.py
Normal file
20
quest/migrations/0004_quest_tags.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.1.1 on 2018-10-02 14:33
|
||||
|
||||
from django.db import migrations
|
||||
import taggit.managers
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('taggit', '0002_auto_20150616_2121'),
|
||||
('quest', '0003_auto_20180928_0747'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='quest',
|
||||
name='tags',
|
||||
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
|
||||
),
|
||||
]
|
|
@ -5,6 +5,7 @@ The main quest models.
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
class Quest(models.Model):
|
||||
"""
|
||||
|
@ -17,6 +18,7 @@ class Quest(models.Model):
|
|||
anon_name = models.CharField(max_length=20, default="Anonymous")
|
||||
live = models.BooleanField()
|
||||
live_time = models.DateTimeField(blank=True, null=True)
|
||||
tags = TaggableManager()
|
||||
|
||||
|
||||
class Message(models.Model):
|
||||
|
|
|
@ -18,7 +18,7 @@ def index(request):
|
|||
return HttpResponse("Hello, world. You're at the quest index.")
|
||||
|
||||
|
||||
def quest(request, quest_id, page_num='1'):
|
||||
def quest(request, quest_id, page_num='0'):
|
||||
"""
|
||||
Arbituary quest page view.
|
||||
"""
|
||||
|
|
0
search/__init__.py
Normal file
0
search/__init__.py
Normal file
3
search/admin.py
Normal file
3
search/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
search/apps.py
Normal file
5
search/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SearchConfig(AppConfig):
|
||||
name = 'search'
|
19
search/jinja2/search/index.html
Normal file
19
search/jinja2/search/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Search{% endblock %}
|
||||
{% block content %}
|
||||
<form method="get" action="{{ url('search: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">
|
||||
</form>
|
||||
{% if results %}
|
||||
<table>
|
||||
{% for quest in results %}
|
||||
<tr>
|
||||
<td><a href="{{ url('quest:quest', args=[quest.id, '0']) }}">{{ quest.title }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
0
search/migrations/__init__.py
Normal file
0
search/migrations/__init__.py
Normal file
3
search/models.py
Normal file
3
search/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
search/tests.py
Normal file
3
search/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
12
search/urls.py
Normal file
12
search/urls.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Search URL configuration.
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'search'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
29
search/views.py
Normal file
29
search/views.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
/search app views.
|
||||
"""
|
||||
from django.shortcuts import render
|
||||
|
||||
from quest.models import Quest
|
||||
from user.models import User
|
||||
|
||||
def index(request):
|
||||
"""The search page index."""
|
||||
if request.GET:
|
||||
author = request.GET.get('author')
|
||||
title = request.GET.get('title')
|
||||
tags = request.GET.get('tags')
|
||||
if not any((author, title, tags)):
|
||||
return
|
||||
|
||||
results = Quest.objects.all()
|
||||
if author:
|
||||
results = results.filter(
|
||||
owner__username__unaccent__icontains=author)
|
||||
if title:
|
||||
results = results.filter(title__unaccent__icontains=title)
|
||||
if tags:
|
||||
results = results.filter(tags__name__in=tags.split())
|
||||
results = results.distinct()
|
||||
context = locals()
|
||||
return render(request, 'search/index.html', context)
|
|
@ -8,7 +8,7 @@ function toggle_cookie(cookie, state) {
|
|||
function toggle_header() {
|
||||
if (document.getElementById('header').style.display == 'flex') {
|
||||
document.getElementById('header').style.display = 'none';
|
||||
document.getElementById('headerHidden').style.display = 'initial';
|
||||
document.getElementById('headerHidden').style.display = 'flex';
|
||||
toggle_cookie('hide_header', 'on');
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -31,13 +31,16 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.postgres',
|
||||
'channels',
|
||||
'taggit',
|
||||
'user.apps.UserConfig',
|
||||
'homepage.apps.HomepageConfig',
|
||||
'create_quest.apps.CreateQuestConfig',
|
||||
'quest.apps.QuestConfig',
|
||||
'login.apps.LoginConfig',
|
||||
'signup.apps.SignupConfig',
|
||||
'search.apps.SearchConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -159,3 +162,6 @@ CHANNEL_LAYERS = {
|
|||
|
||||
# Image server url
|
||||
IMG_SVR_URL = "https://img.steelbea.me/"
|
||||
|
||||
# Taggit
|
||||
TAGGIT_CASE_INSENSITIVE = True
|
||||
|
|
|
@ -15,4 +15,5 @@ urlpatterns = [
|
|||
path('login/', include('login.urls')),
|
||||
path('logout/', include('logout.urls')),
|
||||
path('user/', include('user.urls')),
|
||||
path('search/', include('search.urls')),
|
||||
]
|
||||
|
|
4
todo
4
todo
|
@ -1,15 +1,13 @@
|
|||
New Features:
|
||||
Notifications
|
||||
Banner images
|
||||
Search page
|
||||
Front page to show new quests
|
||||
Webm posting
|
||||
(you) counter
|
||||
Account managament/logout
|
||||
Account managament
|
||||
Display profile link in header bar
|
||||
Tagging system
|
||||
Quote backlinks
|
||||
Quest homepage
|
||||
|
||||
Improvements:
|
||||
More options for text posts (lists and so on)
|
||||
|
|
Loading…
Reference in New Issue
Block a user