First phase of making the / (site/home) view generic enough to use it for
Sponsor "home" page, Program "home" page, Organization "home" page, etc. when
combined with HomeSettings.
First phase of addressing this issue:
http://code.google.com/p/soc/issues/detail?id=64
by factoring "Site Settings" apart from the site/home stuff.
Patch by: Todd Larsen
Review by: Pawel Solyga
Review URL: http://codereviews.googleopensourceprograms.com/1405
--- a/app/soc/logic/models/site_settings.py Wed Oct 15 21:23:29 2008 +0000
+++ b/app/soc/logic/models/site_settings.py Wed Oct 15 21:27:47 2008 +0000
@@ -32,6 +32,9 @@
"""Logic methods for the SiteSettings model
"""
+ DEF_SITE_SETTINGS_PATH = 'site'
+ DEF_SITE_HOME_DOC_LINK_NAME = 'home'
+
def __init__(self):
"""Defines the name, key_name and model for this entity.
"""
--- a/app/soc/logic/site/map.py Wed Oct 15 21:23:29 2008 +0000
+++ b/app/soc/logic/site/map.py Wed Oct 15 21:27:47 2008 +0000
@@ -96,10 +96,10 @@
# it should be obvious that every page comes from the home page
in_breadcrumb=False)
-site_home_edit = page.Page(
+site_settings_edit = page.Page(
page.Url(
- r'^site/home/edit$',
- 'soc.views.site.home.edit'),
+ r'^site/settings/edit$',
+ 'soc.views.site.settings.edit'),
'Site: Settings',
short_name='Site Settings',
parent=home)
@@ -111,7 +111,7 @@
'soc.views.site.user.profile.lookup'),
'Site: Look Up an Existing User',
short_name='Look Up Site User',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_user_create = page.Page(
page.Url(
@@ -119,7 +119,7 @@
'soc.views.site.user.profile.create'),
'Site: Create New User Profile',
short_name='Create Site User',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_user_edit = page.Page(
page.Url(
@@ -127,7 +127,7 @@
'soc.views.site.user.profile.edit'),
'Site: Modify Existing User Profile',
short_name='Modify Site User',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_user_list = page.Page(
page.Url(
@@ -135,7 +135,7 @@
'soc.views.site.user.list.all'),
'Site: List of Users',
short_name='List Site Users',
- parent=site_home_edit)
+ parent=site_settings_edit)
# Document views
docs_show = page.Page(
@@ -152,7 +152,7 @@
'soc.views.site.docs.edit.create'),
'Site: Create New Document',
'Create new Site Document',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_docs_edit = page.Page(
page.Url(
@@ -160,7 +160,7 @@
'soc.views.site.docs.edit.edit'),
'Site: Modify Existing Document',
short_name='Modify Site Document',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_docs_delete = page.Page(
page.Url(
@@ -168,7 +168,7 @@
'soc.views.site.docs.edit.delete'),
'Site: Delete Existing Document',
short_name='Delete Site Document',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_docs_list = page.Page(
page.Url(
@@ -176,7 +176,7 @@
'soc.views.site.docs.list.all'),
'Site: List of Documents',
short_name='List Site Documents',
- parent=site_home_edit)
+ parent=site_settings_edit)
# Sponsor Group public view
sponsor_profile = page.Page(
@@ -193,7 +193,7 @@
'soc.views.site.sponsor.profile.create'),
'Site: Create New Sponsor',
short_name='Create New Site Sponsor',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_sponsor_delete = page.Page(
page.Url(
@@ -201,7 +201,7 @@
'soc.views.site.sponsor.profile.delete'),
'Site: Delete Existing Sponsor',
short_name='Delete Site Sponsor',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_sponsor_edit = page.Page(
page.Url(
@@ -209,7 +209,7 @@
'soc.views.site.sponsor.profile.edit'),
'Site: Modify Existing Sponsor',
short_name='Modify Site Sponsor',
- parent=site_home_edit)
+ parent=site_settings_edit)
site_sponsor_list = page.Page(
page.Url(
@@ -217,7 +217,7 @@
'soc.views.site.sponsor.list.all'),
'Site: List of Sponsors',
short_name='List Site Sponsors',
- parent=site_home_edit)
+ parent=site_settings_edit)
# these are not really used...
--- a/app/soc/templates/soc/site/home/edit.html Wed Oct 15 21:23:29 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-{% extends "soc/base.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 scripts %}
- <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
-{% endblock %}
-
-{% block page_title %}Site Settings{% endblock %}
-{% block header_title %}
-Site Settings
-{% endblock %}
-
-{% block body %}
-<p>
-<p>
-{% block instructions %}
-Please use this form to set basic site settings.
-{% endblock %}
-</p>
-<form method="POST">
- <table>
- {{ document_form.as_table }}
- {{ settings_form.as_table }}
- <tr>
- <td colspan="4"> </td>
- </tr>
- <table>
- <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>
- {% endblock %}
- </tr>
- </table>
-</form>
-</p>
-{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/site/settings/edit.html Wed Oct 15 21:27:47 2008 +0000
@@ -0,0 +1,53 @@
+{% extends "soc/base.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 scripts %}
+ <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
+{% endblock %}
+
+{% block page_title %}Site Settings{% endblock %}
+{% block header_title %}
+Site Settings
+{% endblock %}
+
+{% block body %}
+<p>
+<p>
+{% block instructions %}
+Please use this form to set basic site settings.
+{% endblock %}
+</p>
+<form method="POST">
+ <table>
+ {{ document_form.as_table }}
+ {{ settings_form.as_table }}
+ <tr>
+ <td colspan="4"> </td>
+ </tr>
+ <table>
+ <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>
+ {% endblock %}
+ </tr>
+ </table>
+</form>
+</p>
+{% endblock %}
--- a/app/soc/views/site/home.py Wed Oct 15 21:23:29 2008 +0000
+++ b/app/soc/views/site/home.py Wed Oct 15 21:27:47 2008 +0000
@@ -18,8 +18,6 @@
public: how the general public sees the site home page of a Melange
site
-
-edit: site settings view for logged-in Developers
"""
__authors__ = [
@@ -30,72 +28,14 @@
from google.appengine.api import users
from google.appengine.ext import db
-from django import forms
-from django import http
-from django import shortcuts
-
from soc.logic import models
-from soc.logic import out_of_band
-from soc.logic import validate
-from soc.logic.models import document
-from soc.logic.site import id_user
-from soc.views import simple
from soc.views import helper
-from soc.views.helper import access
import soc.logic.models.site_settings
-import soc.models.document
-import soc.models.site_settings
-import soc.views.helper.forms
import soc.views.helper.responses
import soc.views.helper.templates
-import soc.views.helper.widgets
-import soc.views.out_of_band
-class DocumentForm(helper.forms.DbModelForm):
- content = forms.fields.CharField(widget=helper.widgets.TinyMCE(
- attrs={'rows':10, 'cols':40}))
-
- class Meta:
- """Inner Meta class that defines some behavior for the form.
- """
- #: db.Model subclass for which the form will gather information
- model = soc.models.document.Document
-
- #: list of model fields which will *not* be gathered by the form
- exclude = ['partial_path', 'link_name',
- 'author', 'modified', 'created', 'inheritance_line']
-
-
-class SiteSettingsForm(helper.forms.DbModelForm):
- """Django form displayed when creating or editing Site Settings.
- """
- class Meta:
- """Inner Meta class that defines some behavior for the form.
- """
- #: db.Model subclass for which the form will gather information
- model = soc.models.site_settings.SiteSettings
-
- #: list of model fields which will *not* be gathered by the form
- exclude = ['inheritance_line', 'home']
-
- def clean_feed_url(self):
- feed_url = self.cleaned_data.get('feed_url')
-
- if feed_url == '':
- # feed url not supplied (which is OK), so do not try to validate it
- return None
-
- if not validate.isFeedURLValid(feed_url):
- raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
-
- return feed_url
-
-
-DEF_SITE_SETTINGS_PATH = 'site'
-DEF_SITE_HOME_DOC_LINK_NAME = 'home'
-
DEF_SITE_HOME_PUBLIC_TMPL = 'soc/site/home/public.html'
def public(request, template=DEF_SITE_HOME_PUBLIC_TMPL):
@@ -111,8 +51,8 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- site_settings = soc.logic.models.site_settings.logic.getFromFields(
- path=DEF_SITE_SETTINGS_PATH)
+ site_settings = models.site_settings.logic.getFromFields(
+ path=models.site_settings.logic.DEF_SITE_SETTINGS_PATH)
if site_settings:
context['site_settings'] = site_settings
@@ -128,90 +68,3 @@
context['site_document'] = site_doc
return helper.responses.respond(request, template, context=context)
-
-
-DEF_SITE_HOME_EDIT_TMPL = 'soc/site/home/edit.html'
-
-def edit(request, template=DEF_SITE_HOME_EDIT_TMPL):
- """View for Developer to edit content of Melange site home page.
-
- Args:
- request: the standard django request object.
- template: the template path to use for rendering the template.
-
- Returns:
- A subclass of django.http.HttpResponse with generated template.
- """
-
- try:
- access.checkIsDeveloper(request)
- except soc.views.out_of_band.AccessViolationResponse, alt_response:
- return alt_response.response()
-
- # create default template context for use with any templates
- context = helper.responses.getUniversalContext(request)
-
- settings_form = None
- document_form = None
-
- if request.method == 'POST':
- document_form = DocumentForm(request.POST)
- settings_form = SiteSettingsForm(request.POST)
-
- if document_form.is_valid() and settings_form.is_valid():
- link_name = DEF_SITE_HOME_DOC_LINK_NAME
- partial_path=DEF_SITE_SETTINGS_PATH
- logged_in_id = users.get_current_user()
- author = models.user.logic.getFromFields(email=logged_in_id.email())
-
- properties = {
- 'title': document_form.cleaned_data.get('title'),
- 'short_name': document_form.cleaned_data.get('short_name'),
- 'abstract': document_form.cleaned_data.get('abstract'),
- 'content': document_form.cleaned_data.get('content'),
- 'link_name': link_name,
- 'partial_path': partial_path,
- 'id': logged_in_id,
- 'author': author,
- }
-
- site_doc = document.logic.updateOrCreateFromFields(
- properties, partial_path=partial_path, link_name=link_name)
-
- feed_url = settings_form.cleaned_data.get('feed_url')
-
- site_settings = models.site_settings.logic.updateOrCreateFromFields(
- {'feed_url': feed_url, 'home': site_doc}, path=DEF_SITE_SETTINGS_PATH)
-
- context['notice'] = 'Site Settings saved.'
- else: # request.method == 'GET'
- # try to fetch SiteSettings entity by unique key_name
- site_settings = models.site_settings.logic.getFromFields(
- path=DEF_SITE_SETTINGS_PATH)
-
- if site_settings:
- # populate form with the existing SiteSettings entity
- settings_form = SiteSettingsForm(instance=site_settings)
-
- # check if ReferenceProperty to home Document is valid
- try:
- site_doc = site_settings.home
- except db.Error:
- site_doc = None
-
- else:
- # no SiteSettings entity exists for this key_name, so show a blank form
- settings_form = SiteSettingsForm()
- site_doc = None
-
- if site_doc:
- # populate form with the existing Document entity
- document_form = DocumentForm(instance=site_doc)
- else:
- # no Document entity exists for this key_name, so show a blank form
- document_form = DocumentForm()
-
- context.update({'document_form': document_form,
- 'settings_form': settings_form })
-
- return helper.responses.respond(request, template, context)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/site/settings.py Wed Oct 15 21:27:47 2008 +0000
@@ -0,0 +1,181 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 the Melange authors.
+#
+# 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.
+
+"""Site-wide Melange home page views.
+
+public: how the general public sees the site home page of a Melange
+ site
+
+edit: site settings view for logged-in Developers
+"""
+
+__authors__ = [
+ '"Pawel Solyga" <pawel.solyga@gmail.com>',
+ ]
+
+
+from google.appengine.api import users
+from google.appengine.ext import db
+
+from django import forms
+from django import http
+from django import shortcuts
+
+from soc.logic import models
+from soc.logic import out_of_band
+from soc.logic import validate
+from soc.logic.models import document
+from soc.logic.site import id_user
+from soc.views import simple
+from soc.views import helper
+from soc.views.helper import access
+
+import soc.logic.models.site_settings
+import soc.models.document
+import soc.models.site_settings
+import soc.views.helper.forms
+import soc.views.helper.responses
+import soc.views.helper.templates
+import soc.views.helper.widgets
+import soc.views.out_of_band
+
+
+class DocumentForm(helper.forms.DbModelForm):
+ content = forms.fields.CharField(widget=helper.widgets.TinyMCE(
+ attrs={'rows':10, 'cols':40}))
+
+ class Meta:
+ """Inner Meta class that defines some behavior for the form.
+ """
+ #: db.Model subclass for which the form will gather information
+ model = soc.models.document.Document
+
+ #: list of model fields which will *not* be gathered by the form
+ exclude = ['partial_path', 'link_name',
+ 'author', 'modified', 'created', 'inheritance_line']
+
+
+class SiteSettingsForm(helper.forms.DbModelForm):
+ """Django form displayed when creating or editing Site Settings.
+ """
+ class Meta:
+ """Inner Meta class that defines some behavior for the form.
+ """
+ #: db.Model subclass for which the form will gather information
+ model = soc.models.site_settings.SiteSettings
+
+ #: list of model fields which will *not* be gathered by the form
+ exclude = ['inheritance_line', 'home']
+
+ def clean_feed_url(self):
+ feed_url = self.cleaned_data.get('feed_url')
+
+ if feed_url == '':
+ # feed url not supplied (which is OK), so do not try to validate it
+ return None
+
+ if not validate.isFeedURLValid(feed_url):
+ raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
+
+ return feed_url
+
+
+DEF_SITE_HOME_EDIT_TMPL = 'soc/site/settings/edit.html'
+
+def edit(request, template=DEF_SITE_HOME_EDIT_TMPL):
+ """View for Developer to edit content of Melange site home page.
+
+ Args:
+ request: the standard django request object.
+ template: the template path to use for rendering the template.
+
+ Returns:
+ A subclass of django.http.HttpResponse with generated template.
+ """
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.views.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
+ # create default template context for use with any templates
+ context = helper.responses.getUniversalContext(request)
+
+ settings_form = None
+ document_form = None
+
+ if request.method == 'POST':
+ document_form = DocumentForm(request.POST)
+ settings_form = SiteSettingsForm(request.POST)
+
+ if document_form.is_valid() and settings_form.is_valid():
+ link_name = models.site_settings.logic.DEF_SITE_HOME_DOC_LINK_NAME
+ partial_path=models.site_settings.logic.DEF_SITE_SETTINGS_PATH
+ logged_in_id = users.get_current_user()
+ author = models.user.logic.getFromFields(email=logged_in_id.email())
+
+ properties = {
+ 'title': document_form.cleaned_data.get('title'),
+ 'short_name': document_form.cleaned_data.get('short_name'),
+ 'abstract': document_form.cleaned_data.get('abstract'),
+ 'content': document_form.cleaned_data.get('content'),
+ 'link_name': link_name,
+ 'partial_path': partial_path,
+ 'id': logged_in_id,
+ 'author': author,
+ }
+
+ site_doc = document.logic.updateOrCreateFromFields(
+ properties, partial_path=partial_path, link_name=link_name)
+
+ feed_url = settings_form.cleaned_data.get('feed_url')
+
+ site_settings = models.site_settings.logic.updateOrCreateFromFields(
+ {'feed_url': feed_url, 'home': site_doc},
+ path=models.site_settings.logic.DEF_SITE_SETTINGS_PATH)
+
+ context['notice'] = 'Site Settings saved.'
+ else: # request.method == 'GET'
+ # try to fetch SiteSettings entity by unique key_name
+ site_settings = models.site_settings.logic.getFromFields(
+ path=models.site_settings.logic.DEF_SITE_SETTINGS_PATH)
+
+ if site_settings:
+ # populate form with the existing SiteSettings entity
+ settings_form = SiteSettingsForm(instance=site_settings)
+
+ # check if ReferenceProperty to home Document is valid
+ try:
+ site_doc = site_settings.home
+ except db.Error:
+ site_doc = None
+
+ else:
+ # no SiteSettings entity exists for this key_name, so show a blank form
+ settings_form = SiteSettingsForm()
+ site_doc = None
+
+ if site_doc:
+ # populate form with the existing Document entity
+ document_form = DocumentForm(instance=site_doc)
+ else:
+ # no Document entity exists for this key_name, so show a blank form
+ document_form = DocumentForm()
+
+ context.update({'document_form': document_form,
+ 'settings_form': settings_form })
+
+ return helper.responses.respond(request, template, context)