Skip to content

Commit

Permalink
apps/djangosaml2_overwrites: fix deprecation of ugettext
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk committed Jun 6, 2024
1 parent 9bae995 commit e6a91a8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
46 changes: 20 additions & 26 deletions apps/djangosaml2_overwrites/forms.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
from allauth.account.models import EmailAddress
from django import forms
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _

from apps.users.models import User


class Djangosaml2SignupForm(forms.ModelForm):
terms_of_use = forms.BooleanField(
label=_('Terms of use')
)
data_protection = forms.BooleanField(
label=_('Data protection')
)
terms_of_use = forms.BooleanField(label=_("Terms of use"))
data_protection = forms.BooleanField(label=_("Data protection"))
get_notifications = forms.BooleanField(
label=pgettext_lazy(
'diid',
'Notifications: Yes, I would like to be notified by e-mail about '
'the beginning and end of participation opportunities and about '
'comments on my contributions by other users. This applies to all '
'projects I follow.'
"diid",
"Notifications: Yes, I would like to be notified by e-mail about "
"the beginning and end of participation opportunities and about "
"comments on my contributions by other users. This applies to all "
"projects I follow.",
),
required=False
required=False,
)
get_newsletters = forms.BooleanField(
label=pgettext_lazy(
'diid',
'Newsletter: Yes, I would like to receive e-mail newsletters '
'about the projects I follow.'
"diid",
"Newsletter: Yes, I would like to receive e-mail newsletters "
"about the projects I follow.",
),
required=False
required=False,
)

class Meta:
model = User
fields = [
'username',
'get_notifications',
'get_newsletters'
]
fields = ["username", "get_notifications", "get_newsletters"]

def clean_username(self):
username = self.cleaned_data['username']
username = self.cleaned_data["username"]
try:
user = User.objects.get(username__iexact=username)
if user != self.instance:
raise forms.ValidationError(
User._meta.get_field('username').error_messages['unique'])
User._meta.get_field("username").error_messages["unique"]
)
except User.DoesNotExist:
pass
return username

def save(self):
email_address = EmailAddress.objects.get(user=self.instance,
email=self.instance.email)
email_address = EmailAddress.objects.get(
user=self.instance, email=self.instance.email
)
email_address.verified = True
email_address.save()
super().save()
22 changes: 13 additions & 9 deletions apps/djangosaml2_overwrites/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views import generic
from djangosaml2.utils import validate_referral_url

Expand All @@ -11,14 +11,14 @@
from . import forms


class Djangosaml2SignupView(LoginRequiredMixin,
SuccessMessageMixin,
generic.UpdateView):
class Djangosaml2SignupView(
LoginRequiredMixin, SuccessMessageMixin, generic.UpdateView
):

model = User
template_name = 'djangosaml2_overwrites/signup.html'
template_name = "djangosaml2_overwrites/signup.html"
form_class = forms.Djangosaml2SignupForm
success_message = _('Your profile was successfully updated.')
success_message = _("Your profile was successfully updated.")

def get_object(self):
return get_object_or_404(User, pk=self.request.user.id)
Expand All @@ -33,7 +33,11 @@ def get_context_data(self, **kwargs):
ret = super().get_context_data(**kwargs)
redirect_field_value = self.request.GET.get("next")
site = get_current_site(self.request)
ret.update({"site": site,
"redirect_field_name": "next",
"redirect_field_value": redirect_field_value})
ret.update(
{
"site": site,
"redirect_field_name": "next",
"redirect_field_value": redirect_field_value,
}
)
return ret

0 comments on commit e6a91a8

Please sign in to comment.