Commits

Sergey Maranchuk committed f0df669 Merge

merge

Comments (0)

Files changed (13)

djangobb_forum/fields.py

 except ImportError:
     from StringIO import StringIO
 import random
+from hashlib import sha1
 
 from django.db.models import OneToOneField
 from django.db.models.fields.related import SingleRelatedObjectDescriptor 
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.core.serializers.json import DjangoJSONEncoder
 from django.utils import simplejson as json
-from django.utils.hashcompat import sha_constructor
 from django.conf import settings
 
 
     def save_form_data(self, instance, data):
         if data and self.width and self.height:
             content = self.resize_image(data.read(), width=self.width, height=self.height)
-            salt = sha_constructor(str(random.random())).hexdigest()[:5]
-            fname =  sha_constructor(salt + settings.SECRET_KEY).hexdigest() + '.png'
+            salt = sha1(str(random.random())).hexdigest()[:5]
+            fname =  sha1(salt + settings.SECRET_KEY).hexdigest() + '.png'
             data = SimpleUploadedFile(fname, content, data.content_type)
         super(ExtendedImageField, self).save_form_data(instance, data)
 

djangobb_forum/forms.py

             #show_group = self.cleaned_data['show_group']
             sort_by = self.cleaned_data['sort_by']
             sort_dir = self.cleaned_data['sort_dir']
+            qs = qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH)
             if sort_by=='username':
                 if sort_dir=='ASC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('username')
+                    return qs.order_by('username')
                 elif sort_dir=='DESC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-username')
+                    return qs.order_by('-username')
             elif sort_by=='registered':
                 if sort_dir=='ASC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('date_joined')
+                    return qs.order_by('date_joined')
                 elif sort_dir=='DESC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-date_joined')
+                    return qs.order_by('-date_joined')
             elif sort_by=='num_posts':
                 if sort_dir=='ASC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('forum_profile__post_count')
+                    return qs.order_by('forum_profile__post_count')
                 elif sort_dir=='DESC':
-                    return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-forum_profile__post_count')
+                    return qs.order_by('-forum_profile__post_count')
         else:
             return qs
 

djangobb_forum/middleware.py

 class LastLoginMiddleware(object):
     def process_request(self, request):
         if request.user.is_authenticated():
-            cache.set(str(request.user.id), True, forum_settings.USER_ONLINE_TIMEOUT)
+            cache.set('djangobb_user%d' % request.user.id, True, forum_settings.USER_ONLINE_TIMEOUT)
 
 class ForumMiddleware(object):
     def process_request(self, request):
 class UsersOnline(object):
     def process_request(self, request):
         now = datetime.now()
-        delta = now - timedelta(minutes=forum_settings.USER_ONLINE_TIMEOUT)
-        users_online = cache.get('users_online', {})
-        guests_online = cache.get('guests_online', {})
+        delta = now - timedelta(seconds=forum_settings.USER_ONLINE_TIMEOUT)
+        users_online = cache.get('djangobb_users_online', {})
+        guests_online = cache.get('djangobb_guests_online', {})
 
         if request.user.is_authenticated():
             users_online[request.user.id] = now
             if guests_online[guest_id] < delta:
                 del guests_online[guest_id]
 
-        cache.set('users_online', users_online, 60*60*24)
-        cache.set('guests_online', guests_online, 60*60*24)
+        cache.set('djangobb_users_online', users_online, 60*60*24)
+        cache.set('djangobb_guests_online', guests_online, 60*60*24)

djangobb_forum/models.py

 from datetime import datetime
 import os
 import os.path
+from hashlib import sha1
 
 from django.db import models
 from django.contrib.auth.models import User, Group
 from django.conf import settings
 from django.utils.translation import ugettext_lazy as _
-from django.utils.hashcompat import sha_constructor
 from django.db.models.signals import post_save
 
 from djangobb_forum.fields import AutoOneToOneField, ExtendedImageField, JSONField
     def save(self, *args, **kwargs):
         super(Attachment, self).save(*args, **kwargs)
         if not self.hash:
-            self.hash = sha_constructor(str(self.id) + settings.SECRET_KEY).hexdigest()
+            self.hash = sha1(str(self.id) + settings.SECRET_KEY).hexdigest()
         super(Attachment, self).save(*args, **kwargs)
 
     @models.permalink

djangobb_forum/settings.py

 DEFAULT_TIME_ZONE = get('DJANGOBB_DEFAULT_TIME_ZONE', 3)
 SIGNATURE_MAX_LENGTH = get('DJANGOBB_SIGNATURE_MAX_LENGTH', 1024)
 SIGNATURE_MAX_LINES = get('DJANGOBB_SIGNATURE_MAX_LINES', 3)
-READ_TIMEOUT = get('DJANGOBB_READ_TIMEOUT', 3600 * 24 * 7)
 HEADER = get('DJANGOBB_HEADER', 'DjangoBB')
 TAGLINE = get('DJANGOBB_TAGLINE', 'Django based forum engine')
 DEFAULT_MARKUP = get('DJANGOBB_DEFAULT_MARKUP', 'bbcode')
 NOTICE = get('DJANGOBB_NOTICE', '')
