def edit_user(request): if request.method == 'GET': profile = request.user.get_profile() if profile.mobile_phone == 'Not Assigned': profile.mobile_phone = '' form = EditUserProfileForm( data=dict(title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, mobile_phone=profile.mobile_phone)) return render_to_response( "accountmanagement/profile/edit_profile.html", {'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = EditUserProfileForm(request.POST) message = "" if form.is_valid(): _update_user_and_profile(request, form) message = _('Profile has been updated successfully') return render_to_response( "accountmanagement/profile/edit_profile.html", { 'form': form, 'message': message }, context_instance=RequestContext(request))
def edit_user(request): if request.method == 'GET': profile = request.user.get_profile() form = EditUserProfileForm( data=dict(title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, office_phone=profile.office_phone, mobile_phone=profile.mobile_phone, skype=profile.skype)) return render_to_response( "accountmanagement/profile/edit_profile.html", {'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = EditUserProfileForm(request.POST) message = "" if form.is_valid(): user = User.objects.get(username=request.user.username) user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.save() ngo_user_profile = NGOUserProfile.objects.get(user=user) ngo_user_profile.title = form.cleaned_data['title'] ngo_user_profile.office_phone = form.cleaned_data['office_phone'] ngo_user_profile.mobile_phone = form.cleaned_data['mobile_phone'] ngo_user_profile.skype = form.cleaned_data['skype'] ngo_user_profile.save() message = 'Profile has been updated successfully' return render_to_response( "accountmanagement/profile/edit_profile.html", { 'form': form, 'message': message }, context_instance=RequestContext(request))
def upgrade(request, token=None): profile = request.user.get_profile() organization = get_organization(request) if request.method == 'GET': form = UpgradeForm() organization_form = OrganizationForm(instance=organization) profile_form = EditUserProfileForm( data=dict(title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, mobile_phone=profile.mobile_phone)) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request)) if request.method == 'POST': form = UpgradeForm(request.POST) organization = Organization.objects.get(org_id=request.POST["org_id"]) organization_form = OrganizationForm(request.POST, instance=organization).update() profile_form = EditUserProfileForm(request.POST) if form.is_valid() and organization_form.is_valid( ) and profile_form.is_valid(): organization.save() invoice_period = form.cleaned_data['invoice_period'] preferred_payment = form.cleaned_data['preferred_payment'] payment_details = PaymentDetails.objects.model( organization=organization, invoice_period=invoice_period, preferred_payment=preferred_payment) payment_details.save() message_tracker = MessageTracker(organization=organization, month=datetime.datetime.today()) message_tracker.save() DataSenderOnTrialAccount.objects.filter( organization=organization).delete() _send_upgrade_email(request.user, request.LANGUAGE_CODE) _update_user_and_profile(request, profile_form) messages.success(request, _("upgrade success message")) if token: request.user.backend = 'django.contrib.auth.backends.ModelBackend' sign_in(request, request.user) Token.objects.get(pk=token).delete() return HttpResponseRedirect(django_settings.LOGIN_REDIRECT_URL) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request))
def edit_user(request): if request.method == 'GET': profile = request.user.get_profile() if profile.mobile_phone == 'Not Assigned': profile.mobile_phone = '' org = get_organization(request) form = EditUserProfileForm(organization=org, reporter_id=profile.reporter_id, data=dict( title=profile.title, full_name=profile.user.first_name, username=profile.user.username, mobile_phone=profile.mobile_phone)) return render_to_response( "accountmanagement/profile/edit_profile.html", { 'form': form, 'is_pro_sms': org.is_pro_sms }, context_instance=RequestContext(request)) if request.method == 'POST': post_parameter = request.POST.copy() post_parameter['role'] = request.user.groups.all()[0].name profile = request.user.get_profile() org = get_organization(request) form = EditUserProfileForm(organization=org, reporter_id=profile.reporter_id, data=post_parameter) message = "" if form.is_valid(): _update_user_and_profile(form, request.user.username) message = _('Profile has been updated successfully') return render_to_response( "accountmanagement/profile/edit_profile.html", { 'form': form, 'message': message, 'is_pro_sms': org.is_pro_sms }, context_instance=RequestContext(request))
def edit_user(request): if request.method == "GET": profile = request.user.get_profile() form = EditUserProfileForm( data=dict( title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, office_phone=profile.office_phone, mobile_phone=profile.mobile_phone, skype=profile.skype, ) ) return render_to_response( "accountmanagement/profile/edit_profile.html", {"form": form}, context_instance=RequestContext(request) ) if request.method == "POST": form = EditUserProfileForm(request.POST) message = "" if form.is_valid(): user = User.objects.get(username=request.user.username) user.first_name = form.cleaned_data["first_name"] user.last_name = form.cleaned_data["last_name"] user.save() ngo_user_profile = NGOUserProfile.objects.get(user=user) ngo_user_profile.title = form.cleaned_data["title"] ngo_user_profile.office_phone = form.cleaned_data["office_phone"] ngo_user_profile.mobile_phone = form.cleaned_data["mobile_phone"] ngo_user_profile.skype = form.cleaned_data["skype"] ngo_user_profile.save() message = "Profile has been updated successfully" return render_to_response( "accountmanagement/profile/edit_profile.html", {"form": form, "message": message}, context_instance=RequestContext(request), )
def edit_user_profile(request, user_id=None): user = User.objects.get(id=user_id) current_user = request.user if user is None: data = {"errors": "User not found"} return HttpResponse(json.dumps(data), mimetype="application/json", status=404) if not current_user.has_higher_privileges_than(user): return HttpResponseRedirect(django_settings.ACCESS_DENIED_PAGE) else: profile = user.get_profile() if request.method == 'GET': if profile.mobile_phone == 'Not Assigned': profile.mobile_phone = '' org = get_organization(request) manager = get_database_manager(user) questionnaire_list = get_questionnaires_for_user(user.id, manager) questionnaire_map = make_questionnaire_map(questionnaire_list) form_data = dict(title=profile.title, id=user_id, full_name=profile.user.first_name, username=profile.user.username, mobile_phone=profile.mobile_phone, role=user.groups.all()[0].name, questionnaires=questionnaire_map) return render_to_response("accountmanagement/account/edit_user.html", { 'form_data': json.dumps(form_data), 'is_pro_sms': org.is_pro_sms, 'current_lang': get_language() }, context_instance=(RequestContext(request))) if request.method == 'POST': post_parameters = request.POST role = post_parameters['role'] ngo_user = NGOUserProfile.objects.get(user=user) manager = get_database_manager(user) reporter_id = ngo_user.reporter_id previous_role = user.groups.all()[0].name org = get_organization(request) form = EditUserProfileForm(organization=org, reporter_id=profile.reporter_id, data=request.POST) message = "" _edit_user_success = False if form.is_valid(): _update_user_and_profile(form, user.username, role) name = post_parameters["full_name"] if role == 'Project Managers': selected_questionnaires = post_parameters.getlist( 'selected_questionnaires[]') selected_questionnaire_names = post_parameters.getlist( 'selected_questionnaire_names[]') if selected_questionnaires is None or len( selected_questionnaires) < 1: selected_questionnaires = [] dissociate_user_as_datasender_with_projects( reporter_id, user, previous_role, selected_questionnaires) make_user_data_sender_for_projects(manager, selected_questionnaires, reporter_id) update_user_permission(manager, user_id=user.id, project_ids=selected_questionnaires) UserActivityLog().log(request, action=UPDATED_USER, detail=activity_log_detail( name, friendly_name(role), selected_questionnaire_names)) elif role == 'Extended Users': if previous_role != 'Extended Users': associate_user_with_all_projects_of_organisation( manager, reporter_id) update_user_permission(manager, user_id=user.id, project_ids=[]) UserActivityLog().log(request, action=UPDATED_USER, detail=activity_log_detail( name, friendly_name(role))) message = _('Profile has been updated successfully') _edit_user_success = True data = dict(edit_user_success=_edit_user_success, errors=form.errors, message=message) return HttpResponse(json.dumps(data), mimetype="application/json", status=200)