def edit(request): key = ApiKey.objects.get(user=request.user) if request.method == 'POST': form = ProfileForm(request.POST, request=request) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") request.user.email = email request.user.first_name = first_name request.user.last_name = last_name request.user.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: request.user.set_password(password) request.user.save() messages.success(request, _(u"Password updated")) else: form = ProfileForm(initial={ 'username': request.user.username, 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'api_key': key.key }, request=request) return render(request, 'oppia/profile/profile.html', { 'form': form, })
def edit(request): key = ApiKey.objects.get(user = request.user) if request.method == 'POST': form = ProfileForm(request.POST,request=request) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") request.user.email = email request.user.first_name = first_name request.user.last_name = last_name request.user.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: request.user.set_password(password) request.user.save() messages.success(request, _(u"Password updated")) else: form = ProfileForm(initial={'username':request.user.username, 'email':request.user.email, 'first_name':request.user.first_name, 'last_name':request.user.last_name, 'api_key': key.key},request=request) return render(request, 'oppia/profile/profile.html', {'form': form,})
def edit(request, user_id=0): if user_id != 0: if can_edit_user(request, user_id): view_user = User.objects.get(pk=user_id) else: return HttpResponse('Unauthorized', status=401) else: view_user = request.user key = ApiKey.objects.get(user = view_user) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") view_user.email = email view_user.first_name = first_name view_user.last_name = last_name view_user.save() try: user_profile = UserProfile.objects.get(user=view_user) user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get("organisation") user_profile.save() except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = view_user user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get("organisation") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: view_user.set_password(password) view_user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=view_user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm(initial={'username':view_user.username, 'email':view_user.email, 'first_name':view_user.first_name, 'last_name':view_user.last_name, 'api_key': key.key, 'job_title': user_profile.job_title, 'organisation': user_profile.organisation,}) return render_to_response( 'oppia/profile/profile.html', {'form': form,}, context_instance=RequestContext(request))
def edit(request): key = ApiKey.objects.get(user=request.user) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") request.user.email = email request.user.first_name = first_name request.user.last_name = last_name request.user.save() try: user_profile = UserProfile.objects.get(user=request.user) user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get( "organisation") user_profile.save() except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = request.user user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get( "organisation") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: request.user.set_password(password) request.user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=request.user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm( initial={ 'username': request.user.username, 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'api_key': key.key, 'job_title': user_profile.job_title, 'organisation': user_profile.organisation, }) return render(request, 'oppia/profile/profile.html', { 'form': form, })
def edit(request): key = ApiKey.objects.get(user = request.user) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") request.user.email = email request.user.first_name = first_name request.user.last_name = last_name request.user.save() try: user_profile = UserProfile.objects.get(user=request.user) user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get("organisation") user_profile.save() except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = request.user user_profile.job_title = form.cleaned_data.get("job_title") user_profile.organisation = form.cleaned_data.get("organisation") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: request.user.set_password(password) request.user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=request.user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm(initial={'username':request.user.username, 'email':request.user.email, 'first_name':request.user.first_name, 'last_name':request.user.last_name, 'api_key': key.key, 'job_title': user_profile.job_title, 'organisation': user_profile.organisation,}) return render(request, 'oppia/profile/profile.html', {'form': form,})
def edit(request, user_id=0): if user_id != 0: if can_edit_user(request, user_id): view_user = User.objects.get(pk=user_id) else: return HttpResponse('Unauthorized', status=401) else: view_user = request.user key = ApiKey.objects.get(user = view_user) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") view_user.email = email view_user.first_name = first_name view_user.last_name = last_name if form.cleaned_data.get("status")=='Tutor': view_user.is_staff=1 view_user.save() try: user_profile = UserProfile.objects.get(user=view_user) #user_profile.job_title = form.cleaned_data.get("job_title") #user_profile.organisation = form.cleaned_data.get("organisation") user_profile.phone_number = form.cleaned_data.get("phone_number") user_profile.phone_number_two = form.cleaned_data.get("phone_number_two") user_profile.phone_number_three = form.cleaned_data.get("phone_number_three") user_profile.year_group = form.cleaned_data.get("year_group") user_profile.program = form.cleaned_data.get("program") user_profile.gender = form.cleaned_data.get("gender") user_profile.status = form.cleaned_data.get("status") user_profile.home_town = form.cleaned_data.get("home_town") user_profile.school_code = form.cleaned_data.get("school_code") user_profile.save() except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = view_user #user_profile.job_title = form.cleaned_data.get("job_title") #user_profile.organisation = form.cleaned_data.get("organisation") user_profile.phone_number = form.cleaned_data.get("phone_number") user_profile.phone_number_two = form.cleaned_data.get("phone_number_two") user_profile.phone_number_three = form.cleaned_data.get("phone_number_three") user_profile.year_group = form.cleaned_data.get("year_group") user_profile.program = form.cleaned_data.get("program") user_profile.gender = form.cleaned_data.get("gender") user_profile.status = form.cleaned_data.get("status") user_profile.home_town = form.cleaned_data.get("home_town") user_profile.school_code = form.cleaned_data.get("school_code") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: view_user.set_password(password) view_user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=view_user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm(initial={'username':view_user.username, 'email':view_user.email, 'first_name':view_user.first_name, 'last_name':view_user.last_name, 'api_key': key.key, 'job_title': user_profile.job_title, 'organisation': user_profile.organisation, 'phone_number': user_profile.phone_number, 'gender': user_profile.gender, 'phone_number_two': user_profile.phone_number_two, 'phone_number_three': user_profile.phone_number_three, 'year_group': user_profile.year_group, 'program': user_profile.program, 'status': user_profile.status, 'home_town': user_profile.home_town, 'school_code': user_profile.school_code,}) return render_to_response( 'oppia/profile/profile.html', {'form': form,}, context_instance=RequestContext(request))
def edit(request, user_id=0): if user_id != 0: if can_edit_user(request, user_id): view_user = User.objects.get(pk=user_id) else: return HttpResponse('Unauthorized', status=401) else: view_user = request.user key = ApiKey.objects.get(user=view_user) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") view_user.email = email view_user.first_name = first_name view_user.last_name = last_name if form.cleaned_data.get("status") == 'Tutor': view_user.is_staff = 1 view_user.save() try: user_profile = UserProfile.objects.get(user=view_user) #user_profile.job_title = form.cleaned_data.get("job_title") #user_profile.organisation = form.cleaned_data.get("organisation") user_profile.phone_number = form.cleaned_data.get( "phone_number") user_profile.phone_number_two = form.cleaned_data.get( "phone_number_two") user_profile.phone_number_three = form.cleaned_data.get( "phone_number_three") user_profile.year_group = form.cleaned_data.get("year_group") user_profile.program = form.cleaned_data.get("program") user_profile.gender = form.cleaned_data.get("gender") user_profile.status = form.cleaned_data.get("status") user_profile.home_town = form.cleaned_data.get("home_town") user_profile.school_code = form.cleaned_data.get("school_code") user_profile.save() except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = view_user #user_profile.job_title = form.cleaned_data.get("job_title") #user_profile.organisation = form.cleaned_data.get("organisation") user_profile.phone_number = form.cleaned_data.get( "phone_number") user_profile.phone_number_two = form.cleaned_data.get( "phone_number_two") user_profile.phone_number_three = form.cleaned_data.get( "phone_number_three") user_profile.year_group = form.cleaned_data.get("year_group") user_profile.program = form.cleaned_data.get("program") user_profile.gender = form.cleaned_data.get("gender") user_profile.status = form.cleaned_data.get("status") user_profile.home_town = form.cleaned_data.get("home_town") user_profile.school_code = form.cleaned_data.get("school_code") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: view_user.set_password(password) view_user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=view_user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm( initial={ 'username': view_user.username, 'email': view_user.email, 'first_name': view_user.first_name, 'last_name': view_user.last_name, 'api_key': key.key, 'job_title': user_profile.job_title, 'organisation': user_profile.organisation, 'phone_number': user_profile.phone_number, 'gender': user_profile.gender, 'phone_number_two': user_profile.phone_number_two, 'phone_number_three': user_profile.phone_number_three, 'year_group': user_profile.year_group, 'program': user_profile.program, 'status': user_profile.status, 'home_town': user_profile.home_town, 'school_code': user_profile.school_code, }) return render_to_response('oppia/profile/profile.html', { 'form': form, }, context_instance=RequestContext(request))
def edit(request, user_id=0): if user_id != 0: if can_edit_user(request, user_id): view_user = User.objects.get(pk=user_id) else: raise exceptions.PermissionDenied else: view_user = request.user key = ApiKey.objects.get(user=view_user) if request.method == 'POST': form = ProfileForm(request.POST) build_form_options(form) if form.is_valid(): # update basic data email = form.cleaned_data.get("email") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") view_user.email = email view_user.first_name = first_name view_user.last_name = last_name view_user.save() try: user_profile = UserProfile.objects.get(user=view_user) except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = view_user user_profile.sex = form.cleaned_data.get("sex") user_profile.age_range = form.cleaned_data.get("age_range") user_profile.role = form.cleaned_data.get("role") user_profile.location = form.cleaned_data.get("location") user_profile.save() messages.success(request, _(u"Profile updated")) # if password should be changed password = form.cleaned_data.get("password") if password: view_user.set_password(password) view_user.save() messages.success(request, _(u"Password updated")) else: try: user_profile = UserProfile.objects.get(user=view_user) except UserProfile.DoesNotExist: user_profile = UserProfile() form = ProfileForm(initial={'username':view_user.username, 'email':view_user.email, 'first_name':view_user.first_name, 'last_name':view_user.last_name, 'sex': user_profile.sex, 'age_range': user_profile.age_range, 'role': user_profile.role, 'location': user_profile.location, 'api_key': key.key}) build_form_options(form) return render(request, 'oppia/profile/profile.html', {'form': form,})