Compare commits
2 Commits
7f7d21384e
...
9306248902
Author | SHA1 | Date |
---|---|---|
Matthias Portzel | 9306248902 | |
Matthias Portzel | 40fd0aaa5c |
|
@ -6,7 +6,7 @@ import sys
|
|||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'whispermaphone.settings')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "whispermaphone.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
|
|
@ -52,6 +52,9 @@ button, input[type="button"], input[type="submit"], .button {
|
|||
outline: none;
|
||||
font-size: 13px;
|
||||
}
|
||||
form input[type="submit"] {
|
||||
font-size: 15px;
|
||||
}
|
||||
button:hover, button:focus,
|
||||
input[type="button"]:hover, input[type="button"]:focus,
|
||||
input[type="submit"]:hover, input[type="submit"]:focus,
|
||||
|
@ -61,8 +64,8 @@ input[type="submit"]:hover, input[type="submit"]:focus,
|
|||
}
|
||||
|
||||
/* Textbox/textarea styles */
|
||||
textarea, input[type="text"], input[type="password"] {
|
||||
padding: 0 5px;
|
||||
textarea, input[type="text"], input[type="search"], input[type="password"] {
|
||||
padding: 0 2px;
|
||||
outline: none;
|
||||
resize: none;
|
||||
background: none;
|
||||
|
@ -73,13 +76,20 @@ textarea, input[type="text"], input[type="password"] {
|
|||
border-bottom: 1px solid var(--accent-color);
|
||||
border-radius: 0;
|
||||
overflow-x: hidden;
|
||||
display: block;
|
||||
display: inline-block;
|
||||
line-height: 1.5;
|
||||
}
|
||||
textarea::placeholder, input[type="text"]::placeholder {
|
||||
color: var(--text-color);
|
||||
opacity: 50%;
|
||||
}
|
||||
textarea {
|
||||
display: block;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-bottom: 4em;
|
||||
}
|
||||
|
||||
.text, .thought-end {
|
||||
max-width: 100%;
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
|
||||
{% block head %}
|
||||
<link rel="alternate" href="/feed" type="application/rss+xml" title="RSS">
|
||||
{% if not first_page %}
|
||||
<link rel="canonical" href="/?page={{ current_page_slug }}">
|
||||
{% else %}
|
||||
<link rel="canonical" href="/">
|
||||
{% endif %}
|
||||
|
||||
<link href="{% static 'thoughts/codehighlight.css' %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
|
@ -21,7 +26,7 @@
|
|||
<nav class="history-nav top" aria-label="History Navigation">
|
||||
<ul>
|
||||
{% for page in pages %}
|
||||
{% if page.slug == current_page %}
|
||||
{% if page.slug == current_page_slug %}
|
||||
<li><span class="current-page">{{ page.formatted_name }}</span></li>
|
||||
{% else %}
|
||||
<li><a href="?page={{ page.slug }}">{{ page.formatted_name }}</a></li>
|
||||
|
@ -91,7 +96,7 @@
|
|||
<nav class="history-nav bottom" aria-label="History Navigation">
|
||||
<ul>
|
||||
{% for page in pages %}
|
||||
{% if page.slug == current_page %}
|
||||
{% if page.slug == current_page_slug %}
|
||||
<li><span class="current-page">{{ page.formatted_name }}</span></li>
|
||||
{% else %}
|
||||
<li><a href="?page={{ page.slug }}">{{ page.formatted_name }}</a></li>
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
</div>
|
||||
|
||||
<input type="submit" id="post-button" value="{% if editing %}Update{% else %}Submit{% endif %}">
|
||||
{{ form.submit }}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -10,57 +10,39 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<form method="get" action="search">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input type="submit" value="Search">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<form method="get" action="search">
|
||||
{{ form.q }}
|
||||
|
||||
{% if query %}
|
||||
{% load tz %}
|
||||
<input type="submit" id="post-button" value="{% if editing %}Update{% else %}Submit{% endif %}">
|
||||
</form>
|
||||
|
||||
<h3>Results</h3>
|
||||
{% if query %}
|
||||
{% load tz %}
|
||||
|
||||
{% for thought in page.object_list %}
|
||||
<div class="thought" id="{{ thought.uuid }}">
|
||||
<div class="main">
|
||||
<span class="main-text text">{{ thought.object.text|urlize }}</span>
|
||||
{% for thought in page.object_list %}
|
||||
<div class="thought" id="{{ thought.uuid }}">
|
||||
<div class="main">
|
||||
<span class="main-text text">{{ thought.object.text|urlize }}</span>
|
||||
|
||||
<a href="/?show={{thought.object.uuid}}" class="button show-more">Show</a>
|
||||
</div>
|
||||
|
||||
<div class="thought-end">
|
||||
<span class="timestamp">
|
||||
{% timezone thought.object.get_timezone %}
|
||||
{{ thought.object.posted|time:"g:i a" }}
|
||||
{{ thought.object.posted|date:"M d, Y" }},
|
||||
|
||||
UTC{{ thought.object.get_offset_hours }}
|
||||
{{ thought.object.get_season }}
|
||||
{% endtimezone %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<a href="/?show={{thought.object.uuid}}" class="button show-more">Show</a>
|
||||
</div>
|
||||
{% empty %}
|
||||
<p>No results found.</p>
|
||||
{% endfor %}
|
||||
|
||||
<!-- {% if page.has_previous or page.has_next %}
|
||||
<div>
|
||||
{% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
|
||||
|
|
||||
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
|
||||
<div class="thought-end">
|
||||
<span class="timestamp">
|
||||
{% timezone thought.object.get_timezone %}
|
||||
{{ thought.object.posted|time:"g:i a" }}
|
||||
{{ thought.object.posted|date:"M d, Y" }},
|
||||
|
||||
UTC{{ thought.object.get_offset_hours }}
|
||||
{{ thought.object.get_season }}
|
||||
{% endtimezone %}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %} -->
|
||||
{% else %}
|
||||
{# Show some example queries to run, maybe query syntax, something else? #}
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
{% empty %}
|
||||
<p>No results found.</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,18 +5,18 @@ import base64
|
|||
|
||||
import magic
|
||||
|
||||
from django import forms
|
||||
from django.shortcuts import render, redirect
|
||||
from django.utils.crypto import constant_time_compare
|
||||
|
||||
from whispermaphone import settings
|
||||
from .models import Thought, ThoughtForm, ALLOWED_MEDIA_TYPES
|
||||
|
||||
from .pagination import get_all_pages, get_page_slug
|
||||
|
||||
from haystack.views import SearchView, search_view_factory
|
||||
from haystack.query import SearchQuerySet
|
||||
from haystack.forms import SearchForm
|
||||
|
||||
from whispermaphone import settings
|
||||
from .models import Thought, ThoughtForm, ALLOWED_MEDIA_TYPES
|
||||
from .pagination import get_all_pages, get_page_slug
|
||||
|
||||
def check_authenticated(request):
|
||||
authenticated = False
|
||||
try:
|
||||
|
@ -35,12 +35,10 @@ def index(request):
|
|||
except ValueError:
|
||||
highlighted_uuid = ""
|
||||
|
||||
# Figure out what page we're viewing
|
||||
## Figure out what page we're viewing
|
||||
pages = get_all_pages()
|
||||
|
||||
# First item in pages should be listed first
|
||||
requested_page = pages[0]
|
||||
requested_slug = request.GET.get("page", default=requested_page.slug)
|
||||
requested_slug = request.GET.get("page", default="")
|
||||
|
||||
# show=uuid takes priority over page
|
||||
if highlighted_uuid:
|
||||
|
@ -50,10 +48,16 @@ def index(request):
|
|||
except Thought.DoesNotExist:
|
||||
pass
|
||||
|
||||
if requested_page.slug != requested_slug:
|
||||
for p in pages:
|
||||
if p.slug == requested_slug:
|
||||
requested_page = p
|
||||
# When we get here, either:
|
||||
# no slug was passed, requested_slug is ""
|
||||
# a valid highlighted_uuid was passed, requested_slug is the slug of that page
|
||||
# requested_slug is an invalid slug
|
||||
# requested_slug is a valid slug
|
||||
# First item in pages should be listed first
|
||||
requested_page = pages[0]
|
||||
for p in pages:
|
||||
if p.slug == requested_slug:
|
||||
requested_page = p
|
||||
|
||||
thoughts = requested_page.get_all_entries()
|
||||
|
||||
|
@ -62,7 +66,7 @@ def index(request):
|
|||
"highlighted": highlighted_uuid,
|
||||
"authenticated": authenticated,
|
||||
"pages": pages,
|
||||
"current_page": requested_slug,
|
||||
"current_page_slug": requested_page.slug,
|
||||
"first_page": requested_page == pages[0] # if you're viewing the first page
|
||||
})
|
||||
|
||||
|
@ -171,9 +175,18 @@ def about(request):
|
|||
"authenticated": check_authenticated(request)
|
||||
})
|
||||
|
||||
class ThoughtsSearchForm(SearchForm):
|
||||
q = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={"type": "search", "placeholder": "Search query"}),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
search = search_view_factory(
|
||||
template="thoughts/search/search.html",
|
||||
view_class=SearchView,
|
||||
form_class=SearchForm,
|
||||
form_class=ThoughtsSearchForm,
|
||||
searchqueryset=SearchQuerySet().order_by("-posted")
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue