36 from soc.views import simple |
36 from soc.views import simple |
37 from soc.views.helper import access |
37 from soc.views.helper import access |
38 from soc.views.user import profile |
38 from soc.views.user import profile |
39 |
39 |
40 import soc.logic |
40 import soc.logic |
41 import soc.models.sponsor |
41 import soc.models.sponsor as sponsor_model |
42 import soc.views.helper.forms |
42 import soc.views.helper.forms |
43 import soc.views.helper.requests |
43 import soc.views.helper.requests |
44 import soc.views.helper.responses |
44 import soc.views.helper.responses |
45 import soc.views.helper.widgets |
45 import soc.views.helper.widgets |
46 import soc.views.out_of_band |
46 import soc.views.out_of_band |
51 """ |
51 """ |
52 class Meta: |
52 class Meta: |
53 """Inner Meta class that defines some behavior for the form. |
53 """Inner Meta class that defines some behavior for the form. |
54 """ |
54 """ |
55 #: db.Model subclass for which the form will gather information |
55 #: db.Model subclass for which the form will gather information |
56 model = soc.models.sponsor.Sponsor |
56 model = sponsor_model.Sponsor |
57 |
57 |
58 #: list of model fields which will *not* be gathered by the form |
58 #: list of model fields which will *not* be gathered by the form |
59 exclude = ['founder', 'inheritance_line'] |
59 exclude = ['founder', 'inheritance_line'] |
60 |
60 |
61 # TODO(pawel.solyga): write validation functions for other fields |
61 # TODO(pawel.solyga): write validation functions for other fields |
70 |
70 |
71 class EditForm(CreateForm): |
71 class EditForm(CreateForm): |
72 """Django form displayed when editing a Sponsor. |
72 """Django form displayed when editing a Sponsor. |
73 """ |
73 """ |
74 link_name = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
74 link_name = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
75 created_by = forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
75 founded_by = forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
76 required=False) |
76 required=False) |
77 |
77 |
78 def clean_link_name(self): |
78 def clean_link_name(self): |
79 link_name = self.cleaned_data.get('link_name') |
79 link_name = self.cleaned_data.get('link_name') |
80 if not validate.isLinkNameFormatValid(link_name): |
80 if not validate.isLinkNameFormatValid(link_name): |
178 values=profile.SUBMIT_MESSAGES)) |
178 values=profile.SUBMIT_MESSAGES)) |
179 |
179 |
180 # populate form with the existing Sponsor entity |
180 # populate form with the existing Sponsor entity |
181 founder_link_name = existing_sponsor.founder.link_name |
181 founder_link_name = existing_sponsor.founder.link_name |
182 sponsor_form = EditForm(instance=existing_sponsor, |
182 sponsor_form = EditForm(instance=existing_sponsor, |
183 initial={'created_by': founder_link_name}) |
183 initial={'founded_by': founder_link_name}) |
184 else: |
184 else: |
185 if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
185 if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
186 # redirect to aggressively remove 'Profile saved' query parameter |
186 # redirect to aggressively remove 'Profile saved' query parameter |
187 return http.HttpResponseRedirect(request.path) |
187 return http.HttpResponseRedirect(request.path) |
188 |
188 |
189 # no Sponsor entity exists for this link name, so show a blank form |
189 # no Sponsor entity exists for this link name, so show a blank form |
190 sponsor_form = CreateForm() |
190 sponsor_form = CreateForm() |
191 |
191 |
192 context.update({'form': sponsor_form, |
192 context.update({'form': sponsor_form, |
193 'existing_group': existing_sponsor, |
193 'existing_group': existing_sponsor, |
194 'group_type': 'Sponsor'}) |
194 'group_type': 'Sponsor', |
|
195 'group_type_short': sponsor_model.Sponsor.GROUP_TYPE_SHORT}) |
195 |
196 |
196 return helper.responses.respond(request, template, context) |
197 return helper.responses.respond(request, template, context) |
197 |
198 |
198 |
199 |
199 DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL = 'soc/group/profile/edit.html' |
200 DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL = 'soc/group/profile/edit.html' |