+@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:\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', 'indefinetly').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
+\r
+ SuspendAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=data)\r
+\r
+ return decorators.RefreshPageCommand()\r
+\r
+\r
+def user_view(template, tab_name, tab_title, tab_description, private=False, tabbed=True, render_to=None, weight=500):\r