From 745f67c37acdb9574c5297004adde2b9a7da5fdb Mon Sep 17 00:00:00 2001 From: hernani Date: Fri, 11 Mar 2011 20:01:26 +0000 Subject: [PATCH] merging jambazov > trunk git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@823 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/node.py | 25 +++++++++++++++--- forum/models/tag.py | 26 ++++++++++++++++++- .../skins/default/templates/base_content.html | 6 ++++- .../default/templates/node/award_points.html | 23 ++++++++++++++++ forum/templatetags/node_tags.py | 6 +++++ forum/urls.py | 5 ++-- forum/views/commands.py | 17 ++++++++++++ 7 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 forum/skins/default/templates/node/award_points.html diff --git a/forum/models/node.py b/forum/models/node.py index abd1f5a..7449082 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -8,6 +8,7 @@ from django.utils.safestring import mark_safe from django.utils.html import strip_tags from forum.utils.html import sanitize_html from forum.settings import SUMMARY_LENGTH +from forum.modules import MODULES_PACKAGE from utils import PickledObjectField class NodeContent(models.Model): @@ -142,12 +143,30 @@ class NodeManager(CachedManager): use_for_related_fields = True def get_query_set(self): + CurrentUserHolder = None + + moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE + exec moderation_import + qs = NodeQuerySet(self.model) if self.model is not Node: - return qs.filter(node_type=self.model.get_type()) - else: - return qs + qs = qs.filter(node_type=self.model.get_type()) + + if CurrentUserHolder is not None: + user = CurrentUserHolder.user + + try: + filter_content = not user.is_staff and not user.is_superuser + except: + filter_content = True + + if filter_content: + qs = qs.exclude(state_string__contains="(in_moderation)").exclude(state_string__contains="(deleted)").exclude( + state_string__contains="(rejected)" + ) + + return qs def get_for_types(self, types, *args, **kwargs): kwargs['node_type__in'] = [t.get_type() for t in types] diff --git a/forum/models/tag.py b/forum/models/tag.py index 44e0a74..2a3609a 100644 --- a/forum/models/tag.py +++ b/forum/models/tag.py @@ -1,13 +1,36 @@ import datetime from base import * +from forum.modules import MODULES_PACKAGE + from django.utils.translation import ugettext as _ import django.dispatch class ActiveTagManager(models.Manager): def get_query_set(self): - return super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1) + qs = super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1) + + CurrentUserHolder = None + + moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE + exec moderation_import + + if CurrentUserHolder is not None: + user = CurrentUserHolder.user + + try: + filter_content = not user.is_staff and not user.is_superuser + except: + filter_content = True + + if filter_content: + moderation_import = 'from %s.moderation.hooks import get_tag_ids' % MODULES_PACKAGE + exec moderation_import + qs = qs.exclude(id__in=get_tag_ids('deleted')).exclude(id__in=get_tag_ids('rejected')).exclude( + id__in=get_tag_ids('in_moderation') + ) + return qs class Tag(BaseModel): name = models.CharField(max_length=255, unique=True) @@ -18,6 +41,7 @@ class Tag(BaseModel): used_count = models.PositiveIntegerField(default=0) active = ActiveTagManager() + objects = ActiveTagManager() class Meta: ordering = ('-used_count', 'name') diff --git a/forum/skins/default/templates/base_content.html b/forum/skins/default/templates/base_content.html index 2281f0e..021437c 100644 --- a/forum/skins/default/templates/base_content.html +++ b/forum/skins/default/templates/base_content.html @@ -16,9 +16,13 @@ {% if settings.USE_CUSTOM_CSS|or_preview:request %} {% endif %} + {% block forestyle %}{% endblock %} - + \ No newline at end of file diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index 01745be..544d918 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -90,6 +90,12 @@ def post_controls(post, user): controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id}), title=_("answer permanent link"), command=True, withprompt=True)) + # Users should be able to award points for an answer. Users cannot award their own answers + if user != post.author and user.is_authenticated(): + controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id, + 'answer_id' : post.id}), title=_("award points to %s") % post.author, + command=True, withprompt=True)) + # The other controls are visible only to authenticated users. if user.is_authenticated(): try: diff --git a/forum/urls.py b/forum/urls.py index be0d9f3..fc64e28 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -85,8 +85,9 @@ urlpatterns += patterns('', name="convert_comment"), url(r'^%s(?P\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"), url(r'^%s(?P\d+)/$' % _('answer_link/'), app.commands.answer_permanent_link, name="answer_permanent_link"), - url(r'^%s(?P\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite") - , + url(r'^%s(?P\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite"), + url(r'^%s%s(?P\d+)/%s(?P\d+)/$' % (_('award_points/'), _('user/'), _('answer/')), app.commands.award_points, name="award_points"), + url(r'^%s(?P\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'), url(r'^%s(?P\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'), url(r'^%s(?P\d+)/(?P\d+)?$' % _('subscribe/'), app.commands.subscribe, name="subscribe"), diff --git a/forum/views/commands.py b/forum/views/commands.py index 3d2f9d3..11818ec 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -580,3 +580,20 @@ def answer_permanent_link(request, id): # Display the template return render_to_response('node/permanent_link.html', { 'url' : url, }) + +@decorate.withfn(command) +def award_points(request, user_id, answer_id): + user = request.user + awarded_user = get_object_or_404(User, id=user_id) + + # Users shouldn't be able to award themselves + if awarded_user.id == user.id: + raise CannotDoOnOwnException(_("award")) + + # Anonymous users cannot award points, they just don't have such + if not user.is_authenticated(): + raise AnonymousNotAllowedException(_('award')) + + return render_to_response("node/award_points.html", { 'user' : user, 'awarded_user' : awarded_user, }) + # Display the template + return render_to_response('node/permanent_link.html', { 'url' : url, }) -- 2.39.5