def register(self, form): RegistrationView.SEND_ACTIVATION_EMAIL = not preferences.SitePreferences.disable_mail_verification user = super(RegistrationView, self).register(form) profile, _ = Profile.objects.get_or_create(user=user, defaults={ 'language': Language.get_python3(), }) if preferences.SitePreferences.disable_mail_verification: user.is_active = True user.save() cleaned_data = form.cleaned_data profile.timezone = cleaned_data['timezone'] profile.language = cleaned_data['language'] profile.save() if newsletter_id is not None and cleaned_data['newsletter']: Subscription(user=user, newsletter_id=newsletter_id, subscribed=True).save() return user
def edit_profile(request): profile = Profile.objects.get(user=request.user) if profile.mute: raise Http404() if request.method == 'POST': form = ProfileForm(request.POST, instance=profile, user=request.user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(request.user) revisions.set_comment(_('Updated on site')) if newsletter_id is not None: try: subscription = Subscription.objects.get( user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: if form.cleaned_data['newsletter']: Subscription(user=request.user, newsletter_id=newsletter_id, subscribed=True).save() else: if subscription.subscribed != form.cleaned_data[ 'newsletter']: subscription.update( ('unsubscribe', 'subscribe')[form.cleaned_data['newsletter']]) return HttpResponseRedirect(request.path) else: form = ProfileForm(instance=profile, user=request.user) if newsletter_id is not None: try: subscription = Subscription.objects.get( user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: form.fields['newsletter'].initial = False else: form.fields['newsletter'].initial = subscription.subscribed tzmap = getattr(settings, 'TIMEZONE_MAP', None) return render( request, 'user/edit_profile.jade', { 'form': form, 'title': _('Edit profile'), 'TIMEZONE_MAP': tzmap or 'http://momentjs.com/static/img/world.png', 'TIMEZONE_BG': getattr(settings, 'TIMEZONE_BG', None if tzmap else '#4E7CAD'), })
def edit_profile(request): if request.profile.mute: raise Http404() if request.method == 'POST': form = ProfileForm(request.POST, instance=request.profile, user=request.user) if form.is_valid(): with revisions.create_revision(atomic=True): form.save() revisions.set_user(request.user) revisions.set_comment(_('Updated on site')) if newsletter_id is not None: try: subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: if form.cleaned_data['newsletter']: Subscription(user=request.user, newsletter_id=newsletter_id, subscribed=True).save() else: if subscription.subscribed != form.cleaned_data['newsletter']: subscription.update(('unsubscribe', 'subscribe')[form.cleaned_data['newsletter']]) perm = Permission.objects.get(codename='test_site', content_type=ContentType.objects.get_for_model(Profile)) if form.cleaned_data['test_site']: request.user.user_permissions.add(perm) else: request.user.user_permissions.remove(perm) return HttpResponseRedirect(request.path) else: form = ProfileForm(instance=request.profile, user=request.user) if newsletter_id is not None: try: subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: form.fields['newsletter'].initial = False else: form.fields['newsletter'].initial = subscription.subscribed form.fields['test_site'].initial = request.user.has_perm('judge.test_site') tzmap = settings.TIMEZONE_MAP return render(request, 'user/edit-profile.html', { 'require_staff_2fa': settings.DMOJ_REQUIRE_STAFF_2FA, 'form': form, 'title': _('Edit profile'), 'profile': request.profile, 'can_download_data': bool(settings.DMOJ_USER_DATA_DOWNLOAD), 'has_math_config': bool(settings.MATHOID_URL), 'ignore_user_script': True, 'TIMEZONE_MAP': tzmap or 'http://momentjs.com/static/img/world.png', 'TIMEZONE_BG': settings.TIMEZONE_BG if tzmap else '#4E7CAD', })
def register(self, form): user = super(RegistrationView, self).register(form) profile, _ = Profile.objects.get_or_create(user=user, defaults={ 'language': Language.get_default_language(), }) cleaned_data = form.cleaned_data profile.timezone = cleaned_data['timezone'] profile.language = cleaned_data['language'] profile.organizations.add(*cleaned_data['organizations']) profile.save() if newsletter_id is not None and cleaned_data['newsletter']: Subscription(user=user, newsletter_id=newsletter_id, subscribed=True).save() return user
def save(self, request): user = super(MySignupForm, self).save(request) profile, _ = Profile.objects.get_or_create( user=user, defaults={'language': Language.get_python2()}) profile.name = self.cleaned_data.get('display_name') profile.timezone = self.cleaned_data.get('timezone') profile.language = self.cleaned_data.get('language') profile.organizations.add(*self.cleaned_data.get('organizations')) profile.save() if newsletter_id is not None and self.cleaned_data.get('newsletter'): Subscription(user=user, newsletter_id=newsletter_id, subscribed=True).save() return user
def edit_profile(request): profile = Profile.objects.get(user=request.user) if profile.mute: raise Http404() if request.method == 'POST': form = ProfileForm(request.POST, instance=profile, user=request.user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(request.user) revisions.set_comment(_('Updated on site')) if newsletter_id is not None: try: subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: if form.cleaned_data['newsletter']: Subscription(user=request.user, newsletter_id=newsletter_id, subscribed=True).save() else: if subscription.subscribed != form.cleaned_data['newsletter']: subscription.update(('unsubscribe', 'subscribe')[form.cleaned_data['newsletter']]) perm = Permission.objects.get(codename='test_site', content_type=ContentType.objects.get_for_model(Profile)) if form.cleaned_data['test_site']: request.user.user_permissions.add(perm) else: request.user.user_permissions.remove(perm) return HttpResponseRedirect(request.path) else: form = ProfileForm(instance=profile, user=request.user) if newsletter_id is not None: try: subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id) except Subscription.DoesNotExist: form.fields['newsletter'].initial = False else: form.fields['newsletter'].initial = subscription.subscribed form.fields['test_site'].initial = request.user.has_perm('judge.test_site') tzmap = getattr(settings, 'TIMEZONE_MAP', None) return render(request, 'user/edit-profile.html', { 'form': form, 'title': _('Edit profile'), 'profile': profile, 'has_math_config': bool(getattr(settings, 'MATHOID_URL', False)), 'TIMEZONE_MAP': tzmap or 'http://momentjs.com/static/img/world.png', 'TIMEZONE_BG': getattr(settings, 'TIMEZONE_BG', None if tzmap else '#4E7CAD'), })