Add #12: Lo-Fi Version
This commit is contained in:
parent
d566a85158
commit
a04005ad12
15 changed files with 276 additions and 86 deletions
|
@ -31,29 +31,9 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if sticky_topics or topics %}
|
||||
{% for topic in sticky_topics|forum_unreads:user %}
|
||||
<tr class="isticky">
|
||||
<td class="tcl">
|
||||
<div class="intd">
|
||||
<div class="icon"><div class="nosize"><!-- --></div></div>
|
||||
<div class="tclcon">
|
||||
{% if topic|has_unreads:user %}
|
||||
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span></strong>
|
||||
{% else %}
|
||||
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="tc2">{{ topic.post_count }}</td>
|
||||
<td class="tc3">{{ topic.views }}</td>
|
||||
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user }}</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
{% if topics %}
|
||||
{% for topic in topics|forum_unreads:user %}
|
||||
<tr {% if topic|has_unreads:user %}class="inew"{% endif %} {% if topic.closed %}class="iclosed"{% endif %}>
|
||||
<tr {% if topic.sticky %} class="isticky"{% endif %} {% if topic|has_unreads:user %}class="inew"{% endif %} {% if topic.closed %}class="iclosed"{% endif %}>
|
||||
<td class="tcl">
|
||||
<div class="intd">
|
||||
<div class="icon"><div class="nosize"><!-- --></div></div>
|
||||
|
@ -90,6 +70,16 @@
|
|||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="brdfooter" class="block">
|
||||
<div class="box">
|
||||
<div class="inbox" align="center">
|
||||
<a href="{{ forum.get_absolute_url }}lofi/">Lo-Fi Version</a>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block controls %}
|
||||
|
|
|
@ -63,6 +63,15 @@
|
|||
|
||||
</div>
|
||||
|
||||
<div id="brdfooter" class="block">
|
||||
<div class="box">
|
||||
<div class="inbox" align="center">
|
||||
<a href="{% url lofi_index %}">Lo-Fi Version</a>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block controls %}
|
||||
|
|
18
apps/forum/templates/forum/lofi/base.html
Normal file
18
apps/forum/templates/forum/lofi/base.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
<meta name="robots" content="index,follow" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}forum/css/lofi/lofiscreen.css" media="screen" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}forum/css/lofi/lofihandheld.css" media="handheld" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}forum/css/lofi/lofiprint.css" media="print" />
|
||||
<title>DjangoBB LoFi version</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% include 'forum/lofi/header.html' %}
|
||||
|
||||
{% block content %} {% endblock %}
|
||||
|
||||
{% include 'forum/lofi/footer.html' %}
|
||||
</body>
|
||||
</html>
|
1
apps/forum/templates/forum/lofi/footer.html
Normal file
1
apps/forum/templates/forum/lofi/footer.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div id='ipbcopyright'>Powered by <a href="http://www.djangobb.org/">DjangoBB</a></div>
|
27
apps/forum/templates/forum/lofi/forum.html
Normal file
27
apps/forum/templates/forum/lofi/forum.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{% extends 'forum/lofi/base.html' %}
|
||||
{% load forum_extras %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div id='largetext'>{% trans "Full Version:" %} {% link forum %}</div>
|
||||
<div class='ipbnav'>
|
||||
<a href="{% url lofi_index %}">{% trans "Root" %}</a> » {% lofi_link forum %}
|
||||
</div>
|
||||
|
||||
<div class="ipbpagespan">
|
||||
{% lofi_pagination %}
|
||||
</div>
|
||||
|
||||
<div id="ipbcontent">
|
||||
<div class="topicwrap">
|
||||
<ol>
|
||||
{% for topic in topics|forum_unreads:user %}
|
||||
<li>{% if topic.sticky %}<span style="color: red;"><strong>{% trans "IMPORTANT:" %}</strong></span>{% endif %}{% lofi_link topic %} <span class="desc">({{ topic.reply_count }} {% trans "replies" %})</span></li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<div class='smalltext'>This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please <a href='{{ forum.get_absolute_url }}'>click here</a>.</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
7
apps/forum/templates/forum/lofi/header.html
Normal file
7
apps/forum/templates/forum/lofi/header.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% load i18n %}
|
||||
<div id='ipbwrapper'>
|
||||
<div class='ipbnavsmall'>
|
||||
<a href='{% url search %}'>{% trans "Search" %}</a> -
|
||||
<a href='{% url forum_users %}'>{% trans "User list" %}</a>
|
||||
</div>
|
||||
|
29
apps/forum/templates/forum/lofi/index.html
Normal file
29
apps/forum/templates/forum/lofi/index.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
{% extends 'forum/lofi/base.html' %}
|
||||
{% load forum_extras %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div id='largetext'>{% trans "Full Version:" %} <a href="{% url index %}">{% trans "Root" %}</a></div>
|
||||
<div class='ipbnav'>
|
||||
<a href="{% url lofi_index %}">{% trans "Root" %}</a>
|
||||
</div>
|
||||
|
||||
<div id="ipbcontent">
|
||||
<div class="forumwrap">
|
||||
<ul>
|
||||
{% for iter in cats %}
|
||||
<li><strong>{{ iter.cat }}</strong></li>
|
||||
<ul>
|
||||
{% for forum in iter.forums %}
|
||||
<li>{% lofi_link forum %} <span class="desc">({{ forum.post_count }} {% trans "posts" %})</span></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class='smalltext'>This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please <a href='{% url index %}'>click here</a>.</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
4
apps/forum/templates/forum/lofi/pagination.html
Normal file
4
apps/forum/templates/forum/lofi/pagination.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{% load i18n %}
|
||||
{% for number in page_list %}
|
||||
<a href="{{ get_params }}page={{ number }}">{{ number }}</a>
|
||||
{% endfor %}
|
32
apps/forum/templates/forum/lofi/topic.html
Normal file
32
apps/forum/templates/forum/lofi/topic.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% extends 'forum/lofi/base.html' %}
|
||||
{% load forum_extras %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div id='largetext'>{% trans "Full Version:" %} {% link topic %}</div>
|
||||
<div class='ipbnav'>
|
||||
<a href="{% url lofi_index %}">{% trans "Root" %}</a> » {% lofi_link topic.forum %} » {% lofi_link topic %}
|
||||
</div>
|
||||
|
||||
<div class="ipbpagespan">
|
||||
{% lofi_pagination %}
|
||||
</div>
|
||||
|
||||
<div id='ipbcontent'>
|
||||
{% for post in posts %}
|
||||
<div class='postwrapper'>
|
||||
<div class='posttopbar'>
|
||||
<div class='postname'>{{ post.user }}</div>
|
||||
<div class='postdate'>{% forum_time post.created %}</div>
|
||||
</div>
|
||||
<div class='postcontent'>
|
||||
{{ post.body_html|safe }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class='smalltext'>This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please <a href='{{ topic.get_absolute_url }}'>click here</a>.</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -153,6 +153,16 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="brdfooter" class="block">
|
||||
<div class="box">
|
||||
<div class="inbox" align="center">
|
||||
<a href="{{ topic.get_absolute_url }}lofi/">Lo-Fi Version</a>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block controls %}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
# -*- coding: utf-8
|
||||
from datetime import datetime, timedelta
|
||||
import urllib
|
||||
try:
|
||||
from hashlib import md5
|
||||
except ImportError:
|
||||
import md5
|
||||
md5 = md5.new
|
||||
|
||||
from django import template
|
||||
from django.core.urlresolvers import reverse
|
||||
|
@ -104,7 +98,24 @@ def pagination(context, adjacent_pages=1):
|
|||
'page_list': page_list,
|
||||
'per_page': context['per_page'],
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('forum/lofi/pagination.html',takes_context=True)
|
||||
def lofi_pagination(context):
|
||||
page_list = range(1, context['pages'] + 1)
|
||||
paginator = context['paginator']
|
||||
|
||||
get_params = '&'.join(['%s=%s' % (x[0],','.join(x[1])) for x in
|
||||
context['request'].GET.iteritems() if (not x[0] == 'page' and not x[0] == 'per_page')])
|
||||
if get_params:
|
||||
get_params = '?%s&' % get_params
|
||||
else:
|
||||
get_params = '?'
|
||||
|
||||
return {
|
||||
'get_params': get_params,
|
||||
'page_list': page_list,
|
||||
'paginator': paginator,
|
||||
}
|
||||
|
||||
@register.simple_tag
|
||||
def link(object, anchor=u''):
|
||||
|
@ -116,6 +127,16 @@ def link(object, anchor=u''):
|
|||
anchor = anchor or smart_unicode(object)
|
||||
return mark_safe('<a href="%s">%s</a>' % (url, escape(anchor)))
|
||||
|
||||
@register.simple_tag
|
||||
def lofi_link(object, anchor=u''):
|
||||
"""
|
||||
Return A tag with lofi_link to object.
|
||||
"""
|
||||
|
||||
url = hasattr(object,'get_absolute_url') and object.get_absolute_url() or None
|
||||
anchor = anchor or smart_unicode(object)
|
||||
return mark_safe('<a href="%slofi">%s</a>' % (url, escape(anchor)))
|
||||
|
||||
@register.filter
|
||||
def has_unreads(topic, user):
|
||||
"""
|
||||
|
@ -226,32 +247,14 @@ def forum_stars(user):
|
|||
else:
|
||||
return mark_safe('<img src="%sforum/img/stars/Star_0.gif" alt="" >' % (settings.MEDIA_URL))
|
||||
|
||||
|
||||
@register.filter
|
||||
def online(user):
|
||||
return cache.get(str(user.id))
|
||||
|
||||
|
||||
@register.filter
|
||||
def pm_unreads(user):
|
||||
return PrivateMessage.objects.filter(dst_user=user, read=False).count()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def new_reports():
|
||||
return Report.objects.filter(zapped=False).count()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def gravatar(email):
|
||||
if forum_settings.GRAVATAR_SUPPORT:
|
||||
size = max(forum_settings.AVATAR_WIDTH, forum_settings.AVATAR_HEIGHT)
|
||||
url = "http://www.gravatar.com/avatar.php?"
|
||||
url += urllib.urlencode({
|
||||
'gravatar_id': md5(email.lower()).hexdigest(),
|
||||
'size': size,
|
||||
'default': forum_settings.GRAVATAR_DEFAULT,
|
||||
})
|
||||
return url
|
||||
else:
|
||||
return ''
|
|
@ -9,6 +9,11 @@ urlpatterns = patterns('',
|
|||
# Captcha
|
||||
(r'^', include('apps.captcha.urls')),
|
||||
|
||||
# Lo-Fi version
|
||||
url('^lofi/$', views.index, {'full':False}, name='lofi_index'),
|
||||
url('^(?P<forum_id>\d+)/lofi/$', views.show_forum, {'full':False}, name='lofi_forum'),
|
||||
url('^topic/(?P<topic_id>\d+)/lofi/$', views.show_topic, {'full':False}, name='lofi_topic'),
|
||||
|
||||
# Misc
|
||||
url('^$', views.index, name='index'),
|
||||
url('^(?P<forum_id>\d+)/$', views.show_forum, name='forum'),
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.utils.translation import force_unicode
|
|||
from django.utils.simplejson import JSONEncoder
|
||||
from django import forms
|
||||
from django.template.defaultfilters import urlize as django_urlize
|
||||
from django.core.paginator import Paginator
|
||||
|
||||
from apps.forum import settings as forum_settings
|
||||
|
||||
|
@ -228,3 +229,26 @@ def smiles(data):
|
|||
smiled_html = parser.html
|
||||
parser.close()
|
||||
return smiled_html
|
||||
|
||||
def paginate(items, request, per_page, total_count=None):
|
||||
try:
|
||||
page_number = int(request.GET.get('page', 1))
|
||||
except ValueError:
|
||||
page_number = 1
|
||||
|
||||
paginator = Paginator(items, per_page)
|
||||
pages = paginator.num_pages
|
||||
paged_list_name = paginator.page(page_number).object_list
|
||||
|
||||
return pages, paginator, paged_list_name
|
||||
|
||||
def set_language(request, language):
|
||||
"""
|
||||
Change the language of session of authenticated user.
|
||||
"""
|
||||
|
||||
if language and check_for_language(language):
|
||||
if hasattr(request, 'session'):
|
||||
request.session['django_language'] = language
|
||||
else:
|
||||
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language)
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.db import connection
|
||||
from django.core.cache import cache
|
||||
|
||||
from apps.forum.util import render_to, paged, build_form
|
||||
from apps.forum.util import render_to, paged, build_form, paginate
|
||||
from apps.forum.models import Category, Forum, Topic, Post, Profile, Read, Reputation, Report, PrivateMessage
|
||||
from apps.forum.forms import AddPostForm, EditPostForm, UserSearchForm, PostSearchForm, ReputationForm, MailToForm, EssentialsProfileForm, PersonalProfileForm, MessagingProfileForm, PersonalityProfileForm, DisplayProfileForm, PrivacyProfileForm, ReportForm, UploadAvatarForm, CreatePMForm
|
||||
from apps.forum.markups import mypostmarkup
|
||||
|
@ -20,7 +20,7 @@ from apps.forum import settings as forum_settings
|
|||
from apps.forum.util import urlize, smiles
|
||||
|
||||
@render_to('forum/index.html')
|
||||
def index(request):
|
||||
def index(request, full=True):
|
||||
users_online = []
|
||||
#TODO: refactoring
|
||||
for user in User.objects.all():
|
||||
|
@ -39,16 +39,27 @@ def index(request):
|
|||
|
||||
cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
|
||||
cats = sorted(cats.values(), cmpdef)
|
||||
|
||||
return {'cats': cats,
|
||||
'posts': Post.objects.count(),
|
||||
'topics': Topic.objects.count(),
|
||||
'users': User.objects.count(),
|
||||
'users_online': users_online,
|
||||
'online_count': len(users_online),
|
||||
'guest_count': guest_count,
|
||||
'last_user': User.objects.order_by('-date_joined')[0],
|
||||
}
|
||||
if full:
|
||||
return {'cats': cats,
|
||||
'posts': Post.objects.count(),
|
||||
'topics': Topic.objects.count(),
|
||||
'users': User.objects.count(),
|
||||
'users_online': users_online,
|
||||
'online_count': len(users_online),
|
||||
'guest_count': guest_count,
|
||||
'last_user': User.objects.order_by('-date_joined')[0],
|
||||
}
|
||||
else:
|
||||
return {'cats': cats,
|
||||
'posts': Post.objects.count(),
|
||||
'topics': Topic.objects.count(),
|
||||
'users': User.objects.count(),
|
||||
'users_online': users_online,
|
||||
'online_count': len(users_online),
|
||||
'guest_count': guest_count,
|
||||
'last_user': User.objects.order_by('-date_joined')[0],
|
||||
}, 'forum/lofi/index.html'
|
||||
|
||||
|
||||
@render_to('forum/moderate.html')
|
||||
@paged('topics', forum_settings.FORUM_PAGE_SIZE)
|
||||
|
@ -179,26 +190,36 @@ def misc(request):
|
|||
|
||||
@render_to('forum/forum.html')
|
||||
@paged('topics', forum_settings.FORUM_PAGE_SIZE)
|
||||
def show_forum(request, forum_id):
|
||||
def show_forum(request, forum_id, full=True):
|
||||
forum = Forum.objects.get(pk=forum_id)
|
||||
topics = forum.topics.filter(sticky=False).select_related()
|
||||
topics = forum.topics.order_by('-sticky').select_related()
|
||||
moderator = request.user.is_superuser or\
|
||||
request.user in forum.moderators.all()
|
||||
if full:
|
||||
return {'categories': Category.objects.all(),
|
||||
'forum': forum,
|
||||
'topics': topics,
|
||||
'paged_qs': topics,
|
||||
'posts': forum.posts.count(),
|
||||
'topics': forum.topics.count(),
|
||||
'moderator': moderator,
|
||||
}
|
||||
else:
|
||||
pages, paginator, paged_list_name = paginate(topics, request, forum_settings.FORUM_PAGE_SIZE)
|
||||
return {'categories': Category.objects.all(),
|
||||
'forum': forum,
|
||||
'posts': forum.posts.count(),
|
||||
'moderator': moderator,
|
||||
'pages': pages,
|
||||
'paginator': paginator,
|
||||
'topics': paged_list_name,
|
||||
}, 'forum/lofi/forum.html'
|
||||
|
||||
return {'categories': Category.objects.all(),
|
||||
'forum': forum,
|
||||
'topics': topics,
|
||||
'sticky_topics': forum.topics.filter(sticky=True),
|
||||
'paged_qs': topics,
|
||||
'posts': forum.posts.count(),
|
||||
'topics': forum.topics.count(),
|
||||
'moderator': moderator,
|
||||
}
|
||||
|
||||
|
||||
@render_to('forum/topic.html')
|
||||
@paged('posts', forum_settings.TOPIC_PAGE_SIZE)
|
||||
def show_topic(request, topic_id):
|
||||
def show_topic(request, topic_id, full=True):
|
||||
topic = Topic.objects.select_related().get(pk=topic_id)
|
||||
topic.views += 1
|
||||
topic.save()
|
||||
|
@ -227,18 +248,28 @@ def show_topic(request, topic_id):
|
|||
subscribed = True
|
||||
else:
|
||||
subscribed = False
|
||||
|
||||
highlight_word = request.GET.get('hw', '')
|
||||
|
||||
return {'categories': Category.objects.all(),
|
||||
'topic': topic,
|
||||
'last_post': last_post,
|
||||
'form': form,
|
||||
'moderator': moderator,
|
||||
'subscribed': subscribed,
|
||||
'paged_qs': posts,
|
||||
'highlight_word': highlight_word,
|
||||
}
|
||||
if full:
|
||||
return {'categories': Category.objects.all(),
|
||||
'topic': topic,
|
||||
'last_post': last_post,
|
||||
'form': form,
|
||||
'moderator': moderator,
|
||||
'subscribed': subscribed,
|
||||
'paged_qs': posts,
|
||||
}
|
||||
else:
|
||||
pages, paginator, paged_list_name = paginate(posts, request, forum_settings.TOPIC_PAGE_SIZE)
|
||||
return {'categories': Category.objects.all(),
|
||||
'topic': topic,
|
||||
#'last_post': last_post,
|
||||
#'form': form,
|
||||
#'moderator': moderator,
|
||||
#'subscribed': subscribed,
|
||||
#'paged_qs': posts,
|
||||
'pages': pages,
|
||||
'paginator': paginator,
|
||||
'posts': paged_list_name,
|
||||
}, 'forum/lofi/topic.html'
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
|
@ -12,9 +12,9 @@ ADMINS = (
|
|||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = '' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = '' # Not used with sqlite3.
|
||||
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = 'DjangoBB' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = 'root' # Not used with sqlite3.
|
||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
|
|
Reference in a new issue