+ 'user': user,\r
+ 'form' : form,\r
+ 'gravatar_faq_url' : reverse('faq') + '#gravatar',\r
+ }, context_instance=RequestContext(request))\r
+\r
+\r
+@decorate.withfn(decorators.command)\r
+def user_powers(request, id, action, status):\r
+ if not request.user.is_superuser:\r
+ raise decorators.CommandException(_("Only superusers are allowed to alter other users permissions."))\r
+\r
+ if (action == 'remove' and 'status' == 'super') and not request.user.is_siteowner():\r
+ raise decorators.CommandException(_("Only the site owner can remove the super user status from other user."))\r
+\r
+ user = get_object_or_404(User, id=id)\r
+ new_state = action == 'grant'\r
+\r
+ if status == 'super':\r
+ user.is_superuser = new_state\r
+ elif status == 'staff':\r
+ user.is_staff = new_state\r
+ else:\r
+ raise Http404()\r
+\r
+ user.save()\r
+ return decorators.RefreshPageCommand()\r
+\r
+\r
+@decorate.withfn(decorators.command)\r
+def award_points(request, id):\r
+ if not request.POST:\r
+ return render_to_response('users/karma_bonus.html')\r
+\r
+ if not request.user.is_superuser:\r
+ raise decorators.CommandException(_("Only superusers are allowed to award reputation points"))\r
+\r
+ try:\r
+ points = int(request.POST['points'])\r
+ except:\r
+ raise decorators.CommandException(_("Invalid number of points to award."))\r
+\r
+ user = get_object_or_404(User, id=id)\r
+\r
+ extra = dict(message=request.POST.get('message', ''), awarding_user=request.user.id, value=points)\r
+\r
+ BonusRepAction(user=request.user, extra=extra).save(data=dict(value=points, affected=user))\r
+\r
+ return {'commands': {\r
+ 'update_profile_karma': [user.reputation]\r
+ }}\r
+ \r
+\r
+@decorate.withfn(decorators.command)\r
+def suspend(request, id):\r
+ user = get_object_or_404(User, id=id)\r
+\r
+ if not request.user.is_superuser:\r
+ raise decorators.CommandException(_("Only superusers can suspend other users"))\r
+\r
+ if not request.POST.get('bantype', None):\r
+ if user.is_suspended():\r
+ suspension = user.suspension\r
+ suspension.cancel(user=request.user, ip=request.META['REMOTE_ADDR'])\r
+ return decorators.RefreshPageCommand()\r
+ else:\r
+ return render_to_response('users/suspend_user.html')\r
+\r
+ data = {\r
+ 'bantype': request.POST.get('bantype', 'Indefinitely').strip(),\r
+ 'publicmsg': request.POST.get('publicmsg', _('Bad behaviour')),\r
+ 'privatemsg': request.POST.get('privatemsg', None) or request.POST.get('publicmsg', ''),\r
+ 'suspended': user\r
+ }\r
+\r
+ if data['bantype'] == 'forxdays':\r
+ try:\r
+ data['forxdays'] = int(request.POST['forxdays'])\r
+ except:\r
+ raise decorators.CommandException(_('Invalid numeric argument for the number of days.'))\r