示例#1
0
class SignupForm(RegistrationFormUniqueEmail):
    """
    A user-friendly sign up form with dynamically configurable help texts and validation.
    """

    # Have to redeclare the entire field from the super class in order
    # to add our own help text:
    email = forms.EmailField(
        help_text=lambda: markdown(config.EMAIL_HELP_TEXT),
        required=True,
        validators=[
            validators.validate_confusables_email,
        ])

    def clean_email(self):
        """Perform additional email validation if configured in the admin interface."""
        pattern = config.EMAIL_PATTERN
        if pattern:
            # The pattern is always validated in the admin interface by testing if
            # re.compile() succeeds. If it fails to compile now, there must be some
            # serious error which we can't fix here and it's better to crash.
            regex = re.compile(pattern, re.VERBOSE)
            if not regex.search(self.cleaned_data["email"]):
                raise ValidationError(markdown(config.EMAIL_ERROR_MESSAGE))
        return super().clean_email()

    def clean_username(self):
        """Ensure no duplicate user names exist, using case-insensitive comparison."""
        username = self.cleaned_data.get("username")
        if User.objects.filter(username__iexact=username):
            raise forms.ValidationError(
                "A user with that username already exists.")
        return username
示例#2
0
 def test_markdown_tables(self):
     html = markdown(MARKDOWN_TABLE)
     signature_expressions = [
         '<table>', '<thead>', '<tr>', '<th>A</th>', '<tbody>',
         '<td>Test 1</td>'
     ]
     for expression in signature_expressions:
         self.assertTrue(expression in html)
示例#3
0
文件: forms.py 项目: 00mjk/inloop
class ConfirmStudentDetailsForm(forms.ModelForm):
    ownwork_confirmed = forms.BooleanField(
        help_text=lambda: markdown(config.OWNWORK_DECLARATION),
        required=True,
    )

    class Meta:
        model = StudentDetails
        fields = ['matnum', 'ownwork_confirmed']
示例#4
0
 def clean_email(self):
     """Perform additional email validation if configured in the admin interface."""
     pattern = config.EMAIL_PATTERN
     if pattern:
         # The pattern is always validated in the admin interface by testing if
         # re.compile() succeeds. If it fails to compile now, there must be some
         # serious error which we can't fix here and it's better to crash.
         regex = re.compile(pattern, re.VERBOSE)
         if not regex.search(self.cleaned_data["email"]):
             raise ValidationError(markdown(config.EMAIL_ERROR_MESSAGE))
     return super().clean_email()
示例#5
0
 def clean_email(self):
     """Perform additional email validation if configured in the admin interface."""
     pattern = config.EMAIL_PATTERN
     if pattern:
         # The pattern is always validated in the admin interface by testing if
         # re.compile() succeeds. If it fails to compile now, there must be some
         # serious error which we can't fix here and it's better to crash.
         regex = re.compile(pattern, re.VERBOSE)
         if not regex.search(self.cleaned_data["email"]):
             raise ValidationError(markdown(config.EMAIL_ERROR_MESSAGE))
     return super().clean_email()
示例#6
0
 def test_markdown_tables(self):
     html = markdown(MARKDOWN_TABLE)
     signature_expressions = [
         '<table>',
         '<thead>',
         '<tr>',
         '<th>A</th>',
         '<tbody>',
         '<td>Test 1</td>'
     ]
     for expression in signature_expressions:
         self.assertTrue(expression in html)
示例#7
0
 def test_fenced_code(self):
     html = markdown(FENCED_CODE)
     self.assertTrue('<code class="language-python">' in html)
示例#8
0
 def test_autoids(self):
     html = markdown('# Heading')
     self.assertTrue('<h1 id="heading">Heading</h1>' in html)
示例#9
0
 def test_fenced_code(self):
     html = markdown(FENCED_CODE)
     self.assertTrue('<code class="language-python">' in html)
示例#10
0
 def test_autoids(self):
     html = markdown('# Heading')
     self.assertTrue('<h1 id="heading">Heading</h1>' in html)