def profile(request): if request.method == 'POST': form = ProfileForm(request.POST, instance = request.user.get_profile()) subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_profile()) userform = UserForm(request.POST, instance = request.user) if form.is_valid() and userform.is_valid() and subscriptionform.is_valid(): form.save() subscriptionform.save() userform.save() set_lang(request.user, request = request, user = request.user) # Need to redirect to allow language change response = HttpResponseRedirect('/accounts/profile/') response.set_cookie(settings.LANGUAGE_COOKIE_NAME, request.user.get_profile().language) return response else: form = ProfileForm(instance = request.user.get_profile()) subscriptionform = SubscriptionForm(instance = request.user.get_profile()) userform = UserForm(instance = request.user) response = render_to_response('profile.html', RequestContext(request, { 'form': form, 'userform': userform, 'subscriptionform': subscriptionform, 'title': _('User profile'), })) response.set_cookie(settings.LANGUAGE_COOKIE_NAME, request.user.get_profile().language) return response
def profile(request): user_profile = request.user.get_profile() if request.method == "POST": # Read params form = ProfileForm(request.POST, instance=user_profile) subscriptionform = SubscriptionForm(request.POST, instance=user_profile) userform = UserForm(request.POST, instance=request.user) if form.is_valid() and userform.is_valid() and subscriptionform.is_valid(): # Save changes form.save() subscriptionform.save() userform.save() # Change language set_lang(request.user, request=request, user=request.user) # Redirect after saving (and possibly changing language) response = HttpResponseRedirect(reverse("profile")) # Set language cookie and activate new language (for message below) lang_code = user_profile.language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.info(request, _("Your profile has been updated.")) return response else: form = ProfileForm(instance=user_profile) subscriptionform = SubscriptionForm(instance=user_profile) userform = UserForm(instance=request.user) response = render_to_response( "profile.html", RequestContext( request, { "form": form, "userform": userform, "subscriptionform": subscriptionform, "profile": user_profile, "title": _("User profile"), }, ), ) response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_profile.language) return response
def profile(request): if request.method == 'POST': # Read params form = ProfileForm(request.POST, instance = request.user.get_profile()) subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_profile()) userform = UserForm(request.POST, instance = request.user) if form.is_valid() and userform.is_valid() and subscriptionform.is_valid(): # Save changes form.save() subscriptionform.save() userform.save() # Change language set_lang(request.user, request = request, user = request.user) # Redirect after saving (and possibly changing language) response = HttpResponseRedirect('/accounts/profile/') # Set language cookie and activate new language (for message bellow) lang_code = request.user.get_profile().language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.info(request, _('Your profile has been updated.')) return response else: form = ProfileForm(instance = request.user.get_profile()) subscriptionform = SubscriptionForm(instance = request.user.get_profile()) userform = UserForm(instance = request.user) profile = request.user.get_profile() response = render_to_response('profile.html', RequestContext(request, { 'form': form, 'userform': userform, 'subscriptionform': subscriptionform, 'profile': profile, 'title': _('User profile'), })) response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language) return response
def profile(request): if request.method == 'POST': # Read params form = ProfileForm(request.POST, instance = request.user.get_profile()) subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_profile()) userform = UserForm(request.POST, instance = request.user) if form.is_valid() and userform.is_valid() and subscriptionform.is_valid(): # Save changes form.save() subscriptionform.save() userform.save() # Change language set_lang(request.user, request = request, user = request.user) # Redirect after saving (and possibly changing language) response = HttpResponseRedirect('/accounts/profile/') # Set language cookie and activate new language (for message below) lang_code = request.user.get_profile().language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.info(request, _('Your profile has been updated.')) return response else: form = ProfileForm(instance = request.user.get_profile()) subscriptionform = SubscriptionForm(instance = request.user.get_profile()) userform = UserForm(instance = request.user) profile = request.user.get_profile() response = render_to_response('profile.html', RequestContext(request, { 'form': form, 'userform': userform, 'subscriptionform': subscriptionform, 'profile': profile, 'title': _('User profile'), })) response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language) return response
def user_profile(request): profile = request.user.profile form_classes = [ ProfileForm, SubscriptionForm, SubscriptionSettingsForm, ] if request.method == 'POST': # Parse POST params forms = [form(request.POST, instance=profile) for form in form_classes] forms.append(UserForm(request.POST, instance=request.user)) if appsettings.DEMO_SERVER and request.user.username == 'demo': return deny_demo(request) if min([form.is_valid() for form in forms]): # Save changes for form in forms: form.save() # Change language set_lang(request, request.user.profile) # Redirect after saving (and possibly changing language) response = redirect('profile') # Set language cookie and activate new language (for message below) lang_code = profile.language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.success(request, _('Your profile has been updated.')) return response else: forms = [form(instance=profile) for form in form_classes] forms.append(UserForm(instance=request.user)) social = request.user.social_auth.all() social_names = [assoc.provider for assoc in social] all_backends = set(load_backends(BACKENDS).keys()) new_backends = [ x for x in all_backends if x == 'email' or x not in social_names ] license_projects = SubProject.objects.filter( project__in=Project.objects.all_acl(request.user) ).exclude( license='' ) response = render( request, 'accounts/profile.html', { 'form': forms[0], 'subscriptionform': forms[1], 'subscriptionsettingsform': forms[2], 'userform': forms[3], 'profile': profile, 'title': _('User profile'), 'licenses': license_projects, 'associated': social, 'new_backends': new_backends, } ) response.set_cookie( settings.LANGUAGE_COOKIE_NAME, profile.language ) return response
def user_profile(request): profile = request.user.profile if not request.user.is_demo and not profile.language: profile.language = get_language() profile.save(update_fields=['language']) form_classes = [ ProfileForm, SubscriptionForm, SubscriptionSettingsForm, UserSettingsForm, DashboardSettingsForm, ] all_backends = set(load_backends(social_django.utils.BACKENDS).keys()) if request.method == 'POST': # Parse POST params forms = [form(request.POST, instance=profile) for form in form_classes] forms.append(UserForm(request.POST, instance=request.user)) if request.user.is_demo: return deny_demo(request) if all(form.is_valid() for form in forms): # Save changes for form in forms: form.save() # Change language set_lang(request, request.user.profile) # Redirect after saving (and possibly changing language) response = redirect_profile(request.POST.get('activetab')) # Set language cookie and activate new language (for message below) lang_code = profile.language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.success(request, _('Your profile has been updated.')) return response else: forms = [form(instance=profile) for form in form_classes] forms.append(UserForm(instance=request.user)) if not request.user.has_usable_password() and 'email' in all_backends: messages.warning( request, render_to_string('accounts/password-warning.html')) social = request.user.social_auth.all() social_names = [assoc.provider for assoc in social] new_backends = [ x for x in all_backends if x == 'email' or x not in social_names ] license_projects = Component.objects.filter( project__in=request.user.allowed_projects).exclude(license='') result = render( request, 'accounts/profile.html', { 'languagesform': forms[0], 'subscriptionform': forms[1], 'subscriptionsettingsform': forms[2], 'usersettingsform': forms[3], 'dashboardsettingsform': forms[4], 'userform': forms[5], 'profile': profile, 'title': _('User profile'), 'licenses': license_projects, 'associated': social, 'new_backends': new_backends, 'managed_projects': request.user.owned_projects, 'auditlog': request.user.auditlog_set.all()[:20], }) result.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language) return result
def user_profile(request): profile = request.user.profile if request.method == 'POST': # Read params form = ProfileForm( request.POST, instance=profile ) subscriptionform = SubscriptionForm( request.POST, instance=profile ) userform = UserForm( request.POST, instance=request.user ) if appsettings.DEMO_SERVER and request.user.username == 'demo': messages.warning( request, _('You can not change demo profile on the demo server.') ) return redirect('profile') if (form.is_valid() and userform.is_valid() and subscriptionform.is_valid()): # Save changes form.save() subscriptionform.save() userform.save() # Change language set_lang(request.user, request=request, user=request.user) # Redirect after saving (and possibly changing language) response = redirect('profile') # Set language cookie and activate new language (for message below) lang_code = profile.language response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) translation.activate(lang_code) messages.info(request, _('Your profile has been updated.')) return response else: form = ProfileForm( instance=profile ) subscriptionform = SubscriptionForm( instance=profile ) userform = UserForm( instance=request.user ) social = request.user.social_auth.all() social_names = [assoc.provider for assoc in social] all_backends = set(load_backends(BACKENDS).keys()) new_backends = [ x for x in all_backends if x == 'email' or x not in social_names ] license_projects = Project.objects.all_acl( request.user ).exclude( license='' ) response = render( request, 'accounts/profile.html', { 'form': form, 'userform': userform, 'subscriptionform': subscriptionform, 'profile': profile, 'title': _('User profile'), 'licenses': license_projects, 'associated': social, 'new_backends': new_backends, } ) response.set_cookie( settings.LANGUAGE_COOKIE_NAME, profile.language ) return response