implement new module gvawebcore to provide common code

- add gvawebcore.forms.PasswordModelFormMixin
- add generated documentation
- add german translation
This commit is contained in:
Jan Dittberner 2015-01-25 12:00:30 +01:00
parent 1ab832b94a
commit 9883db6fa2
5 changed files with 92 additions and 0 deletions

View file

@ -15,6 +15,7 @@ Common code
.. toctree:: .. toctree::
code/gvacommon code/gvacommon
code/gvawebcore
Celery task stubs Celery task stubs

11
docs/code/gvawebcore.rst Normal file
View file

@ -0,0 +1,11 @@
:py:mod:`gvawebcore`
====================
.. automodule:: gvawebcore
:py:mod:`forms <gvawebcore.forms>`
----------------------------------
.. automodule:: gvawebcore.forms
:members:

View file

@ -0,0 +1,5 @@
"""
This is a collection of modules that can be used by multiple gnuviechadmin
apps.
"""

View file

@ -0,0 +1,43 @@
"""
This module defines form classes that can be extended by other gnuviechadmin
apps' forms.
"""
from __future__ import absolute_import, unicode_literals
from django import forms
from django.utils.translation import ugettext_lazy as _
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
"""
Error message for non matching passwords.
"""
class PasswordModelFormMixin(forms.Form):
"""
A form for entering a password in two password fields. The form checks
whether both fields contain the same string.
"""
password1 = forms.CharField(
label=_('Password'), widget=forms.PasswordInput,
)
password2 = forms.CharField(
label=_('Password (again)'), widget=forms.PasswordInput,
)
def clean_password2(self):
"""
Check that the two password entries match.
:return: the validated password
:rtype: str or None
"""
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError(PASSWORD_MISMATCH_ERROR)
return password2

View file

@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: gvawebcore\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-25 11:49+0100\n"
"PO-Revision-Date: 2015-01-25 11:49+0100\n"
"Last-Translator: Jan Dittberner <jan@dittberner.info>\n"
"Language-Team: Jan Dittberner <jan@dittberner.info>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.6.10\n"
"X-Poedit-SourceCharset: UTF-8\n"
#: forms.py:12
msgid "Passwords don't match"
msgstr "Passwörter stimmen nicht überein"
#: forms.py:25
msgid "Password"
msgstr "Passwort: "
#: forms.py:28
msgid "Password (again)"
msgstr "Passwortwiederholung"