Skip to content

Instantly share code, notes, and snippets.

@cjadeveloper
Created October 17, 2018 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjadeveloper/ff5fcf3d828d3b7635f9dd0e8ed13a3b to your computer and use it in GitHub Desktop.
Save cjadeveloper/ff5fcf3d828d3b7635f9dd0e8ed13a3b to your computer and use it in GitHub Desktop.
vista de la app registration
from django.contrib.auth.forms import UserCreationForm
from django.views.generic import CreateView
from django.urls import reverse_lazy
from django import forms
from django.contrib.auth import password_validation
from django.utils.functional import lazy
from django.utils.html import format_html
from django.utils.module_loading import import_string
from django.utils.translation import gettext as _, ngettext
def _password_validators_help_text_html_for_bulma(password_validators=None):
"""
Redefinimos el método _password_validators_help_text_html para que
retorne un string HTML string con todos los help texts de todos los validadores
configurados en una <ul> agregando la clase "help" requerida por bulma.
"""
help_texts = password_validation.password_validators_help_texts(
password_validators)
help_items = [format_html('<li>{}</li>', help_text)
for help_text in help_texts]
return '<ul class="help">%s</ul>' % ''.join(help_items) if help_items else ''
password_validators_help_text_html_for_bulma = lazy(
_password_validators_help_text_html_for_bulma, str)
# Create your views here.
class SignUpView(CreateView):
form_class = UserCreationForm
template_name = 'registration/signup.html'
def get_success_url(self):
return reverse_lazy('login') + '?register'
def get_form(self, form_class=None):
form = super(SignUpView, self).get_form()
form.fields['password1'].help_text = password_validators_help_text_html_for_bulma
return form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment