]> git.openstreetmap.org Git - osqa.git/commitdiff
merging jambazov > trunk
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 11 Mar 2011 20:01:26 +0000 (20:01 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 11 Mar 2011 20:01:26 +0000 (20:01 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@823 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/node.py
forum/models/tag.py
forum/skins/default/templates/base_content.html
forum/skins/default/templates/node/award_points.html [new file with mode: 0644]
forum/templatetags/node_tags.py
forum/urls.py
forum/views/commands.py

index abd1f5a3b402f8cf946c1cdf626e77fb91c93dbc..74490829b46245097af166dca69c0632e5ec812a 100644 (file)
@@ -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 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):
 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):
     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:
         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]
 
     def get_for_types(self, types, *args, **kwargs):
         kwargs['node_type__in'] = [t.get_type() for t in types]
index 44e0a749aa40f0bdbd6fe274c59f374dc55c774f..2a3609a9636d6f4cd6fdbe2f7461620a5162ef48 100644 (file)
@@ -1,13 +1,36 @@
 import datetime
 from base import *
 
 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):
 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)
 
 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()
     used_count = models.PositiveIntegerField(default=0)
 
     active = ActiveTagManager()
+    objects = ActiveTagManager()
 
     class Meta:
         ordering = ('-used_count', 'name')
 
     class Meta:
         ordering = ('-used_count', 'name')
index 2281f0e6e3cc36ec8f17ad30b22ff405f88cf123..021437ce4c3115fc3597562056463317b46e3e59 100644 (file)
         {% if settings.USE_CUSTOM_CSS|or_preview:request %}
         <link href="{% url custom_css %}" rel="stylesheet" type="text/css" />
         {% endif %}
         {% if settings.USE_CUSTOM_CSS|or_preview:request %}
         <link href="{% url custom_css %}" rel="stylesheet" type="text/css" />
         {% endif %}
+        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" />
         {% block forestyle %}{% endblock %}
         <script src="http://www.google.com/jsapi" type="text/javascript"></script>
         {% block forestyle %}{% endblock %}
         <script src="http://www.google.com/jsapi" type="text/javascript"></script>
-        <script type="text/javascript">google.load("jquery", "1.4.2");</script>
+        <script type="text/javascript">
+            google.load("jquery", "1.4.2");
+            google.load("jqueryui", "1", {autoload:true});
+        </script>
         <script type="text/javascript">
         /* <![CDATA[ */
             var i18nLang = '{{settings.LANGUAGE_CODE}}';
         <script type="text/javascript">
         /* <![CDATA[ */
             var i18nLang = '{{settings.LANGUAGE_CODE}}';
diff --git a/forum/skins/default/templates/node/award_points.html b/forum/skins/default/templates/node/award_points.html
new file mode 100644 (file)
index 0000000..8210069
--- /dev/null
@@ -0,0 +1,23 @@
+{% load i18n %}
+
+<p>
+{% blocktrans %}
+Award {{ awarded_user }} with reputation points.
+{% endblocktrans %}
+</p>
+
+<p>
+    Points:
+    <span id="reputation_points_award">1</span>
+</p>
+
+<div class="award_points_slider"></div>
+
+<script>
+$('.award_points_slider').slider({
+    min: 1, max: {{ user.reputation }},
+    slide: function(evt, ui) {
+        $('#reputation_points_award').html(ui.value)
+    }
+});
+</script>
\ No newline at end of file
index 01745be5fb82b936c44ef8e2742c28af1e65391d..544d91872da498422acceab42c90726b9fb9494f 100644 (file)
@@ -90,6 +90,12 @@ def post_controls(post, user):
         controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id}),\r
                                      title=_("answer permanent link"), command=True, withprompt=True))\r
 \r
         controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id}),\r
                                      title=_("answer permanent link"), command=True, withprompt=True))\r
 \r
+        # Users should be able to award points for an answer. Users cannot award their own answers\r
+        if user != post.author and user.is_authenticated():\r
+            controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id,\r
+                                         'answer_id' : post.id}), title=_("award points to %s") % post.author,\r
+                                         command=True, withprompt=True))\r
+\r
     # The other controls are visible only to authenticated users.\r
     if user.is_authenticated():\r
         try:\r
     # The other controls are visible only to authenticated users.\r
     if user.is_authenticated():\r
         try:\r
index be0d9f3a7e37c1dea8a2a50870e7840d55ed05e9..fc64e28ac953c980a2dcb1272bd1ccd70c0f9a70 100644 (file)
@@ -85,8 +85,9 @@ urlpatterns += patterns('',
                             name="convert_comment"),
                         url(r'^%s(?P<id>\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"),
                         url(r'^%s(?P<id>\d+)/$' % _('answer_link/'), app.commands.answer_permanent_link, name="answer_permanent_link"),
                             name="convert_comment"),
                         url(r'^%s(?P<id>\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"),
                         url(r'^%s(?P<id>\d+)/$' % _('answer_link/'), app.commands.answer_permanent_link, name="answer_permanent_link"),
-                        url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite")
-                        ,
+                        url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite"),
+                        url(r'^%s%s(?P<user_id>\d+)/%s(?P<answer_id>\d+)/$' % (_('award_points/'), _('user/'), _('answer/')), app.commands.award_points, name="award_points"),
+
                         url(r'^%s(?P<id>\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'),
                         url(r'^%s(?P<id>\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'),
                         url(r'^%s(?P<id>\d+)/(?P<user>\d+)?$' % _('subscribe/'), app.commands.subscribe, name="subscribe"),
                         url(r'^%s(?P<id>\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'),
                         url(r'^%s(?P<id>\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'),
                         url(r'^%s(?P<id>\d+)/(?P<user>\d+)?$' % _('subscribe/'), app.commands.subscribe, name="subscribe"),
index 3d2f9d32de268da53eb053e0f746b5b30577c3c7..11818ecacf30c17539ae8d13867683e43ce8bf56 100644 (file)
@@ -580,3 +580,20 @@ def answer_permanent_link(request, id):
 
     # Display the template
     return render_to_response('node/permanent_link.html', { 'url' : url, })
 
     # 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, })