-USER_ONLINE_TIMEOUT = get('DJANGOBB_USER_ONLINE_TIMEOUT', 15)
+USER_ONLINE_TIMEOUT = get('DJANGOBB_USER_ONLINE_TIMEOUT', 15 * 60)
 EMAIL_DEBUG = get('DJANGOBB_FORUM_EMAIL_DEBUG', False)
 POST_USER_SEARCH = get('DJANGOBB_POST_USER_SEARCH', 1)
 
 LOFI_SUPPORT = get('DJANGOBB_LOFI_SUPPORT', True)
 
 # PM Extension
-PM_SUPPORT = get('DJANGOBB_PM_SUPPORT', True)
+if 'django_messages' not in settings.INSTALLED_APPS:
+    PM_SUPPORT = False
+else:
+    PM_SUPPORT = get('DJANGOBB_PM_SUPPORT', True)
 
 # AUTHORITY Extension
 AUTHORITY_SUPPORT = get('DJANGOBB_AUTHORITY_SUPPORT', True)

djangobb_forum/templates/djangobb_forum/profile/profile_essentials.html

 							<label><strong>{{ form.email.label }}</strong><br>
 							{{ form.email }}<br></label>
 							{% if request.user.is_superuser %}
-							<p><a href="{% url djangobb:misc %}?mail_to={{ profile }}">{% trans "Send e-mail" %}</a></p>
+								<p><a href="{% url djangobb:misc %}?mail_to={{ profile }}">{% trans "Send e-mail" %}</a></p>
 							{% endif %}
 
 						</div>

djangobb_forum/templates/djangobb_forum/search_posts.html

 {% extends 'djangobb_forum/base.html' %}
 {% load forum_extras %}
 {% load i18n %}
+{% load pagination_tags %}
 
 {% block content %}
-{% with results as paged_qs %}
+{% autopaginate results forum_settings.FORUM_PAGE_SIZE %}
 <div class="linkst">
 	<div class="inbox">
-		<p class="pagelink">{% pagination %}</p>
+		<p class="pagelink">{% paginate %}</p>
 		<div class="clearer"></div>
 	</div>
 </div>
 {% if results %}
 {% for post in results %}
 <div class="blockpost searchposts roweven">
-	<h2>{% link post.object.topic.forum %}&nbsp;&raquo;&nbsp;{% link post.object.topic %}&nbsp;&raquo;&nbsp;<a href="{{ post.object.get_absolute_url }}">{% forum_time post.object.created %}</a></h2>
+	<h2>{% link post.object.topic.forum %}&nbsp;&raquo;&nbsp;{% link post.object.topic %}&nbsp;&raquo;&nbsp;<a href="{{ post.object.get_absolute_url }}">{% forum_time post.created %}</a></h2>
 
 	<div class="box">
 		<div class="inbox">
 				<dl>
 					<dt><strong><a href="{% url djangobb:forum_profile post.object.user %}">{{ post.object.user }}</a></strong></dt>
 					<dd>{% trans "Replies:" %} {{ post.object.topic.post_count }}</dd>
-					<dd><div class="icon"><div class="nosize"><!-- --></div></div>
-</dd>
-
+					<dd><div class="icon"><div class="nosize"><!-- --></div></div></dd>
 					<dd><p class="clearb"><a href="{{ post.object.get_absolute_url }}">{% trans "Go to post" %}</a></p></dd>
 				</dl>
 			</div>
 			<div class="postright">
 				<div class="postmsg">
 					{{ post.object.body_html|safe }}
-
 				</div>
 			</div>
 			<div class="clearer"></div>
 <div id="msg" class="block">
 	<h2><span>{% trans "Info" %}</span></h2>
 	<div class="box">
-
 		<div class="inbox">
 		<p>{% trans "Your search returned no hits." %}</p>
 		<p><a href="javascript: history.go(-1)">{% trans "Go back" %}</a></p>
 
 <div class="postlinksb">
 	<div class="inbox">
-		<p class="pagelink">{% pagination %}</p>
+		<p class="pagelink">{% paginate %}</p>
 		<div class="clearer"></div>
 	</div>
 </div>
-{% endwith %}
 {% endblock %}
 
 {% block controls %}
 					{% endif %}
 				</dl>
 {% endblock %}
-
-

djangobb_forum/templates/djangobb_forum/search_topics.html

 <div id="msg" class="block">
 	<h2><span>{% trans "Info" %}</span></h2>
 	<div class="box">
-
 		<div class="inbox">
 		<p>{% trans "Your search returned no hits." %}</p>
 		<p><a href="javascript: history.go(-1)">{% trans "Go back" %}</a></p>

djangobb_forum/templatetags/forum_extras.py

     
 @register.filter
 def online(user):
-    return cache.get(str(user.id))
+    return cache.get('djangobb_user%d' % user.id)
 
 @register.filter
 def attachment_link(attach):

