Improvements on the news app. It's not nearly done yet, don't bother playing with it for a while unless you're really curious and want to see ugly, un-refined code :)
This commit is contained in:
parent
9db148f98c
commit
648bee599e
8 changed files with 160 additions and 13 deletions
|
|
@ -2,5 +2,7 @@ from django.conf.urls.defaults import *
|
|||
|
||||
urlpatterns = patterns('apps.news.views',
|
||||
(r'^show/(?P<entry_id>\d+)/$', 'show_news'),
|
||||
# (r'^news/categories/list/$', 'recent_kills'),
|
||||
(r'^archive/$', 'news_archive'),
|
||||
(r'^search/$', 'search_form'),
|
||||
(r'^search/results/$', 'search_results'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,29 @@
|
|||
#
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
import django.views.generic.list_detail as list_detail
|
||||
import django.views.generic.list_detail as gv_list_detail
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth.models import User
|
||||
from django import newforms as forms
|
||||
|
||||
from apps.news.models import NewsTopic, NewsEntry
|
||||
|
||||
# The sidebar text to be included as a variable on each page. There's got to
|
||||
# be a better, cleaner way to include this on every page.
|
||||
sidebar = """
|
||||
<p class='doNotDisplay doNotPrint'>This page’s menu:</p>
|
||||
<ul id='side-bar'>
|
||||
<li><a href='/news/archive'>News Archive</a></li>
|
||||
<li><a href='/tbi'>Search News</a></li>
|
||||
</ul>
|
||||
"""
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
"""
|
||||
Class to represent a news search form under Django's newforms.
|
||||
"""
|
||||
search_terms = forms.CharField(max_length=100, min_length=3, required=True)
|
||||
|
||||
def show_news(request, entry_id):
|
||||
"""
|
||||
Show an individual news entry.
|
||||
|
|
@ -16,8 +34,70 @@ def show_news(request, entry_id):
|
|||
|
||||
pagevars = {
|
||||
"page_title": "News Entry",
|
||||
"news_entry": news_entry
|
||||
"news_entry": news_entry,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/show_entry.html', pagevars, context_instance)
|
||||
|
||||
def news_archive(request):
|
||||
"""
|
||||
Shows an archive of news entries.
|
||||
"""
|
||||
news_entries = NewsEntry.objects.all().order_by('-date_posted')
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
|
||||
pagevars = {
|
||||
"page_title": "News Archive",
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
|
||||
def search_form(request):
|
||||
"""
|
||||
Render the news search form.
|
||||
"""
|
||||
debug =""
|
||||
|
||||
if request.method == 'GET':
|
||||
debug = "GET"
|
||||
search_form = SearchForm(request.GET)
|
||||
if search_form.is_valid():
|
||||
return HttpResponseRedirect('/news/search/results/?search_terms='+ search_form.cleaned_data['search_terms'])
|
||||
else:
|
||||
debug = "NOTHING"
|
||||
search_form = SearchForm()
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Search News",
|
||||
"search_form": search_form,
|
||||
"debug": debug,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/search_form.html', pagevars, context_instance)
|
||||
|
||||
def search_results(request):
|
||||
"""
|
||||
Shows an archive of news entries.
|
||||
"""
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
|
||||
search_form = SearchForm(request.GET)
|
||||
valid_search = search_form.is_valid()
|
||||
cleaned_get = search_form.cleaned_data
|
||||
|
||||
news_entries = NewsEntry.objects.filter(title__contains=cleaned_get['search_terms'])
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Search Results",
|
||||
"searchtext": "search_terms="+ cleaned_get['search_terms'],
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
|
|
@ -15,6 +15,7 @@ def page_index(request):
|
|||
Main root page.
|
||||
"""
|
||||
# Some misc. configurable stuff.
|
||||
# TODO: Move this to either SQL or settings.py based configuration.
|
||||
fpage_player_limit = 4
|
||||
fpage_news_entries = 2
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
{% block header_ext %}
|
||||
{% endblock %}
|
||||
|
||||
<title>{{game_name}}</title>
|
||||
<title>{{game_name}} - {{page_title}}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
<div class="superHeader">
|
||||
<span>Related Sites:</span>
|
||||
<a href="http://evennia.com" title="The Python-based MUD server">Evennia</a> |
|
||||
<a href="http://www.oswd.org/userinfo.phtml?user=haran" title="Other designs by haran">haran’s Designs</a>
|
||||
<a href="http://www.oswd.org/designs/search/designer/id/3013/" title="Other designs by haran">haran’s Designs</a>
|
||||
</div>
|
||||
|
||||
<div class="midHeader">
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
<p class="newsSummary">{{entry.body|truncatewords:20}}</p>
|
||||
{% endfor %}
|
||||
|
||||
<div class="more"><a href="/tbi">More News »</a></div>
|
||||
<div class="more"><a href="/news/archive">More News »</a></div>
|
||||
|
||||
<p class="filler"><!-- Filler para to extend left vertical line --></p>
|
||||
</div>
|
||||
|
|
|
|||
51
webtemplates/prosimii/news/archive.html
Normal file
51
webtemplates/prosimii/news/archive.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block header_ext %}
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{{sidebar}}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 id="alt-layout">News Archive</h1>
|
||||
|
||||
<strong>Navigation:</strong> <a href="/news/archive/?page=1">First</a> |
|
||||
{% if has_previous %}
|
||||
<a href="/news/archive/?page={{previous}}">Prev</a>
|
||||
{% else %}
|
||||
Prev
|
||||
{% endif %}
|
||||
|
||||
| <em>{{page}}</em> of <em>{{pages}}</em> pages |
|
||||
|
||||
{% if has_next %}
|
||||
<a href="/news/archive/?page={{next}}">Next</a>
|
||||
{% else %}
|
||||
Next
|
||||
{% endif %}
|
||||
| <a href="/news/archive/?page={{pages}}">Last</a>
|
||||
|
||||
{% for entry in object_list %}
|
||||
<a href="/news/show/{{entry.id}}" class="newsHeading">{{entry.topic.name}}: {{entry.title}}</a>
|
||||
<p class="newsDate">By {{entry.author.username}} on {{entry.date_posted|time}}</p>
|
||||
<p class="newsSummary">{{entry.body|truncatewords:80}}</p>
|
||||
{% endfor %}
|
||||
|
||||
<strong>Navigation:</strong> <a href="/news/archive/?page=1">First</a> |
|
||||
{% if has_previous %}
|
||||
<a href="/news/archive/?page={{previous}}">Prev</a>
|
||||
{% else %}
|
||||
Prev
|
||||
{% endif %}
|
||||
|
||||
| <em>{{page}}</em> of <em>{{pages}}</em> pages |
|
||||
|
||||
{% if has_next %}
|
||||
<a href="/news/archive/?page={{next}}">Next</a>
|
||||
{% else %}
|
||||
Next
|
||||
{% endif %}
|
||||
| <a href="/news/archive/?page={{pages}}&{{searchtext|urlencode}}">Last</a>
|
||||
|
||||
{% endblock %}
|
||||
19
webtemplates/prosimii/news/search_form.html
Normal file
19
webtemplates/prosimii/news/search_form.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block header_ext %}
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{{sidebar}}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 id="alt-layout">Search News</h1>
|
||||
<p>Enter a search term or phrase to search by. Matches will be made against
|
||||
news titles and their contents.</p>
|
||||
<form method="GET">
|
||||
{{search_form.as_p}}
|
||||
<button type="Submit">Submit</button>
|
||||
</form>
|
||||
{{debug}}
|
||||
{% endblock %}
|
||||
|
|
@ -4,13 +4,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
<p class="doNotDisplay doNotPrint">This page’s menu:</p>
|
||||
<ul id="side-bar">
|
||||
<li><a href="#alt-layout" title="Alternative layout">Alt. layout</a></li>
|
||||
<li><a href="#compatibility" title="Improved cross-browser compatibility">Compatibility</a></li>
|
||||
<li><a href="#stylesheets" title="Comprehensive stylesheets">Stylesheets</a></li>
|
||||
<li><a href="#accessibility" title="Accessibility features">Accessibility</a></li>
|
||||
</ul>
|
||||
{{sidebar}}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue