root/trunk/djedna/catalog/forms.py

Revision 400, 1.6 kB (checked in by thomas, 10 months ago)

Added GPLv3 copyright notices

Line 
1 # (c) Copyright 2008 Thomas Bohmbach, Jr.
2 #
3 # This file is part of DJ Edna.
4 #
5 # DJ Edna is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
9 #
10 # DJ Edna is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # DJ Edna.  If not, see <http://www.gnu.org/licenses/>.
17
18 from django import newforms as forms
19
20 from djedna.permit.models import ActionAccessCode, GroupAccessCode
21
22 class SearchForm(forms.Form):
23     search = forms.CharField(required=False, label='')
24     def output_html(self):
25         return self._html_output(u'%(label)s %(field)s%(help_text)s', u'<p>%s</p>', '<br/>', u' %s', True)
26
27 class RedeemForm(forms.Form):
28     code = forms.CharField(required=True, label='Code')
29    
30     def clean_code(self):
31         try:
32             code = self.cleaned_data['code']
33             perm = ActionAccessCode.objects.get(code=code)
34         except ActionAccessCode.DoesNotExist:
35             try:
36                 perm = GroupAccessCode.objects.get(code=code)
37             except GroupAccessCode.DoesNotExist:
38                 raise forms.ValidationError('The code you entered is not valid.')
39         if not perm.is_valid():
40             raise forms.ValidationError('The code you entered is no longer valid.')
41         return code
42    
43
Note: See TracBrowser for help on using the browser.