djangobb_forum/util.py

 _SMILES = [(re.compile(smile_re), path) for smile_re, path in forum_settings.SMILES]
 
 
-def render_to(template):
-    """
-    Decorator for Django views that sends returned dict to render_to_response function.
-
-    Template name can be decorator parameter or TEMPLATE item in returned dictionary.
-    RequestContext always added as context instance.
-    If view doesn't return dict then decorator simply returns output.
-
-    Parameters:
-     - template: template name to use
-
-    Examples:
-    # 1. Template name in decorator parameters
-
-    @render_to('template.html')
-    def foo(request):
-        bar = Bar.object.all()  
-        return {'bar': bar}
-
-    # equals to 
-    def foo(request):
-        bar = Bar.object.all()  
-        return render_to_response('template.html', 
-                                  {'bar': bar}, 
-                                  context_instance=RequestContext(request))
-
-    # 2. Template name as TEMPLATE item value in return dictionary
-
-    @render_to()
-    def foo(request, category):
-        template_name = '%s.html' % category
-        return {'bar': bar, 'TEMPLATE': template_name}
-    
-    #equals to
-    def foo(request, category):
-        template_name = '%s.html' % category
-        return render_to_response(template_name, 
-                                  {'bar': bar}, 
-                                  context_instance=RequestContext(request))
-    """
-
-    def renderer(function):
-        def wrapper(request, *args, **kwargs):
-            output = function(request, *args, **kwargs)
-            if not isinstance(output, dict):
-                return output
-            tmpl = output.pop('TEMPLATE', template)
-            return render_to_response(tmpl, output, context_instance=RequestContext(request))
-        return wrapper
-    return renderer
-
-
 def absolute_url(path):
     return 'http://%s%s' % (Site.objects.get_current().domain, path)
 

djangobb_forum/views.py

 
 
 def index(request, full=True):
-    users_cached = cache.get('users_online', {})
+    users_cached = cache.get('djangobb_users_online', {})
     users_online = users_cached and User.objects.filter(id__in = users_cached.keys()) or []
-    guests_cached = cache.get('guests_online', {})
+    guests_cached = cache.get('djangobb_guests_online', {})
     guest_count = len(guests_cached)
     users_count = len(users_online)
 
             date = datetime.today() - timedelta(1)
             topics = topics.filter(created__gte=date)
         elif action == 'show_new':
-            last_read = PostTracking.objects.get(user=request.user).last_read
+            try:
+                last_read = PostTracking.objects.get(user=request.user).last_read
+            except PostTracking.DoesNotExist:
+                last_read = None
             if last_read:
                 topics = topics.filter(last_post__updated__gte=last_read).all()
             else:
             if 'topics' in request.GET['show_as']:
                 topics = []
                 topics_to_exclude = SQ()
+                #TODO: rewrite
                 for post in posts:
                     if post.object.topic not in topics:
                         if post.object.topic.forum.category.has_access(request.user):
                     posts = posts.exclude(topics_to_exclude)
                 return render(request, 'djangobb_forum/search_topics.html', {'results': topics})
             elif 'posts' in request.GET['show_as']:
-                return render(request, 'djangobb_forum/search_posts.html', {'results': topics})
+                return render(request, 'djangobb_forum/search_posts.html', {'results': posts})
         return render(request, 'djangobb_forum/search_topics.html', {'results': topics})
     else:
         form = PostSearchForm()
     elif 'mail_to' in request.GET:
         mailto = get_object_or_404(User, username=request.GET['mail_to'])
         form = MailToForm()
-        return (request, 'djangobb_forum/mail_to.html', {'form':form,
-                'mailto': mailto,
-               })
+        return render(request, 'djangobb_forum/mail_to.html', {'form':form,
+                'mailto': mailto}
+                )
 
 
 def show_forum(request, forum_id, full=True):
     if 'post_id' in request.GET:
         post_id = request.GET['post_id']
         post = get_object_or_404(Post, pk=post_id)
-        form.fields['body'].initial = "[quote=%s]%s[/quote]" % (post.user, post.body)
+        form.fields['body'].initial = u"[quote=%s]%s[/quote]" % (post.user, post.body)
 
     if form.is_valid():
         post = form.save();
                 'form': form,
                })
     else:
+        template = 'djangobb_forum/user.html'
         topic_count = Topic.objects.filter(user__id=user.id).count()
         if user.forum_profile.post_count < forum_settings.POST_USER_SEARCH and not request.user.is_authenticated():
             return HttpResponseRedirect(reverse('user_signin') + '?next=%s' % request.path)

extras/requirements.txt

 PIL>=1.1.7
 django-haystack>=1.2.5
 south
-django-messages==0.4.4
 pygments
 postmarkup
-django-pagination
+django-pagination
+https://github.com/arneb/django-messages/tarball/master#egg=django-messages
     packages=find_packages(),
     include_package_data=True,
     install_requires=[
-            'django>=1.2',
+            'django>=1.3.1',
             'pil>=1.1.7',
-            'django-messages==0.4.4',
             'django-haystack',
             'django-pagination',
             'south',