Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Patch by: Pawel Solyga
Review by: to-be-reviewed
--- a/app/soc/templates/soc/group/profile/edit.html Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/templates/soc/group/profile/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -57,16 +57,14 @@
<td colspan="4"> </td>
</tr>
<tr>
+ {% block submit_buttons %}
<td>
<input style="font-weight: bold" type="submit" value="Save Changes"/></span>
</td>
<td>
<input type="button" onclick="location.href='/'" value="Cancel"/>
</td>
- <td> </td>
- <td>
- {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% endif %}
- </td>
+ {% endblock %}
</tr>
</table>
</form>
--- a/app/soc/templates/soc/site/docs/edit.html Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/templates/soc/site/docs/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -52,10 +52,6 @@
<td>
<input type="button" onclick="location.href='/'" value="Cancel"/>
</td>
- <td> </td>
- <td>
- {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% endif %}
- </td>
</tr>
</table>
</form>
--- a/app/soc/templates/soc/site/home/edit.html Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/templates/soc/site/home/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -43,10 +43,6 @@
<td>
<input type="button" onclick="location.href='/'" value="Cancel"/>
</td>
- <td> </td>
- <td>
- {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% endif %}
- </td>
</tr>
</table>
</form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/site/sponsor/profile/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -0,0 +1,20 @@
+{% extends "soc/group/profile/edit.html" %}
+{% comment %}
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+ {% block submit_buttons %}
+ {{ block.super }}
+<td>
+ <input type="button" onclick="location.href='/site/sponsor/profile/{{ existing_group.link_name }}/delete'" value="Delete"/>
+</td>
+ {% endblock %}
\ No newline at end of file
--- a/app/soc/templates/soc/site/user/profile/edit.html Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/templates/soc/site/user/profile/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -75,15 +75,10 @@
<td>
<input type="button" onclick="location.href='/'" value="Cancel"/>
</td>
- <td> </td>
{% if submit_error %}
<td class="formfielderror">
{{ submit_error }}
</td>
-{% else %}
- <td>
- {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% else %} {% endif %}
- </td>
{% endif %}
</tr>
</table>
--- a/app/soc/templates/soc/user/profile/edit.html Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/templates/soc/user/profile/edit.html Thu Oct 09 15:10:51 2008 +0000
@@ -42,10 +42,6 @@
<td>
<input type="button" onclick="location.href='/'" value="Cancel"/>
</td>
- <td> </td>
- <td>
- {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% endif %}
- </td>
</tr>
</table>
</form>
--- a/app/soc/views/site/docs/edit.py Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/views/site/docs/edit.py Thu Oct 09 15:10:51 2008 +0000
@@ -71,6 +71,10 @@
' <a href="/site/docs/edit">Create ' \
'a New Document</a> page.'
+SUBMIT_MESSAGES = (
+ ugettext_lazy('Document saved.'),
+)
+
def edit(request, partial_path=None, linkname=None,
template=DEF_SITE_DOCS_EDIT_TMPL):
"""View for a Developer to modify the properties of a Document Model entity.
@@ -139,7 +143,6 @@
short_name = form.cleaned_data.get('short_name')
abstract = form.cleaned_data.get('abstract')
content = form.cleaned_data.get('content')
- doc_key_name = form.cleaned_data.get('doc_key_name')
doc = soc.logic.document.updateOrCreateDocument(
partial_path=new_partial_path, link_name=new_linkname,
@@ -169,10 +172,10 @@
# referrer was us, so select which submit message to display
# (may display no message if ?s=0 parameter is not present)
- context['submit_message'] = (
+ context['notice'] = (
helper.requests.getSingleIndexedParamValue(
request, profile.SUBMIT_MSG_PARAM_NAME,
- values=profile.SUBMIT_MESSAGES))
+ values=SUBMIT_MESSAGES))
# populate form with the existing User entity
form = EditForm(initial={'doc_key_name': doc.key().name(),
@@ -205,7 +208,6 @@
class CreateForm(helper.forms.DbModelForm):
"""Django form displayed when Developer creates a Document.
"""
- doc_key_name = forms.CharField(widget=forms.HiddenInput)
content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
class Meta:
@@ -242,11 +244,18 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
+ logged_in_id = users.get_current_user()
+
+ alt_response = simple.getAltResponseIfNotDeveloper(request,
+ context=context,
+ id=logged_in_id)
+ if alt_response:
+ return alt_response
+
alt_response = simple.getAltResponseIfNotDeveloper(request,
context=context)
if alt_response:
return alt_response
-
if request.method == 'POST':
form = CreateForm(request.POST)
@@ -257,7 +266,6 @@
short_name = form.cleaned_data.get('short_name')
abstract = form.cleaned_data.get('abstract')
content = form.cleaned_data.get('content')
- doc_key_name = form.cleaned_data.get('doc_key_name')
doc = soc.logic.document.updateOrCreateDocument(
partial_path=new_partial_path, link_name=new_linkname,
--- a/app/soc/views/site/home.py Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/views/site/home.py Thu Oct 09 15:10:51 2008 +0000
@@ -179,7 +179,7 @@
site_settings = soc.logic.site.settings.updateOrCreateSiteSettings(
DEF_SITE_SETTINGS_PATH, home=site_doc, feed_url=feed_url)
- context['submit_message'] = 'Site Settings saved.'
+ context['notice'] = 'Site Settings saved.'
else: # request.method == 'GET'
# try to fetch SiteSettings entity by unique key_name
site_settings = soc.logic.site.settings.getSiteSettings(
--- a/app/soc/views/site/sponsor/profile.py Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py Thu Oct 09 15:10:51 2008 +0000
@@ -165,7 +165,7 @@
# referrer was us, so select which submit message to display
# (may display no message if ?s=0 parameter is not present)
- context['submit_message'] = (
+ context['notice'] = (
helper.requests.getSingleIndexedParamValue(
request, profile.SUBMIT_MSG_PARAM_NAME,
values=profile.SUBMIT_MESSAGES))
@@ -191,3 +191,40 @@
"""create() view is same as edit() view, but with no linkname supplied.
"""
return edit(request, linkname=None, template=template)
+
+
+def delete(request, linkname=None, template=DEF_SITE_SPONSOR_PROFILE_EDIT_TMPL):
+ """Request handler for a Developer to delete Sponsor Model entity.
+
+ Args:
+ request: the standard django request object
+ linkname: the Sponsor's site-unique "linkname" extracted from the URL
+ template: the "sibling" template (or a search list of such templates)
+ from which to construct the public.html template name (or names)
+
+ Returns:
+ A subclass of django.http.HttpResponse which redirects
+ to /site/sponsor/list.
+ """
+ # create default template context for use with any templates
+ context = helper.responses.getUniversalContext(request)
+
+ alt_response = simple.getAltResponseIfNotDeveloper(request,
+ context=context)
+ if alt_response:
+ return alt_response
+
+ existing_sponsor = None
+
+ # try to fetch Sponsor entity corresponding to linkname if one exists
+ try:
+ existing_sponsor = soc.logic.sponsor.getSponsorIfLinkName(linkname)
+ except out_of_band.ErrorResponse, error:
+ # show custom 404 page when link name doesn't exist in Datastore
+ error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
+ return simple.errorResponse(request, error, template, context)
+
+ if existing_sponsor:
+ sponsor.deleteSponsor(existing_sponsor)
+
+ return http.HttpResponseRedirect('/site/sponsor/list')
\ No newline at end of file
--- a/app/soc/views/site/user/profile.py Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/views/site/user/profile.py Thu Oct 09 15:10:51 2008 +0000
@@ -303,7 +303,7 @@
# referrer was us, so select which submit message to display
# (may display no message if ?s=0 parameter is not present)
- context['submit_message'] = (
+ context['notice'] = (
helper.requests.getSingleIndexedParamValue(
request, profile.SUBMIT_MSG_PARAM_NAME,
values=profile.SUBMIT_MESSAGES))
--- a/app/soc/views/user/profile.py Thu Oct 09 13:56:42 2008 +0000
+++ b/app/soc/views/user/profile.py Thu Oct 09 15:10:51 2008 +0000
@@ -147,7 +147,7 @@
# referrer was us, so select which submit message to display
# (may display no message if ?s=0 parameter is not present)
- context['submit_message'] = (
+ context['notice'] = (
helper.requests.getSingleIndexedParamValue(
request, SUBMIT_MSG_PARAM_NAME, values=SUBMIT_MESSAGES))