86 DEF_SPONSOR_NO_LINKNAME_CHANGE_MSG = 'Sponsor link name cannot be changed.' |
86 DEF_SPONSOR_NO_LINKNAME_CHANGE_MSG = 'Sponsor link name cannot be changed.' |
87 DEF_CREATE_NEW_SPONSOR_MSG = ' You can create a new sponsor by visiting' \ |
87 DEF_CREATE_NEW_SPONSOR_MSG = ' You can create a new sponsor by visiting' \ |
88 ' <a href="/site/sponsor/profile">Create ' \ |
88 ' <a href="/site/sponsor/profile">Create ' \ |
89 'a New Sponsor</a> page.' |
89 'a New Sponsor</a> page.' |
90 |
90 |
91 def edit(request, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL): |
91 def edit(request, page=None, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL): |
92 """View for a Developer to modify the properties of a Sponsor Model entity. |
92 """View for a Developer to modify the properties of a Sponsor Model entity. |
93 |
93 |
94 Args: |
94 Args: |
95 request: the standard django request object |
95 request: the standard django request object |
|
96 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
97 a Django view with sidebar menu info |
96 link_name: the Sponsor's site-unique "link_name" extracted from the URL |
98 link_name: the Sponsor's site-unique "link_name" extracted from the URL |
97 template: the "sibling" template (or a search list of such templates) |
99 template: the "sibling" template (or a search list of such templates) |
98 from which to construct the public.html template name (or names) |
100 from which to construct the public.html template name (or names) |
99 |
101 |
100 Returns: |
102 Returns: |
119 try: |
121 try: |
120 existing_sponsor = sponsor.logic.getIfFields(link_name=link_name) |
122 existing_sponsor = sponsor.logic.getIfFields(link_name=link_name) |
121 except out_of_band.ErrorResponse, error: |
123 except out_of_band.ErrorResponse, error: |
122 # show custom 404 page when link name doesn't exist in Datastore |
124 # show custom 404 page when link name doesn't exist in Datastore |
123 error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG |
125 error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG |
124 return simple.errorResponse(request, error, template, context) |
126 return simple.errorResponse(request, error, template, context, page) |
125 |
127 |
126 if request.method == 'POST': |
128 if request.method == 'POST': |
127 if existing_sponsor: |
129 if existing_sponsor: |
128 sponsor_form = EditForm(request.POST) |
130 sponsor_form = EditForm(request.POST) |
129 else: |
131 else: |
135 # abuse that manually, so we check if form link_name is the same as |
137 # abuse that manually, so we check if form link_name is the same as |
136 # url link_name |
138 # url link_name |
137 if sponsor_form.cleaned_data.get('link_name') != link_name: |
139 if sponsor_form.cleaned_data.get('link_name') != link_name: |
138 msg = DEF_SPONSOR_NO_LINKNAME_CHANGE_MSG |
140 msg = DEF_SPONSOR_NO_LINKNAME_CHANGE_MSG |
139 error = out_of_band.ErrorResponse(msg) |
141 error = out_of_band.ErrorResponse(msg) |
140 return simple.errorResponse(request, error, template, context) |
142 return simple.errorResponse(request, error, template, context, page) |
141 |
143 |
142 fields = {} |
144 fields = {} |
143 |
145 |
144 # Ask for all the fields and pull them out |
146 # Ask for all the fields and pull them out |
145 for field in sponsor_form.cleaned_data: |
147 for field in sponsor_form.cleaned_data: |
197 return helper.responses.respond(request, template, context) |
199 return helper.responses.respond(request, template, context) |
198 |
200 |
199 |
201 |
200 DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL = 'soc/group/profile/edit.html' |
202 DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL = 'soc/group/profile/edit.html' |
201 |
203 |
202 def create(request, template=DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL): |
204 def create(request, page=None, template=DEF_SITE_SPONSOR_PROFILE_CREATE_TMPL): |
203 """create() view is same as edit() view, but with no link_name supplied. |
205 """create() view is same as edit() view, but with no link_name supplied. |
204 """ |
206 """ |
205 return edit(request, link_name=None, template=template) |
207 return edit(request, page, link_name=None, template=template) |
206 |
208 |
207 |
209 |
208 def delete(request, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL): |
210 def delete(request, page=None, link_name=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL): |
209 """Request handler for a Developer to delete Sponsor Model entity. |
211 """Request handler for a Developer to delete Sponsor Model entity. |
210 |
212 |
211 Args: |
213 Args: |
212 request: the standard django request object |
214 request: the standard django request object |
|
215 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
216 a Django view with sidebar menu info |
213 link_name: the Sponsor's site-unique "link_name" extracted from the URL |
217 link_name: the Sponsor's site-unique "link_name" extracted from the URL |
214 template: the "sibling" template (or a search list of such templates) |
218 template: the "sibling" template (or a search list of such templates) |
215 from which to construct the public.html template name (or names) |
219 from which to construct the public.html template name (or names) |
216 |
220 |
217 Returns: |
221 Returns: |
233 try: |
237 try: |
234 existing_sponsor = models.sponsor.logic.getIfFields(link_name=link_name) |
238 existing_sponsor = models.sponsor.logic.getIfFields(link_name=link_name) |
235 except out_of_band.ErrorResponse, error: |
239 except out_of_band.ErrorResponse, error: |
236 # show custom 404 page when link name doesn't exist in Datastore |
240 # show custom 404 page when link name doesn't exist in Datastore |
237 error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG |
241 error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG |
238 return simple.errorResponse(request, error, template, context) |
242 return simple.errorResponse(request, error, template, context, page) |
239 |
243 |
240 if existing_sponsor: |
244 if existing_sponsor: |
241 # TODO(pawel.solyga): Create specific delete method for Sponsor model |
245 # TODO(pawel.solyga): Create specific delete method for Sponsor model |
242 # Check if Sponsor can be deleted (has no Hosts and Programs) |
246 # Check if Sponsor can be deleted (has no Hosts and Programs) |
243 models.sponsor.logic.delete(existing_sponsor) |
247 models.sponsor.logic.delete(existing_sponsor) |