def user_settings(request): if request.method == "POST": form = UserSettingsForm(request.POST, instance=request.user) if form.is_valid(): form.save(request) messages.success(request, 'Settings saved successfully.') return HttpResponseRedirect(reverse('user_settings')) else: form = UserSettingsForm(instance=request.user) return render_to_response('authenticated/user/user_settings.html', locals(), context_instance=RequestContext(request))
def edit_settings(request): user_settings, created = UserSettings.objects.get_or_create(user=request.user) if request.method == 'POST': form = UserSettingsForm(request.POST, instance=user_settings) if form.is_valid(): form.save() if request.POST.get('welcome', False): redir_url = "/welcome/3" else: redir_url = request.META["HTTP_REFERER"] messages.success(request, 'Settings saved!') return HttpResponseRedirect(redir_url)
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = {'action': 'User actions', 'user': user} if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance=user) if form.is_valid(): form.save() else: context['error'] = 'Invalid form' return scirius_render(request, 'accounts/user.html', context) if action == "activate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = True user.save() elif action == "deactivate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = False user.save() elif action == "edit": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = UserSettingsForm(instance=user) context = {'form': form} return scirius_render(request, 'accounts/user.html', context) elif action == "delete": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if request.GET.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete' } return scirius_render(request, 'accounts/user.html', context) context = {'action': 'User actions', 'user': user} return scirius_render(request, 'accounts/user.html', context)
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = { 'action': 'User actions', 'user': user } if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance = user) if form.is_valid(): form.save() else: context['error'] = 'Invalid form' return scirius_render(request, 'accounts/user.html', context) if action == "activate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = True user.save() elif action == "deactivate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = False user.save() elif action == "edit": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = UserSettingsForm(instance = user) context = {'form': form } return scirius_render(request, 'accounts/user.html', context) elif action == "delete": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if request.GET.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete'} return scirius_render(request, 'accounts/user.html', context) context = { 'action': 'User actions', 'user': user } return scirius_render(request, 'accounts/user.html', context)
def setting(request): settings = UserSettings.getByCurrentUser() im_protocol = settings.im.protocol if settings.im is not None else '' im_address = settings.im.address if settings.im is not None else '' if request.method == 'GET': form = UserSettingsForm({ 'firstname': settings.firstname, 'lastname': settings.lastname, 'gender': settings.gender, 'profile': settings.profile, 'language': settings.language, 'birthdate': settings.birthdate, 'website': settings.website, 'home_phone': settings.home_phone, 'work_phone': settings.work_phone, 'mobile': settings.mobile, 'fax': settings.fax, 'address': settings.address }) if request.method == 'POST': form = UserSettingsForm(request.POST) logging.getLogger().debug(form) if form.is_valid(): modified_settings = form.save(commit=False) settings.lastname = modified_settings.lastname settings.firstname = modified_settings.firstname settings.gender = modified_settings.gender settings.profile = modified_settings.profile settings.language = modified_settings.language settings.birthdate = modified_settings.birthdate settings.website = modified_settings.website settings.home_phone = modified_settings.home_phone settings.work_phone = modified_settings.work_phone settings.mobile = modified_settings.mobile settings.fax = modified_settings.fax settings.address = modified_settings.address if request.POST['im_address'] is not u'': settings.im = db.IM(request.POST['im_protocol'], request.POST['im_address']) settings.put() return HttpResponseRedirect('/') return render_to_response('setting.html', { 'im_protocol': im_protocol, 'im_address': im_address, 'form': form }, context_instance=RequestContext(request))
def setting(request): settings = UserSettings.getByCurrentUser() im_protocol = settings.im.protocol if settings.im is not None else '' im_address = settings.im.address if settings.im is not None else '' if request.method == 'GET': form = UserSettingsForm({'firstname':settings.firstname, 'lastname':settings.lastname, 'gender':settings.gender, 'profile': settings.profile, 'language': settings.language, 'birthdate':settings.birthdate, 'website': settings.website, 'home_phone': settings.home_phone, 'work_phone':settings.work_phone, 'mobile':settings.mobile, 'fax':settings.fax, 'address':settings.address }) if request.method == 'POST': form = UserSettingsForm(request.POST) logging.getLogger().debug(form) if form.is_valid(): modified_settings = form.save(commit=False) settings.lastname = modified_settings.lastname settings.firstname = modified_settings.firstname settings.gender = modified_settings.gender settings.profile = modified_settings.profile settings.language = modified_settings.language settings.birthdate = modified_settings.birthdate settings.website = modified_settings.website settings.home_phone = modified_settings.home_phone settings.work_phone = modified_settings.work_phone settings.mobile = modified_settings.mobile settings.fax = modified_settings.fax settings.address = modified_settings.address if request.POST['im_address'] is not u'': settings.im = db.IM(request.POST['im_protocol'], request.POST['im_address']) settings.put() return HttpResponseRedirect('/') return render_to_response('setting.html', {'im_protocol':im_protocol,'im_address':im_address,'form': form}, context_instance=RequestContext(request))
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = {'action': 'User actions', 'user': user} if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance = user) if form.is_valid(): form.save() try: sciriususer = user.sciriususer sciriususer.timezone = form.cleaned_data['timezone'] except: sciriususer = SciriusUser.objects.create(user = user, timezone = form.cleaned_data['timezone']) sciriususer.save() else: context['error'] = 'Edition form is not valid' context['form'] = form elif action == 'password': form = PasswordForm(request.POST) if form.is_valid(): user.set_password(form.cleaned_data['password']) user.save() if user == request.user: # If the user change his own password prevent the session to be invalidated update_session_auth_hash(request, user) else: context['error'] = 'Password form is not valid' elif action == "delete": form = DeleteForm(request.POST) if form.is_valid(): if request.POST.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context['error'] = 'Delete form is not valid' return scirius_render(request, 'accounts/user.html', context) if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' context['user'] = get_object_or_404(User, pk=request.user.pk) return scirius_render(request, 'accounts/user.html', context) if action == "activate": user.is_active = True user.save() context['current_action'] = 'Activate user %s' % user.username elif action == "deactivate": user.is_active = False user.save() context['current_action'] = 'Deactivate user %s' % user.username elif action == "edit": form = UserSettingsForm(instance = user) try: form.initial['timezone'] = user.sciriususer.timezone except: pass context['form'] = form context['current_action'] = 'Edit user %s' % user.username return scirius_render(request, 'accounts/user.html', context) elif action == "password": form = PasswordForm() context['form'] = form context['current_action'] = 'Edit password for user %s' % user.username return scirius_render(request, 'accounts/user.html', context) elif action == "delete": context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete'} return scirius_render(request, 'accounts/user.html', context) context['current_action'] = 'User %s' % user.username return scirius_render(request, 'accounts/user.html', context)
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = {'action': 'User actions', 'user': user} if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance=user) if form.is_valid(): form.save() try: sciriususer = user.sciriususer sciriususer.timezone = form.cleaned_data['timezone'] except: sciriususer = SciriusUser.objects.create( user=user, timezone=form.cleaned_data['timezone']) sciriususer.save() else: context['error'] = 'Edition form is not valid' context['form'] = form elif action == 'password': form = PasswordForm(request.POST) if form.is_valid(): user.set_password(form.cleaned_data['password']) user.save() if user == request.user: # If the user change his own password prevent the session to be invalidated update_session_auth_hash(request, user) else: context['error'] = 'Password form is not valid' elif action == "delete": form = DeleteForm(request.POST) if form.is_valid(): if request.POST.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context['error'] = 'Delete form is not valid' return scirius_render(request, 'accounts/user.html', context) if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' context['user'] = get_object_or_404(User, pk=request.user.pk) return scirius_render(request, 'accounts/user.html', context) if action == "activate": user.is_active = True user.save() context['current_action'] = 'Activate user %s' % user.username elif action == "deactivate": user.is_active = False user.save() context['current_action'] = 'Deactivate user %s' % user.username elif action == "edit": form = UserSettingsForm(instance=user) try: form.initial['timezone'] = user.sciriususer.timezone except: pass context['form'] = form context['current_action'] = 'Edit user %s' % user.username return scirius_render(request, 'accounts/user.html', context) elif action == "password": form = PasswordForm() context['form'] = form context['current_action'] = 'Edit password for user %s' % user.username return scirius_render(request, 'accounts/user.html', context) elif action == "delete": context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete' } return scirius_render(request, 'accounts/user.html', context) context['current_action'] = 'User %s' % user.username return scirius_render(request, 'accounts/user.html', context)
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = {'action': 'User actions', 'user': user} if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance=user) if form.is_valid(): form.save() try: sciriususer = user.sciriususer sciriususer.timezone = form.cleaned_data['timezone'] except: sciriususer = SciriusUser.objects.create( user=user, timezone=form.cleaned_data['timezone']) sciriususer.save() else: context['error'] = 'Invalid form' elif action == 'password': form = PasswordForm(request.POST) if form.is_valid(): user.set_password(form.cleaned_data['password']) user.save() else: context['error'] = 'Invalid form' elif action == "delete": form = DeleteForm(request.POST) if form.is_valid(): if request.POST.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context['error'] = 'Invalid form' return scirius_render(request, 'accounts/user.html', context) if action == "activate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = True user.save() elif action == "deactivate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = False user.save() elif action == "edit": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = UserSettingsForm(instance=user) try: form.initial['timezone'] = user.sciriususer.timezone except: pass context['form'] = form return scirius_render(request, 'accounts/user.html', context) elif action == "password": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = PasswordForm() context['form'] = form return scirius_render(request, 'accounts/user.html', context) elif action == "delete": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete' } return scirius_render(request, 'accounts/user.html', context) context = {'action': 'User actions', 'user': user} return scirius_render(request, 'accounts/user.html', context)
def manageuseraction(request, user_id, action): user = get_object_or_404(User, pk=user_id) context = { 'action': 'User actions', 'user': user } if request.method == 'POST': if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if action == "edit": form = UserSettingsForm(request.POST, instance = user) if form.is_valid(): form.save() try: sciriususer = user.sciriususer sciriususer.timezone = form.cleaned_data['timezone'] except: sciriususer = SciriusUser.objects.create(user = user, timezone = form.cleaned_data['timezone']) sciriususer.save() else: context['error'] = 'Invalid form' elif action == 'password': form = PasswordForm(request.POST) if form.is_valid(): user.set_password(form.cleaned_data['password']) user.save() else: context['error'] = 'Invalid form' return scirius_render(request, 'accounts/user.html', context) if action == "activate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = True user.save() elif action == "deactivate": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) user.is_active = False user.save() elif action == "edit": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = UserSettingsForm(instance = user) try: form.initial['timezone'] = user.sciriususer.timezone except: pass context['form'] = form return scirius_render(request, 'accounts/user.html', context) elif action == "password": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) form = PasswordForm() context['form'] = form return scirius_render(request, 'accounts/user.html', context) elif action == "delete": if not request.user.is_superuser: context['error'] = 'Unsufficient permissions' return scirius_render(request, 'accounts/user.html', context) if request.GET.__contains__('confirm'): user.delete() return redirect('/accounts/manage/') else: context = { 'confirm_action': 'Delete user', 'user': user, 'action': 'delete'} return scirius_render(request, 'accounts/user.html', context) context = { 'action': 'User actions', 'user': user } return scirius_render(request, 'accounts/user.html', context)