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):
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]
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)
used_count = models.PositiveIntegerField(default=0)
active = ActiveTagManager()
+ objects = ActiveTagManager()
class Meta:
ordering = ('-used_count', 'name')
{% 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>
- <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}}';
--- /dev/null
+{% 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
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
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"),
# 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, })