# HG changeset patch # User Sverre Rabbelier # Date 1225928280 0 # Node ID 0b479d573a4cca32435975afa1ecdb8e8df57e0e # Parent 31927f21970d5f263cc90716be18a2dc01dbdaef Refactoring of {site/home}_settings to make them use base.View This makes the way for deleting the key_name.py module diff -r 31927f21970d -r 0b479d573a4c app/django/core/urlresolvers.py --- a/app/django/core/urlresolvers.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/django/core/urlresolvers.py Wed Nov 05 23:38:00 2008 +0000 @@ -131,9 +131,9 @@ except ImportError, e: mod_name, _ = get_mod_func(self._callback_str) raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e)) - except AttributeError, e: - mod_name, func_name = get_mod_func(self._callback_str) - raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e)) + #except AttributeError, e: + #mod_name, func_name = get_mod_func(self._callback_str) + #raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e)) return self._callback callback = property(_get_callback) diff -r 31927f21970d -r 0b479d573a4c app/soc/logic/models/home_settings.py --- a/app/soc/logic/models/home_settings.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/logic/models/home_settings.py Wed Nov 05 23:38:00 2008 +0000 @@ -39,9 +39,6 @@ self._name = "HomeSettings" self._model = soc.models.home_settings.HomeSettings - # TODO: remove line below when HomeSettings is implemented using - # views.models.base.View approach - self._keyName = key_name.nameHomeSettings self._skip_properties = [] def getKeyValues(self, entity): @@ -62,5 +59,4 @@ return ['partial_path', 'link_name'] - logic = Logic() diff -r 31927f21970d -r 0b479d573a4c app/soc/logic/models/site_settings.py --- a/app/soc/logic/models/site_settings.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/logic/models/site_settings.py Wed Nov 05 23:38:00 2008 +0000 @@ -43,10 +43,13 @@ self._name = "SiteSettings" self._model = soc.models.site_settings.SiteSettings - # TODO: remove line below when SiteSettings is implemented using - # views.models.base.View approach - self._keyName = key_name.nameSiteSettings self._skip_properties = [] + def getMainKeyValues(self): + """Returns the default key values for the site settings""" + + return [self.DEF_SITE_SETTINGS_PARTIAL_PATH, + self.DEF_SITE_SETTINGS_LINK_NAME] + logic = Logic() diff -r 31927f21970d -r 0b479d573a4c app/soc/logic/models/work.py --- a/app/soc/logic/models/work.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/logic/models/work.py Wed Nov 05 23:38:00 2008 +0000 @@ -39,11 +39,7 @@ self._name = "Work" self._model = soc.models.work.Work - # TODO: remove line below when Work is implemented using - # views.models.base.View approach - self._keyName = key_name.nameWork self._skip_properties = [] - # TODO(tlarsen): write a nameWork method def getKeyValues(self, entity): """See base.Logic.getKeyNameValues. @@ -63,4 +59,5 @@ return ['link_name'] + logic = Logic() diff -r 31927f21970d -r 0b479d573a4c app/soc/logic/site/map.py --- a/app/soc/logic/site/map.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/logic/site/map.py Wed Nov 05 23:38:00 2008 +0000 @@ -37,13 +37,7 @@ home = page.Page( page.Url( r'^$', - 'soc.views.home.public', - kwargs={ - 'partial_path': models.site_settings.logic.DEF_SITE_SETTINGS_PARTIAL_PATH, - 'link_name': models.site_settings.logic.DEF_SITE_SETTINGS_LINK_NAME, - 'entity_type': 'SiteSettings', - 'template': 'soc/home/public.html', - }), + 'soc.views.models.site_settings.main_public'), 'Google Open Source Programs', # it should be obvious that every page comes from the home page in_breadcrumb=False) @@ -99,42 +93,102 @@ # Site Home Page views site_home = page.Page( page.Url( - r'^site/home$', - 'soc.views.home.public', - kwargs={ - 'partial_path': models.site_settings.logic.DEF_SITE_SETTINGS_PARTIAL_PATH, - 'link_name': models.site_settings.logic.DEF_SITE_SETTINGS_LINK_NAME, - 'entity_type': 'SiteSettings', - 'template': 'soc/home/public.html', - }), + r'^home$', + 'soc.views.models.site_settings.main_public'), 'Google Open Source Programs', # it should be obvious that every page comes from the home page in_breadcrumb=False) + site_sub_menu = page.NonPage( 'site-sub-menu', 'Site', parent=home) +home_settings_sub_menu = page.NonPage( + 'home-settings-sub-menu', + 'Home Settings', + parent=site_sub_menu) + +# Site Home Settings views +home_settings_list = page.Page( + page.Url( + r'^home/list$', + 'soc.views.models.home_settings.list'), + 'Site: List Home Settings', + short_name='List Home Settings', + parent=home_settings_sub_menu) + +home_settings_create = page.Page( + page.Url( + r'^home/create$', + 'soc.views.models.home_settings.create'), + 'Site: Create New Home Settings', + short_name='Create Home Settings', + parent=home_settings_sub_menu) + +home_settings_edit = page.Page( + page.Url( + r'^home/edit/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, + 'soc.views.models.home_settings.edit'), + 'Site: Settings', + short_name='Edit Site Settings', + parent=home_settings_sub_menu) + +home_settings_show = page.Page( + page.Url( + r'^home/show/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, + 'soc.views.models.home_settings.public'), + 'Show Document', + parent=home) + + site_settings_sub_menu = page.NonPage( 'site-settings-sub-menu', 'Site Settings', parent=site_sub_menu) -# Site User Profile views +# Site Home Settings views +site_settings_list = page.Page( + page.Url( + r'^site/list$', + 'soc.views.models.site_settings.list'), + 'Site: List Site Settings', + short_name='List Site Settings', + parent=site_settings_sub_menu) + +site_settings_create = page.Page( + page.Url( + r'^site/create$', + 'soc.views.models.site_settings.create'), + 'Site: Create New Site Settings', + short_name='Create Site Settings', + parent=site_settings_sub_menu) + site_settings_edit = page.Page( page.Url( - r'^settings/edit$', - 'soc.views.site.settings.edit', - kwargs={ - 'partial_path': models.site_settings.logic.DEF_SITE_SETTINGS_PARTIAL_PATH, - 'link_name': models.site_settings.logic.DEF_SITE_SETTINGS_LINK_NAME, - 'logic': models.site_settings.logic, - }), + r'^site/edit$', + 'soc.views.models.site_settings.main_edit'), + 'Site: Settings', + short_name='Edit Main Site Settings', + parent=site_settings_sub_menu) + +site_settings_edit = page.Page( + page.Url( + r'^site/edit/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, + 'soc.views.models.site_settings.edit'), 'Site: Settings', short_name='Edit Site Settings', parent=site_settings_sub_menu) +site_settings_show = page.Page( + page.Url( + r'^site/show/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, + 'soc.views.models.site_settings.public'), + 'Show Document', + parent=home) + + # Site User Profile views site_user_sub_menu = page.NonPage( 'site-user-sub-menu', diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/home/public.html --- a/app/soc/templates/soc/home/public.html Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/templates/soc/home/public.html Wed Nov 05 23:38:00 2008 +0000 @@ -1,4 +1,4 @@ -{% extends "soc/home_settings/public.html" %} +{% 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. @@ -13,15 +13,50 @@ limitations under the License. {% endcomment %} +{% block scripts %} +{% if home_settings.feed_url %} + + + +{% endif %} +{% endblock %} + +{% block page_title %} +{% if home_document %} +{{ home_document.title }} +{% else %} +{{ page.long_name }} +{% endif %} +{% endblock %} + +{% block header_title %} +{% if home_document %} +{{ home_document.short_name }} +{% else %} +{{ page.short_name }} +{% endif %} +{% endblock %} + +{% block body %} + {% if home_document %} + {{ home_document.content|safe }} +
Last updated on: {{ home_document.modified }}
+ {% else %} {% block missing_doc %} -The contents of this default Site home page can be changed by -creating a new Document or -editing an existing Document and then selecting -that Document in the -Site Settings interface. -Other elements of this page, such as a feed to be displayed below this -content, can also be set using the -Site Settings interface. -You need to sign in as site Developer in order to change -Site Settings. +This is the default home page can be edited via Settings. {% endblock %} + {% endif %} + {% if home_settings.feed_url %} +
+ {% endif %} +{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/home_settings/error.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/home_settings/error.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,27 @@ +{% 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 page_title %} +Default Home page +{% endblock %} + +{% block header_title %} +Default Home page +{% endblock %} + +{% block body %} +This is the default home page can be edited via Settings.
+You are seeing this page because the specified Home page could not be found. +{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/home_settings/list/home_heading.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/home_settings/list/home_heading.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,4 @@ + + Path + Home Document + diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/home_settings/list/home_row.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/home_settings/list/home_row.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,10 @@ + + +
+ {{ data_element.partial_path}}/{{ data_element.link_name }} +
+ + + diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/home_settings/public.html --- a/app/soc/templates/soc/home_settings/public.html Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/templates/soc/home_settings/public.html Wed Nov 05 23:38:00 2008 +0000 @@ -1,4 +1,4 @@ -{% extends "soc/base.html" %} +{% extends "soc/home/public.html" %} {% comment %} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,50 +13,15 @@ limitations under the License. {% endcomment %} -{% block scripts %} -{% if home_settings.feed_url %} - - - -{% endif %} +{% block missing_doc %} +The contents of this default Site home page can be changed by +creating a new Document or +editing an existing Document and then selecting +that Document in the +Site Settings interface. +Other elements of this page, such as a feed to be displayed below this +content, can also be set using the +Site Settings interface. +You need to sign in as site Developer in order to change +Site Settings. {% endblock %} - -{% block page_title %} -{% if home_document %} -{{ home_document.title }} -{% else %} -{{ page.long_name }} -{% endif %} -{% endblock %} - -{% block header_title %} -{% if home_document %} -{{ home_document.short_name }} -{% else %} -{{ page.short_name }} -{% endif %} -{% endblock %} - -{% block body %} - {% if home_document %} - {{ home_document.content|safe }} -
Last updated on: {{ home_document.modified }}
- {% else %} -{% block missing_doc %} -This is the default home page can be edited via Settings. -{% endblock %} - {% endif %} - {% if home_settings.feed_url %} -
- {% endif %} -{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/site_settings/list/site_heading.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/site_settings/list/site_heading.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,4 @@ + + Path + Home Document + diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/site_settings/list/site_row.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/site_settings/list/site_row.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,10 @@ + + +
+ {{ data_element.partial_path}}/{{ data_element.link_name }} +
+ + + diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/user/edit.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/user/edit.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,82 @@ +{% 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 %} +{% load forms_helpers %} +{% block header_title %} + {{ page.short_name }} + {% if existing_user %} +for {{ existing_user.nick_name }} +<{{ existing_user.id.email }}> + {% endif %} +{% endblock %} +{% block body %} +

+

+{% block instructions %} +Please use this form to alter basic site-wide settings for a User in Google Open Source Programs. +{% endblock %} +

+
+ {{ form.key_name }} + + {% if existing_user %} + {% readonly_field_as_table_row "Id" existing_user.id %} + {% endif %} + {% field_as_table_row form.id %} +{% if lookup_error %} + + + + +{% endif %} + {% field_as_table_row form.link_name %} + {% field_as_table_row form.nick_name %} + {% field_as_table_row form.is_developer %} + {% if existing_user.former_ids %} + + + + + + + {% endif %} + + + +
  + {{ lookup_error }} +
Former ids + {% for former_id in existing_user.former_ids %} + {{ former_id }}
+ {% endfor %} +
  
 
+ + {% block submit_buttons %} + + + {% if submit_error %} + + {% endif %} + {% endblock %} + +
+ + + + + {{ submit_error }} +
+
+

+{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/user/edit_self.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/user/edit_self.html Wed Nov 05 23:38:00 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 %} +{% load forms_helpers %} +{% block page_title %}User Profile{% endblock %} +{% block header_title %} +{% if user %} +Modify Existing User Profile for {{ user.nick_name }} <{{ id.email }}> +{% else %} +Create a New User Profile for <{{ id.email }}> +{% endif %} +{% endblock %} +{% block body %} +

+

+{% block instructions %} +Please use this form to set basic site-wide settings for your participation in Google Open Source Programs. +{% endblock %} +

+
+ + {% field_as_table_row form.nick_name %} + {% field_as_table_row form.link_name %} + + + +
 
+ + + {% block submit_buttons %} + + + {% endblock %} + +
+ + + +
+
+

+{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/user/lookup.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/user/lookup.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,109 @@ +{% 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 %} +{% load forms_helpers %} +{% block body %} +

+

+{% block instructions %} +Please use this form to look up an existing User in Google Open Source Programs. +{% endblock %} +

+
+ +{% if found_user %} +{% readonly_field_as_table_row "Id" found_user.id %} +{% endif %} +{% if email_error %} + + + + +{% endif %} + {% field_as_table_row form.id %} +{% if link_name_error %} + + + + +{% endif %} + {% field_as_table_row form.link_name %} +{% if found_user %} + + + + + + + + + + + + + + {% if found_user.former_ids %} + + + + + + + {% endif %} +{% endif %} + + + + + + + + +{% if edit_link %} + + + + + + +{% endif %} +{% if lookup_link %} + + + + + + +{% endif %} +
  + {{ email_error }} +
  + {{ link_name_error }} +
Nick name{{ found_user.nick_name }}  
Is Developer{{ found_user.is_developer }}  
Former ids + {% for former_id in found_user.former_ids %} + {{ former_id }}
+ {% endfor %} +
  
 
+ +   + {% if lookup_message %}{{ lookup_message }}{% else %} {% endif %} +
 
+ Edit the User profile of {{ found_user.nick_name }}. +
 
+ The specified User was not found, but similar + Users are listed here. +
+
+

+{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/templates/soc/user/public.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/user/public.html Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,27 @@ +{% 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 %} +{% load forms_helpers %} +{% block page_title %}User Public Profile{% endblock %} +{% block header_title %} +User Public Profile for {{ link_name_user.nick_name }} +{% endblock %} +{% block body %} +

+ + {% readonly_field_as_table_row link_name_user.fields.nick_name.label link_name_user.nick_name %} + {% readonly_field_as_table_row link_name_user.fields.link_name.label link_name_user.link_name %} +
+

+{% endblock %} diff -r 31927f21970d -r 0b479d573a4c app/soc/views/helper/access.py --- a/app/soc/views/helper/access.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/views/helper/access.py Wed Nov 05 23:38:00 2008 +0000 @@ -47,7 +47,7 @@ 'Please sign in to continue.') DEF_NO_USER_LOGIN_MSG_FMT = ugettext_lazy( - 'Please create User Profile' + 'Please create User Profile' ' in order to view this page.') DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext_lazy( diff -r 31927f21970d -r 0b479d573a4c app/soc/views/models/base.py --- a/app/soc/views/models/base.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/views/models/base.py Wed Nov 05 23:38:00 2008 +0000 @@ -55,7 +55,7 @@ ' Create ' 'a New %(entity_type)s page.') - def __init__(self, params=None, rights=None): + def __init__(self, params=None, rights=None, stop=False): """ Args: @@ -104,6 +104,10 @@ context['page'] = page entity = None + if not all(kwargs.values()): + #TODO: Change this into a proper redirect + return http.HttpResponseRedirect('/') + try: key_fields = self._logic.getKeyFieldsFromDict(kwargs) entity = self._logic.getIfFields(key_fields) @@ -111,9 +115,7 @@ template = self._params['public_template'] return simple.errorResponse(request, page, error, template, context) - if not entity: - #TODO: Change this into a proper redirect - return http.HttpResponseRedirect('/') + self._public(request, entity, context) context['entity'] = entity context['entity_type'] = self._params['name'] @@ -331,7 +333,18 @@ fields: the new field values """ - raise NotImplementedError + pass + + def _public(self, request, entity, context): + """Performs any required processing to get an entities public page + + Args: + request: the django request object + entity: the entity to make public + context: the context object + """ + + pass def _editGet(self, request, entity, form): """Performs any required processing on the form to get its edit page diff -r 31927f21970d -r 0b479d573a4c app/soc/views/models/home_settings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/models/home_settings.py Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,184 @@ +#!/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. + +"""Views for Home Settings. +""" + +__authors__ = [ + '"Sverre Rabbelier" ', + ] + + +from google.appengine.ext import db +from google.appengine.api import users + +from django import forms +from django.utils.translation import ugettext_lazy + +from soc.logic import dicts +from soc.logic import validate +from soc.views import helper +from soc.views.helper import widgets +from soc.views.models import base + +import soc.models.home_settings +import soc.logic.models.home_settings +import soc.logic.dicts +import soc.views.helper +import soc.views.helper.widgets + + +class SettingsValidationForm(helper.forms.BaseForm): + """Django form displayed when creating or editing Settings. + + This form includes validation functions for Settings fields. + """ + + # TODO(tlarsen): partial_path will be a hard-coded read-only + # field for some (most?) User Roles + doc_partial_path = forms.CharField(required=False, + label=soc.models.work.Work.partial_path.verbose_name, + help_text=soc.models.work.Work.partial_path.help_text) + + # TODO(tlarsen): actually, using these two text fields to specify + # the Document is pretty cheesy; this needs to be some much better + # Role-scoped Document selector that we don't have yet + doc_link_name = forms.CharField(required=False, + label=soc.models.work.Work.link_name.verbose_name, + help_text=soc.models.work.Work.link_name.help_text) + + 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 + + +class CreateForm(SettingsValidationForm): + """Django form displayed when creating or editing 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.home_settings.HomeSettings + + #: list of model fields which will *not* be gathered by the form + exclude = ['inheritance_line', 'home'] + + +class EditForm(CreateForm): + """Django form displayed a Document is edited. + """ + + pass + + +class View(base.View): + """View methods for the Docs model + """ + + def __init__(self, original_params=None, original_rights=None, stop=False): + """Defines the fields and methods required for the base View class + to provide the user with list, public, create, edit and delete views. + + Params: + original_params: a dict with params for this View + original_rights: a dict with right definitions for this View + """ + + params = {} + rights = {} + + params['name'] = "HomeSetting" + params['name_short'] = "Home" + params['name_plural'] = "HomeSettings" + + params['edit_form'] = EditForm + params['create_form'] = CreateForm + + # TODO(tlarsen) Add support for Django style template lookup + params['edit_template'] = 'soc/models/edit.html' + params['public_template'] = 'soc/home_settings/public.html' + params['list_template'] = 'soc/models/list.html' + + params['lists_template'] = { + 'list_main': 'soc/list/list_main.html', + 'list_pagination': 'soc/list/list_pagination.html', + 'list_row': 'soc/home_settings/list/home_row.html', + 'list_heading': 'soc/home_settings/list/home_heading.html', + } + + params['delete_redirect'] = 'home/list' + params['create_redirect'] = 'home/edit' + + params['save_message'] = [ugettext_lazy('Profile saved.')] + + params['edit_params'] = { + self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED, + } + + rights['list'] = [helper.access.checkIsDeveloper] + rights['delete'] = [helper.access.checkIsDeveloper] + + params = dicts.merge(original_params, params) + rights = dicts.merge(original_rights, rights) + + base.View.__init__(self, rights=rights, params=params, stop=stop) + + self._logic = soc.logic.models.home_settings.logic + + def _public(self, request, entity, context): + """ + """ + + if not entity: + return + + try: + home_doc = entity.home + except db.Error: + home_doc = None + + if home_doc: + home_doc.content = helper.templates.unescape(home_doc.content) + context['home_document'] = home_doc + + def _editGet(self, request, entity, form): + """See base.View._editGet(). + """ + + try: + form.fields['doc_partial_path'].initial = entity.home.partial_path + form.fields['doc_link_name'].initial = entity.home.link_name + except db.Error: + pass + + +view = View() + +create = view.create +edit = view.edit +delete = view.delete +list = view.list +public = view.public diff -r 31927f21970d -r 0b479d573a4c app/soc/views/models/site_settings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/models/site_settings.py Wed Nov 05 23:38:00 2008 +0000 @@ -0,0 +1,144 @@ +#!/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. + +"""Views for Site Settings. +""" + +__authors__ = [ + '"Sverre Rabbelier" ', + ] + + +from google.appengine.ext import db +from google.appengine.api import users + +from django import forms +from django.utils.translation import ugettext_lazy + +from soc.logic import dicts +from soc.logic import validate +from soc.views import helper +from soc.views.helper import widgets +from soc.views.models import home_settings + +import soc.models.site_settings +import soc.logic.models.site_settings +import soc.logic.dicts +import soc.views.helper +import soc.views.helper.widgets + + +class CreateForm(home_settings.SettingsValidationForm): + """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'] + + +class EditForm(CreateForm): + """Django form displayed a Document is edited. + """ + + pass + + +class View(home_settings.View): + """View methods for the Docs model + """ + + def __init__(self, original_params=None, original_rights=None): + """Defines the fields and methods required for the base View class + to provide the user with list, public, create, edit and delete views. + + Params: + original_params: a dict with params for this View + original_rights: a dict with right definitions for this View + """ + + params = {} + rights = {} + + params['name'] = "SiteSetting" + params['name_short'] = "Site" + params['name_plural'] = "SiteSettings" + + params['edit_form'] = EditForm + params['create_form'] = CreateForm + + params['lists_template'] = { + 'list_main': 'soc/list/list_main.html', + 'list_pagination': 'soc/list/list_pagination.html', + 'list_row': 'soc/site_settings/list/site_row.html', + 'list_heading': 'soc/site_settings/list/site_heading.html', + } + + params['delete_redirect'] = 'site/list' + params['create_redirect'] = 'site/edit' + + params = dicts.merge(original_params, params) + rights = dicts.merge(original_rights, rights) + + home_settings.View.__init__(self, original_rights=rights, original_params=params, stop=True) + + self._logic = soc.logic.models.site_settings.logic + + def main_public(self, request, page=None, **kwargs): + """Displays the main site settings page + + Args: + request: the standard Django HTTP request object + page: a soc.logic.site.page.Page object + kwargs: not used + """ + + keys = self._logic.getKeyFieldNames() + values = self._logic.getMainKeyValues() + key_values = dicts.zip(keys, values) + + return self.public(request, page, **key_values) + + def main_edit(self, request, page=None, **kwargs): + """Displays the edit page for the main site settings page + + Args: + request: the standard Django HTTP request object + page: a soc.logic.site.page.Page object + kwargs: not used + """ + + keys = self._logic.getKeyFieldNames() + values = self._logic.getMainKeyValues() + key_values = dicts.zip(keys, values) + + return self.edit(request, page, **key_values) + + +view = View() + +create = view.create +edit = view.edit +delete = view.delete +list = view.list +public = view.public +main_public = view.main_public +main_edit = view.main_edit diff -r 31927f21970d -r 0b479d573a4c app/soc/views/user/profile.py --- a/app/soc/views/user/profile.py Wed Nov 05 23:36:28 2008 +0000 +++ b/app/soc/views/user/profile.py Wed Nov 05 23:38:00 2008 +0000 @@ -68,7 +68,7 @@ return link_name -DEF_USER_PROFILE_EDIT_TMPL = 'soc/user/profile/edit.html' +DEF_USER_PROFILE_EDIT_TMPL = 'soc/user/edit_self.html' SUBMIT_MSG_PARAM_NAME = 's'