basic search added

This commit is contained in:
iou1name 2018-10-02 11:35:39 -04:00
parent 7a2f74c86e
commit 4f70d10ea8
21 changed files with 128 additions and 11 deletions

View File

@ -5,7 +5,7 @@ By popular demand, I'm building a better anonkun. It doesn't do much right now t
Python 3.6+ Python 3.6+
PostgreSQL 10.4+ PostgreSQL 10.4+
Redis 4.0.10+ 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 ## 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=# ALTER ROLE "titivillus" SET timezone TO 'UTC';
postgres=# GRANT ALL PRIVILEGES ON DATABASE "titivillus" TO "titivillus"; postgres=# GRANT ALL PRIVILEGES ON DATABASE "titivillus" TO "titivillus";
postgres=# \q postgres=# \q
$ psql titivillus
titivillus=# CREATE EXTENSION unaccent;
titivillus=# \q
``` ```
1. Get on the floor 1. Get on the floor
2. Walk the dinosaur 2. Walk the dinosaur

View File

@ -20,14 +20,20 @@ def index(request):
post_form = PostForm(request.POST, instance=post) post_form = PostForm(request.POST, instance=post)
if all((quest_form.is_valid(), post_form.is_valid())): if all((quest_form.is_valid(), post_form.is_valid())):
quest.save() quest.save()
page = Page( page0 = Page(
quest=quest,
page_num=0,
title="Homepage"
)
page0.save()
page1 = Page(
quest=quest, quest=quest,
page_num=1, page_num=1,
title="Page 1" title="Page 1"
) )
page.save() page1.save()
post.quest = quest post.quest = quest
post.page = page post.page = page1
post.save() post.save()
return redirect('quest:quest', quest_id=quest.id) return redirect('quest:quest', quest_id=quest.id)
else: else:

View File

@ -2,6 +2,12 @@
{% block title %}Index{% endblock %} {% block title %}Index{% endblock %}
{% block content %} {% block content %}
<h1>Quests 'n Shiet</h1> <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 /> <a href="./quest/1">Unga Bunga Quest</a><br />
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<a href="{{ url('create_quest:index') }}">Create New Quest</a><br /> <a href="{{ url('create_quest:index') }}">Create New Quest</a><br />

View File

@ -19,7 +19,7 @@
<span><a href="{{ url('homepage:index') }}">Home</a></span> <span><a href="{{ url('homepage:index') }}">Home</a></span>
{% block header %}{% endblock %} {% block header %}{% endblock %}
</div> </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> <span><a onclick="toggle_header();" href="javascript:void(0);"></a></span>
</div> </div>
<ul id="alerts"> <ul id="alerts">

View File

@ -1,5 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}{{ quest.title }}: Home{% 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') }}">
{% endblock %} {% endblock %}
@ -46,6 +46,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};"> <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> <h3>Pages</h3>
<ul> <ul>
{% for page in pages %} {% for page in pages %}

View 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'),
),
]

View File

@ -5,6 +5,7 @@ The main quest models.
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from taggit.managers import TaggableManager
class Quest(models.Model): class Quest(models.Model):
""" """
@ -17,6 +18,7 @@ class Quest(models.Model):
anon_name = models.CharField(max_length=20, default="Anonymous") anon_name = models.CharField(max_length=20, default="Anonymous")
live = models.BooleanField() live = models.BooleanField()
live_time = models.DateTimeField(blank=True, null=True) live_time = models.DateTimeField(blank=True, null=True)
tags = TaggableManager()
class Message(models.Model): class Message(models.Model):

View File

@ -18,7 +18,7 @@ def index(request):
return HttpResponse("Hello, world. You're at the quest index.") 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. Arbituary quest page view.
""" """

0
search/__init__.py Normal file
View File

3
search/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
search/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class SearchConfig(AppConfig):
name = 'search'

View 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 %}

View File

3
search/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
search/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

12
search/urls.py Normal file
View 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
View 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)

View File

@ -8,7 +8,7 @@ function toggle_cookie(cookie, state) {
function toggle_header() { function toggle_header() {
if (document.getElementById('header').style.display == 'flex') { if (document.getElementById('header').style.display == 'flex') {
document.getElementById('header').style.display = 'none'; document.getElementById('header').style.display = 'none';
document.getElementById('headerHidden').style.display = 'initial'; document.getElementById('headerHidden').style.display = 'flex';
toggle_cookie('hide_header', 'on'); toggle_cookie('hide_header', 'on');
} }
else { else {

View File

@ -31,13 +31,16 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.postgres',
'channels', 'channels',
'taggit',
'user.apps.UserConfig', 'user.apps.UserConfig',
'homepage.apps.HomepageConfig', 'homepage.apps.HomepageConfig',
'create_quest.apps.CreateQuestConfig', 'create_quest.apps.CreateQuestConfig',
'quest.apps.QuestConfig', 'quest.apps.QuestConfig',
'login.apps.LoginConfig', 'login.apps.LoginConfig',
'signup.apps.SignupConfig', 'signup.apps.SignupConfig',
'search.apps.SearchConfig',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -159,3 +162,6 @@ CHANNEL_LAYERS = {
# Image server url # Image server url
IMG_SVR_URL = "https://img.steelbea.me/" IMG_SVR_URL = "https://img.steelbea.me/"
# Taggit
TAGGIT_CASE_INSENSITIVE = True

View File

@ -15,4 +15,5 @@ urlpatterns = [
path('login/', include('login.urls')), path('login/', include('login.urls')),
path('logout/', include('logout.urls')), path('logout/', include('logout.urls')),
path('user/', include('user.urls')), path('user/', include('user.urls')),
path('search/', include('search.urls')),
] ]

4
todo
View File

@ -1,15 +1,13 @@
New Features: New Features:
Notifications Notifications
Banner images Banner images
Search page
Front page to show new quests Front page to show new quests
Webm posting Webm posting
(you) counter (you) counter
Account managament/logout Account managament
Display profile link in header bar Display profile link in header bar
Tagging system Tagging system
Quote backlinks Quote backlinks
Quest homepage
Improvements: Improvements:
More options for text posts (lists and so on) More options for text posts (lists and so on)