def user_detail(request, user_id): edit_user = get_object_or_404(models.User, id=user_id) context = RequestContext(request) profile_form = forms.UserProfileForm(instance=edit_user) if request.method == 'POST': if 'submit_enable' in request.POST: if edit_user.is_active: messages.error(request, 'User is already enabled.') else: edit_user.is_active = True edit_user.save() messages.success(request, 'User %s was enabled.' % edit_user.username) elif 'submit_disable' in request.POST: if edit_user.is_guest(): messages.error(request, 'Cannot disable the guest user.') elif not edit_user.is_active: messages.error(request, 'User is already disabled.') else: edit_user.is_active = False edit_user.save() messages.success(request, 'User %s was disabled.' % edit_user.username) elif 'submit_add_staff' in request.POST: if edit_user.is_staff: messages.error(request, 'User is already staff.') else: edit_user.is_staff = True edit_user.save() messages.success(request, 'User %s staff status enabled.' % edit_user.username) elif 'submit_remove_staff' in request.POST: if edit_user.is_guest(): messages.error(request, 'Cannot change staff status on the guest user.') elif not edit_user.is_staff: messages.error(request, 'User is not currently staff.') else: edit_user.is_staff = False edit_user.save() messages.success(request, 'User %s staff status disabled.' % edit_user.username) elif 'submit_update_profile' in request.POST: profile_form = forms.UserProfileForm(request.POST, request.FILES, instance=edit_user) if profile_form.is_valid(): profile_form.save() messages.success(request, 'User %s e-profile updated' % edit_user.username) else: messages.error(request, 'Unknown form submitted.') context['profile_form'] = profile_form context['edit_user'] = edit_user context['tokens'] = edit_user.tokens.all().order_by('created_time') return render_to_response('kegadmin/user_detail.html', context_instance=context)
def user_detail(request, user_id): edit_user = get_object_or_404(models.User, id=user_id) context = {} profile_form = forms.UserProfileForm(instance=edit_user) if request.method == "POST": if "submit_enable" in request.POST: if edit_user.is_active: messages.error(request, "User is already enabled.") else: edit_user.is_active = True edit_user.save() messages.success(request, "User %s was enabled." % edit_user.username) elif "submit_disable" in request.POST: if edit_user.is_guest(): messages.error(request, "Cannot disable the guest user.") elif not edit_user.is_active: messages.error(request, "User is already disabled.") else: edit_user.is_active = False edit_user.save() messages.success(request, "User %s was disabled." % edit_user.username) elif "submit_add_staff" in request.POST: if edit_user.is_staff: messages.error(request, "User is already staff.") else: edit_user.is_staff = True edit_user.save() messages.success( request, "User %s staff status enabled." % edit_user.username) elif "submit_remove_staff" in request.POST: if edit_user.is_guest(): messages.error( request, "Cannot change staff status on the guest user.") elif not edit_user.is_staff: messages.error(request, "User is not currently staff.") else: edit_user.is_staff = False edit_user.save() messages.success( request, "User %s staff status disabled." % edit_user.username) elif "submit_update_profile" in request.POST: profile_form = forms.UserProfileForm(request.POST, request.FILES, instance=edit_user) if profile_form.is_valid(): profile_form.save() messages.success( request, "User %s e-profile updated" % edit_user.username) else: messages.error(request, "Unknown form submitted.") context["profile_form"] = profile_form context["edit_user"] = edit_user context["tokens"] = edit_user.tokens.all().order_by("created_time") return render(request, "kegadmin/user_detail.html", context=context)