Enforce coding style

This commit is contained in:
Rodolphe Breard 2018-11-08 20:11:14 +01:00
parent e1719f4773
commit 428bd941e2
5 changed files with 43 additions and 11 deletions

View file

@ -102,7 +102,8 @@ class EntriesView(generic.ListView):
if source is None:
return []
nb_max = settings.KHAGANAT_LOGS_MAX_DAYS - settings.KHAGANAT_LOGS_MIN_DAYS
nb_max = settings.KHAGANAT_LOGS_MAX_DAYS
nb_max -= settings.KHAGANAT_LOGS_MIN_DAYS
lst = Entry.objects.filter(
source=source,
)

View file

@ -12,10 +12,20 @@ class RegistrationForm(UserCreationForm):
model = NelUser
fields = (NelUser.EMAIL_FIELD,)
class ChangePasswordForm(forms.Form):
current_password = forms.CharField(label=_('current_password'), widget=forms.PasswordInput)
new_password = forms.CharField(label=_('new_password'), widget=forms.PasswordInput)
new_password_confirm = forms.CharField(label=_('new_password_confirm'), widget=forms.PasswordInput)
current_password = forms.CharField(
label=_('current_password'),
widget=forms.PasswordInput
)
new_password = forms.CharField(
label=_('new_password'),
widget=forms.PasswordInput
)
new_password_confirm = forms.CharField(
label=_('new_password_confirm'),
widget=forms.PasswordInput
)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
@ -28,17 +38,22 @@ class ChangePasswordForm(forms.Form):
new_pass_confirm = cleaned_data.get('new_password_confirm')
user = self.request.user
if new_pass != new_pass_confirm:
raise forms.ValidationError(_('The new password does not match its confirmation.'))
msg = _('The new password does not match its confirmation.')
raise forms.ValidationError(msg)
try:
validate_password(new_pass, user=user)
except ValidationError as error:
raise forms.ValidationError(error)
if not user.check_password(old_pass):
raise forms.ValidationError(_('The current password is incorrect.'))
msg = _('The current password is incorrect.')
raise forms.ValidationError(msg)
class DeleteAccountForm(forms.Form):
current_password = forms.CharField(label=_('current_password'), widget=forms.PasswordInput)
current_password = forms.CharField(
label=_('current_password'),
widget=forms.PasswordInput
)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
@ -49,4 +64,5 @@ class DeleteAccountForm(forms.Form):
password = cleaned_data.get('current_password')
user = self.request.user
if not user.check_password(password):
raise forms.ValidationError(_('The current password is incorrect.'))
msg = _('The current password is incorrect.')
raise forms.ValidationError(msg)

View file

@ -59,6 +59,14 @@ urlpatterns = [
path('settings/', views.settings_default, name='settings'),
# Security
path('settings/security/password/', views.ChangePasswordView.as_view(), name='password_change'),
path('settings/security/delete_account/', views.DeleteAccountView.as_view(), name='delete_account'),
path(
'settings/security/password/',
views.ChangePasswordView.as_view(),
name='password_change'
),
path(
'settings/security/delete_account/',
views.DeleteAccountView.as_view(),
name='delete_account'
),
]

View file

@ -73,7 +73,12 @@ def warn_msg(request, next_url=None):
'next_url': next_url,
'is_authenticated': request.user.is_authenticated,
}
return render_to_string(request, 'nsfw/redirect_page.html', context=context)
ret = render_to_string(
request,
'nsfw/redirect_page.html',
context=context
)
return ret
def redirect(request):
@ -83,6 +88,7 @@ def redirect(request):
)
return HttpResponseRedirect(dest)
def alert(request, next_url=None):
context = {
'next_url': next_url,

View file

@ -4,6 +4,7 @@ from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def get_page(context, slug):
request = context['request']