Mercurial > personas_backend
annotate personasbackend/personas/forms.py @ 182:f1a9f5f820d7
Oops, fixed an infinite-recursion bug.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 16 Apr 2008 20:03:26 -0700 |
parents | 8b9d37988100 |
children |
rev | line source |
---|---|
94
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
1 import django.newforms as forms |
128
9bcc77e37c19
Renamed all references of PersonasBackend to personasbackend, matching PEP-8.
Atul Varma <varmaa@toolness.com>
parents:
127
diff
changeset
|
2 from personasbackend.personas import models |
27
4439a83c5dc6
Added a trivial new/edit form using the django.newforms system.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
3 |
149
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
4 class BasePersonaForm( forms.ModelForm ): |
64
5f21f8d3334b
Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents:
63
diff
changeset
|
5 """ |
5f21f8d3334b
Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents:
63
diff
changeset
|
6 Form given to normal users who don't have the permission to |
5f21f8d3334b
Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents:
63
diff
changeset
|
7 publish Personas. |
5f21f8d3334b
Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents:
63
diff
changeset
|
8 """ |
5f21f8d3334b
Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents:
63
diff
changeset
|
9 |
27
4439a83c5dc6
Added a trivial new/edit form using the django.newforms system.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
10 class Meta: |
4439a83c5dc6
Added a trivial new/edit form using the django.newforms system.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
11 model = models.Persona |
152
052bf8a07b76
The edit persona form now allows admin users to publish personas.
Atul Varma <varmaa@toolness.com>
parents:
149
diff
changeset
|
12 exclude = ["owner", "date_published", "popularity"] |
74
ec926b106c68
Consolidated validating of header/footer URL/image stuff so that it's done at both the model and form level without too much DRY violation. I'm not sure how pleased I am with this, but it'll work for now.
Atul Varma <varmaa@toolness.com>
parents:
72
diff
changeset
|
13 |
92
c5d76a735410
Fixed a validation bug w/ colors
Atul Varma <varmaa@toolness.com>
parents:
91
diff
changeset
|
14 def _color_cleaner( self, field ): |
95
b42e3997fe58
Refactored and simplified validation logic.
Atul Varma <varmaa@toolness.com>
parents:
94
diff
changeset
|
15 models.ensure_color_is_valid( |
b42e3997fe58
Refactored and simplified validation logic.
Atul Varma <varmaa@toolness.com>
parents:
94
diff
changeset
|
16 self.cleaned_data[field], |
b42e3997fe58
Refactored and simplified validation logic.
Atul Varma <varmaa@toolness.com>
parents:
94
diff
changeset
|
17 error_class = forms.ValidationError |
b42e3997fe58
Refactored and simplified validation logic.
Atul Varma <varmaa@toolness.com>
parents:
94
diff
changeset
|
18 ) |
92
c5d76a735410
Fixed a validation bug w/ colors
Atul Varma <varmaa@toolness.com>
parents:
91
diff
changeset
|
19 return self.cleaned_data[field] |
91
cad201e72d73
Added validation for the text_color and accent_color fields.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
20 |
cad201e72d73
Added validation for the text_color and accent_color fields.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
21 def clean_text_color( self ): |
92
c5d76a735410
Fixed a validation bug w/ colors
Atul Varma <varmaa@toolness.com>
parents:
91
diff
changeset
|
22 return self._color_cleaner( "text_color" ) |
91
cad201e72d73
Added validation for the text_color and accent_color fields.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
23 |
cad201e72d73
Added validation for the text_color and accent_color fields.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
24 def clean_accent_color( self ): |
92
c5d76a735410
Fixed a validation bug w/ colors
Atul Varma <varmaa@toolness.com>
parents:
91
diff
changeset
|
25 return self._color_cleaner( "accent_color" ) |
91
cad201e72d73
Added validation for the text_color and accent_color fields.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
26 |
173
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
27 def clean( self ): |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
28 hasHeader = False |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
29 hasFooter = False |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
30 |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
31 if self.instance: |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
32 hasHeader = self.instance.header_img |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
33 hasFooter = self.instance.footer_img |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
34 |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
35 if (not self.files.has_key("header_img")) and (not hasHeader): |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
36 raise forms.ValidationError( "You must upload a header image." ) |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
37 elif (not self.files.has_key("footer_img")) and (not hasFooter): |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
38 raise forms.ValidationError( "You must upload a footer image." ) |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
39 |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
40 return self.cleaned_data |
65c14ecad14c
Personas must now have a valid header and footer uploaded.
Atul Varma <varmaa@toolness.com>
parents:
163
diff
changeset
|
41 |
152
052bf8a07b76
The edit persona form now allows admin users to publish personas.
Atul Varma <varmaa@toolness.com>
parents:
149
diff
changeset
|
42 class AdminPersonaForm( BasePersonaForm ): |
149
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
43 pass |
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
44 |
163
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
45 DEVELOPER_AGREEMENT = """ |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
46 <p>By uploading your Persona to this site, you agree that |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
47 the following are true:</p> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
48 <ul> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
49 <li>you have the right to distribute this Persona, |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
50 including any rights required for material that may be |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
51 trademarked or copyrighted by someone else; and</li> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
52 <li>if any information about the user or usage of this |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
53 Persona is collected or transmitted outside of the user's |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
54 computer, the details of this collection will be provided |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
55 in the description of the software, and you will provide a |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
56 link to a privacy policy detailing how the information is |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
57 managed and protected; and</li> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
58 <li>your Persona may be removed from the site, |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
59 re-categorized, have its description or other information |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
60 changed, or otherwise have its listing changed or removed, |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
61 at the sole discretion of Mozilla and its authorized |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
62 agents; and</li> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
63 <li>the descriptions and other data you provide about the |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
64 Persona are true to the best of your knowledge.</li> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
65 </ul> |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
66 """ |
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
67 |
181
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
68 class UserPersonaForm( BasePersonaForm ): |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
69 class Meta: |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
70 model = BasePersonaForm.Meta.model |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
71 exclude = BasePersonaForm.Meta.exclude + ["status"] |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
72 |
149
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
73 agree_to_terms = forms.BooleanField( |
163
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
74 label = "I have read and accept the developer agreement.", |
149
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
75 # TODO: setting required to True doesn't seem to have any effect, |
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
76 # but the Django docs say it should ensure that the checkbox |
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
77 # is filled out. |
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
78 required = True, |
163
6279ed400a55
Modified wording of the developer agreement. It looks utterly ridiculous right now; this will change.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
79 help_text = DEVELOPER_AGREEMENT |
149
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
80 ) |
98257bc9841e
We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
81 |
74
ec926b106c68
Consolidated validating of header/footer URL/image stuff so that it's done at both the model and form level without too much DRY violation. I'm not sure how pleased I am with this, but it'll work for now.
Atul Varma <varmaa@toolness.com>
parents:
72
diff
changeset
|
82 def clean( self ): |
182
f1a9f5f820d7
Oops, fixed an infinite-recursion bug.
Atul Varma <varmaa@toolness.com>
parents:
181
diff
changeset
|
83 super( UserPersonaForm, self ).clean() |
94
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
84 if not self.cleaned_data["agree_to_terms"]: |
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
85 raise forms.ValidationError( |
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
86 "You must agree to the terms of service to " |
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
87 "submit your Persona." |
e1bfeffce0f0
Added an 'I accept the terms of use' checkbox to Persona submission.
Atul Varma <varmaa@toolness.com>
parents:
92
diff
changeset
|
88 ) |
74
ec926b106c68
Consolidated validating of header/footer URL/image stuff so that it's done at both the model and form level without too much DRY violation. I'm not sure how pleased I am with this, but it'll work for now.
Atul Varma <varmaa@toolness.com>
parents:
72
diff
changeset
|
89 |
ec926b106c68
Consolidated validating of header/footer URL/image stuff so that it's done at both the model and form level without too much DRY violation. I'm not sure how pleased I am with this, but it'll work for now.
Atul Varma <varmaa@toolness.com>
parents:
72
diff
changeset
|
90 return self.cleaned_data |
181
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
91 |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
92 class EditPersonaForm( UserPersonaForm ): |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
93 pass |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
94 |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
95 class NewPersonaForm( UserPersonaForm ): |
8b9d37988100
The developer agreement should show up on the edit page now, for normal users.
Atul Varma <varmaa@toolness.com>
parents:
173
diff
changeset
|
96 pass |