53 |
53 |
54 #: list of model fields which will *not* be gathered by the form |
54 #: list of model fields which will *not* be gathered by the form |
55 exclude = ['founder', 'inheritance_line'] |
55 exclude = ['founder', 'inheritance_line'] |
56 |
56 |
57 # TODO(pawel.solyga): write validation functions for other fields |
57 # TODO(pawel.solyga): write validation functions for other fields |
58 def clean_link_name(self): |
58 def clean_link_id(self): |
59 link_name = self.cleaned_data.get('link_name') |
59 link_id = self.cleaned_data.get('link_id') |
60 if not validate.isLinkNameFormatValid(link_name): |
60 if not validate.isLinkIdFormatValid(link_id): |
61 raise forms.ValidationError("This link name is in wrong format.") |
61 raise forms.ValidationError("This link ID is in wrong format.") |
62 if models.sponsor.logic.getFromFields(link_name=link_name): |
62 if models.sponsor.logic.getFromFields(link_id=link_id): |
63 raise forms.ValidationError("This link name is already in use.") |
63 raise forms.ValidationError("This link ID is already in use.") |
64 return link_name |
64 return link_id |
65 |
65 |
66 |
66 |
67 class EditForm(CreateForm): |
67 class EditForm(CreateForm): |
68 """Django form displayed when editing a Sponsor. |
68 """Django form displayed when editing a Sponsor. |
69 """ |
69 """ |
70 link_name = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
70 link_id = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
71 founded_by = forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
71 founded_by = forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
72 required=False) |
72 required=False) |
73 |
73 |
74 def clean_link_name(self): |
74 def clean_link_id(self): |
75 link_name = self.cleaned_data.get('link_name') |
75 link_id = self.cleaned_data.get('link_id') |
76 if not validate.isLinkNameFormatValid(link_name): |
76 if not validate.isLinkIdFormatValid(link_id): |
77 raise forms.ValidationError("This link name is in wrong format.") |
77 raise forms.ValidationError("This link ID is in wrong format.") |
78 return link_name |
78 return link_id |
79 |
79 |
80 |
80 |
81 class View(base.View): |
81 class View(base.View): |
82 """View methods for the Sponsor model. |
82 """View methods for the Sponsor model. |
83 """ |
83 """ |