-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for django-recaptcha functionality
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.forms import fields, forms | ||
|
||
from formset.widgets import SlugInput | ||
from captcha.fields import ReCaptchaField | ||
from captcha.widgets import ReCaptchaV2Checkbox | ||
|
||
|
||
class ArticleCaptchaForm(forms.Form): | ||
""" | ||
Using a ``SlugField`` | ||
--------------------- | ||
In Django's Admin, a ``SlugField`` can be configured to be prepopulated using the content of | ||
another text input field. To emulate a similar behaviour, **django-formset** provides a special | ||
widget named ``SlugInput``. | ||
.. code-block:: python | ||
from django.forms import fields, forms | ||
from formset.widgets import SlugInput | ||
class ArticleForm(...): | ||
... | ||
title = fields.CharField( | ||
label="Title", | ||
max_length=100, | ||
) | ||
slug = fields.SlugField( | ||
label="Slug", | ||
widget=SlugInput('title'), | ||
) | ||
... | ||
This widget takes a single attribute with the name of another field of the same form. | ||
That field's input value then is used to prepopulate the slug field, where the generated value | ||
is produced by concatenating the values of the source fields, and then by transforming that | ||
result into a valid slug (e.g. substituting dashes for spaces, lowercasing letters and rewriting | ||
unicode characters to ASCII letters). | ||
Prefilled slug fields aren't modified after a value has been saved as this usually is undesired | ||
behaviour. | ||
""" | ||
|
||
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox) | ||
|
||
title = fields.CharField( | ||
label="Title", | ||
max_length=100, | ||
) | ||
|
||
slug = fields.SlugField( | ||
label="Slug", | ||
widget=SlugInput('title'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters