Permalink
Browse files

Cleanup

  • Loading branch information...
1 parent 9500317 commit 64f6134c5db1b35249f1bdd465fbdbd22af0b07e @lorien lorien committed Jan 1, 2010
Showing with 58 additions and 136 deletions.
  1. +7 −0 .hgignore
  2. +12 −11 README
  3. +1 −1 pybb/models.py
  4. +0 −1 pybb/settings.py
  5. +5 −4 pybb/subscription.py
  6. +16 −86 pybb/util.py
  7. +17 −33 pybb/views.py
View
@@ -1,5 +1,12 @@
syntax: glob
+# Global
*.pyc
*.swp
+*.swo
+
+# Distutils
pybb.egg-info/
dist/
+
+# Sphinx
+docs/_build/
View
23 README
@@ -17,6 +17,18 @@ The main point in development of pybb is to build it so it could be
development. I mean that there are no threaded posts and there is only bbcode
markup support and there is no multi-level nested categories.
+
+Dependencies
+============
+
+* BeautifulSoup
+* python-markdown
+* simplejson
+* django-common
+* pytils (optional, need for russian language support)
+* SQLAlchemy (optional) - required for punbb importer
+* south (optional) - required for migrations
+
How to install PYBB?
====================
@@ -35,17 +47,6 @@ How to install PYBB?
* And do not forget to install some authentication application like django-registration or django-account. See info in the bottom of README
-Dependencies
-============
-
-* BeautifulSoup
-* PIL
-* python-markdown
-* pytils
-* SQLAlchemy (optional) - required for punbb importer
-* south (optional) - required for migrations
-
-
i18n support
============
PYBB support only english and russian translations now.
View
@@ -16,7 +16,7 @@
from pybb.markups import mypostmarkup
from pybb.fields import AutoOneToOneField, JSONField
-from pybb.util import urlize, memoize_method, unescape
+from pybb.util import urlize, unescape
TZ_CHOICES = [(float(x[0]), x[1]) for x in (
View
@@ -8,7 +8,6 @@
PYBB_TOPIC_PAGE_SIZE = 10
PYBB_FORUM_PAGE_SIZE = 20
PYBB_USERS_PAGE_SIZE = 20
-PYBB_HOST = 'hey.fix.your.settings'
PYBB_AVATAR_WIDTH = 60
PYBB_AVATAR_HEIGHT = 60
PYBB_DEFAULT_TIME_ZONE = 3
View
@@ -3,8 +3,7 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.utils import translation
-
-from pybb.util import absolute_url
+from django.contrib.sites.models import Site
TOPIC_SUBSCRIPTION_TEXT_TEMPLATE = lambda: _(u"""New reply from %(username)s to topic that you have subscribed on.
@@ -51,11 +50,13 @@ def notify_topic_subscribers(post):
subject = u'RE: %s' % topic.name
to_email = user.email
+ hostname = Sites.objects.get_current().domain
+ delete_url = reverse('pybb_delete_subscription', args=[post.topic.id])
text_content = TOPIC_SUBSCRIPTION_TEXT_TEMPLATE() % {
'username': post.user.username,
'message': post.body_text,
- 'post_url': absolute_url(post.get_absolute_url()),
- 'unsubscribe_url': absolute_url(reverse('pybb_delete_subscription', args=[post.topic.id])),
+ 'post_url': 'http://%s%s' % (hostname, post.get_absolute_url()),
+ 'unsubscribe_url': 'http://%s%s' % (hostname, delete_url),
}
#html_content = html_version(post)
send_mail([to_email], subject, text_content)
View
@@ -9,81 +9,34 @@
from md5 import md5
import urllib
-from django.http import HttpResponse
-from django.utils.functional import Promise
-from django.utils.translation import force_unicode, check_for_language
-from django.utils.simplejson import JSONEncoder
+from django.utils.translation import check_for_language
from django import forms
from django.template.defaultfilters import urlize as django_urlize
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.conf import settings
-def ajax(func):
+def urlize(data):
"""
- Checks request.method is POST. Return error in JSON in other case.
+ Urlize plain text links in the HTML contents.
- If view returned dict, returns JsonResponse with this dict as content.
+ Do not urlize content of A and CODE tags.
"""
- def wrapper(request, *args, **kwargs):
- if request.method == 'POST':
- try:
- response = func(request, *args, **kwargs)
- except Exception, ex:
- response = {'error': traceback.format_exc()}
- else:
- response = {'error': {'type': 403, 'message': 'Accepts only POST request'}}
- if isinstance(response, dict):
- return JsonResponse(response)
- else:
- return response
- return wrapper
+ soup = BeautifulSoup(data)
+ for chunk in soup.findAll(text=True):
+ islink = False
+ ptr = chunk.parent
+ while ptr.parent:
+ if ptr.name == 'a' or ptr.name == 'code':
+ islink = True
+ break
+ ptr = ptr.parent
-class LazyJSONEncoder(JSONEncoder):
- """
- This fing need to save django from crashing.
- """
-
- def default(self, o):
- if isinstance(o, Promise):
- return force_unicode(o)
- else:
- return super(LazyJSONEncoder, self).default(o)
+ if not islink:
+ chunk = chunk.replaceWith(django_urlize(unicode(chunk)))
-
-class JsonResponse(HttpResponse):
- """
- HttpResponse subclass that serialize data into JSON format.
- """
-
- def __init__(self, data, mimetype='application/json'):
- json_data = LazyJSONEncoder().encode(data)
- super(JsonResponse, self).__init__(
- content=json_data, mimetype=mimetype)
-
-
-def urlize(data):
- """
- Urlize plain text links in the HTML contents.
-
- Do not urlize content of A and CODE tags.
- """
-
- soup = BeautifulSoup(data)
- for chunk in soup.findAll(text=True):
- islink = False
- ptr = chunk.parent
- while ptr.parent:
- if ptr.name == 'a' or ptr.name == 'code':
- islink = True
- break
- ptr = ptr.parent
-
- if not islink:
- chunk = chunk.replaceWith(django_urlize(unicode(chunk)))
-
- return unicode(soup)
+ return unicode(soup)
def quote_text(text, markup, username=""):
@@ -103,29 +56,6 @@ def quote_text(text, markup, username=""):
return text
-def absolute_url(path):
- return 'http://%s%s' % (settings.PYBB_HOST, path)
-
-
-def memoize_method(func):
- """
- Cached result of function call.
- """
-
- def wrapper(self, *args, **kwargs):
- CACHE_NAME = '__memcache'
- try:
- cache = getattr(self, CACHE_NAME)
- except AttributeError:
- cache = {}
- setattr(self, CACHE_NAME, cache)
- key = (func, tuple(args), frozenset(kwargs.items()))
- if key not in cache:
- cache[key] = func(self, *args, **kwargs)
- return cache[key]
- return wrapper
-
-
def paginate(items, request, per_page, total_count=None):
try:
page_number = int(request.GET.get('page', 1))
View
@@ -9,8 +9,7 @@
except ImportError:
pytils_enabled = False
-from django.shortcuts import get_object_or_404, get_list_or_404, render_to_response
-from django.template import RequestContext
+from django.shortcuts import get_object_or_404, get_list_or_404
from django.http import HttpResponseRedirect, HttpResponse,\
HttpResponseNotFound, Http404
from django.contrib.auth.models import User
@@ -21,9 +20,11 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext
+from common.decorators import render_to, ajax
+
from pybb.markups import mypostmarkup
from pybb.util import quote_text, paginate,\
- set_language, ajax, urlize
+ set_language, urlize
from pybb.models import Category, Forum, Topic, Post, Profile, \
Attachment, MARKUP_CHOICES
from pybb.forms import AddPostForm, EditPostForm, EditHeadPostForm, \
@@ -32,24 +33,6 @@
from pybb.read_tracking import update_read_tracking
-def render_to(template, func):
- """
- Shortcut for rendering template with RequestContext.
-
- If decorated function returns non dict then just return that result
- else use RequestContext for rendering the template.
- """
-
- def wrapper(request, *args, **kwargs):
- output = func(request, *args, **kwargs)
- if not isinstance(output, dict):
- return output
- else:
- return render_to_response(template, output,
- context_instance=RequestContext(request))
- return wrapper
-
-
def index_ctx(request):
cats = {}
for forum in Forum.objects.all().select_related():
@@ -444,6 +427,7 @@ def post_ajax_preview(request):
content = request.POST.get('content')
markup = request.POST.get('markup')
+ print 'markup', markup
if not markup in dict(MARKUP_CHOICES).keys():
return {'error': 'Invalid markup'}
@@ -462,15 +446,15 @@ def post_ajax_preview(request):
}
-users = render_to('pybb/users.html', users_ctx)
-merge_topics = render_to('pybb/merge_topics.html', merge_topics_ctx)
-delete_post = render_to('pybb/delete_post.html', delete_post_ctx)
-edit_post = render_to('pybb/edit_post.html', edit_post_ctx)
-edit_profile = render_to('pybb/edit_profile.html', edit_profile_ctx)
-user_topics = render_to('pybb/user_topics.html', user_topics_ctx)
-user = render_to('pybb/user.html', user_ctx)
-add_post = render_to('pybb/add_post.html', add_post_ctx)
-show_topic = render_to('pybb/topic.html', show_topic_ctx)
-show_forum = render_to('pybb/forum.html', show_forum_ctx)
-index = render_to('pybb/index.html', index_ctx)
-show_category = render_to('pybb/category.html', show_category_ctx)
+users = render_to('pybb/users.html')(users_ctx)
+merge_topics = render_to('pybb/merge_topics.html')(merge_topics_ctx)
+delete_post = render_to('pybb/delete_post.html')(delete_post_ctx)
+edit_post = render_to('pybb/edit_post.html')(edit_post_ctx)
+edit_profile = render_to('pybb/edit_profile.html')(edit_profile_ctx)
+user_topics = render_to('pybb/user_topics.html')(user_topics_ctx)
+user = render_to('pybb/user.html')(user_ctx)
+add_post = render_to('pybb/add_post.html')(add_post_ctx)
+show_topic = render_to('pybb/topic.html')(show_topic_ctx)
+show_forum = render_to('pybb/forum.html')(show_forum_ctx)
+index = render_to('pybb/index.html')(index_ctx)
+show_category = render_to('pybb/category.html')(show_category_ctx)

0 comments on commit 64f6134

Please sign in to comment.