# HG changeset patch # User Sverre Rabbelier # Date 1233174075 0 # Node ID c532dd9def48587890722ea6a54ad2315ea94d99 # Parent 77aab03aa693bdf945dae373af6e9c44e9dee584 Create a new Tossed layer in the MVC Also move is_enabled to program instead of presence. Patch by: Sverre Rabbelier diff -r 77aab03aa693 -r c532dd9def48 app/soc/logic/models/program.py --- a/app/soc/logic/models/program.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/logic/models/program.py Wed Jan 28 20:21:15 2009 +0000 @@ -23,15 +23,15 @@ ] -from soc.logic.models import base -from soc.logic.models import sponsor as sponsor_logic +from soc.logic.models import tossed +from soc.logic.models import tossed as tossed_logic import gsoc.logic.models.timeline import soc.logic.models.timeline import soc.models.program -class Logic(base.Logic): +class Logic(tossed.Logic): """Logic methods for the Program model. """ @@ -39,7 +39,7 @@ 'ghop' : soc.logic.models.timeline.logic} def __init__(self, model=soc.models.program.Program, - base_model=None, scope_logic=sponsor_logic): + base_model=None, scope_logic=tossed_logic): """Defines the name, key_name and model for this entity. """ diff -r 77aab03aa693 -r c532dd9def48 app/soc/logic/models/site.py --- a/app/soc/logic/models/site.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/logic/models/site.py Wed Jan 28 20:21:15 2009 +0000 @@ -22,20 +22,20 @@ ] -from soc.logic.models import presence +from soc.logic.models import tossed -import soc.models.presence +import soc.models.tossed import soc.models.site -class Logic(presence.Logic): +class Logic(tossed.Logic): """Logic methods for the Site model. """ DEF_SITE_LINK_ID = 'site' def __init__(self, model=soc.models.site.Site, - base_model=soc.models.presence.Presence): + base_model=soc.models.tossed.Tossed): """Defines the name, key_name and model for this entity. """ diff -r 77aab03aa693 -r c532dd9def48 app/soc/logic/models/tossed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/logic/models/tossed.py Wed Jan 28 20:21:15 2009 +0000 @@ -0,0 +1,44 @@ +#!/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. + +"""Tossed (Model) query functions. +""" + +__authors__ = [ + '"Sverre Rabbelier" ', + ] + + +from soc.logic.models import presence +from soc.logic.models import presence as presence_logic + +import soc.models.tossed + + +class Logic(presence.Logic): + """Logic methods for the Tossed model. + """ + + def __init__(self, model=soc.models.tossed.Tossed, + base_model=None, scope_logic=presence_logic): + """Defines the name, key_name and model for this entity. + """ + + super(Logic, self).__init__(model=model, base_model=base_model, + scope_logic=scope_logic) + + +logic = Logic() diff -r 77aab03aa693 -r c532dd9def48 app/soc/models/presence.py --- a/app/soc/models/presence.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/models/presence.py Wed Jan 28 20:21:15 2009 +0000 @@ -57,18 +57,3 @@ feed_url.help_text = ugettext( 'The URL should be a valid ATOM or RSS feed. ' 'Feed entries are shown on the home page.') - - #: Reference to Document containing optional Terms of Service - tos = db.ReferenceProperty( - reference_class=soc.models.document.Document, - verbose_name=ugettext('Terms of Service'), - collection_name='tos') - tos.help_text = ugettext( - 'Document containing optional Terms of Service for participating.') - tos.redirect_url = soc.models.document.Document.URL_NAME - - is_enabled = db.BooleanProperty( - verbose_name=ugettext('Is Enabled')) - is_enabled.help_text = ugettext( - 'Field used to indicate if a Presence is enabled at all, and as such' - ' accessible to non-developers.') diff -r 77aab03aa693 -r c532dd9def48 app/soc/models/program.py --- a/app/soc/models/program.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/models/program.py Wed Jan 28 20:21:15 2009 +0000 @@ -26,11 +26,11 @@ from django.utils.translation import ugettext -import soc.models.presence +import soc.models.tossed import soc.models.timeline -class Program(soc.models.presence.Presence): +class Program(soc.models.tossed.Tossed): """The Program model, representing a Program ran by a Sponsor. """ @@ -99,3 +99,10 @@ timeline = db.ReferenceProperty(reference_class=soc.models.timeline.Timeline, required=True, collection_name="program", verbose_name=ugettext('Timeline')) + + #: Whether the program is enabled + is_enabled = db.BooleanProperty(default=False, + verbose_name=ugettext('Is Enabled')) + is_enabled.help_text = ugettext( + 'Field used to indicate if a Presence is enabled at all, and as such' + ' accessible to non-developers.') diff -r 77aab03aa693 -r c532dd9def48 app/soc/models/site.py --- a/app/soc/models/site.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/models/site.py Wed Jan 28 20:21:15 2009 +0000 @@ -26,10 +26,10 @@ from django.utils.translation import ugettext -import soc.models.presence +import soc.models.tossed -class Site(soc.models.presence.Presence): +class Site(soc.models.tossed.Tossed): """Model of a Site, which stores per site configuration. The Site Model stores configuration information unique to the Melange diff -r 77aab03aa693 -r c532dd9def48 app/soc/models/tossed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/models/tossed.py Wed Jan 28 20:21:15 2009 +0000 @@ -0,0 +1,42 @@ +#!/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. + +"""This module contains the Tossed Model. +""" + +__authors__ = [ + '"Sverre Rabbelier" ', +] + +from google.appengine.ext import db + +from django.utils.translation import ugettext + +import soc.models.presence + + +class Tossed(soc.models.presence.Presence): + """Model of a Presence that has a Terms of Service. + """ + + #: Reference to Document containing optional Terms of Service + tos = db.ReferenceProperty( + reference_class=soc.models.document.Document, + verbose_name=ugettext('Terms of Service'), + collection_name='tos') + tos.help_text = ugettext( + 'Document containing optional Terms of Service for participating.') + tos.redirect_url = soc.models.document.Document.URL_NAME diff -r 77aab03aa693 -r c532dd9def48 app/soc/views/models/presence.py --- a/app/soc/views/models/presence.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/views/models/presence.py Wed Jan 28 20:21:15 2009 +0000 @@ -66,15 +66,10 @@ new_params['home_template'] = 'soc/presence/home.html' new_params['create_extra_dynafields'] = { - # override some editors 'home_link_id': forms.CharField(required=False, label=ugettext('Home page Document link ID'), help_text=soc.models.work.Work.link_id.help_text), - 'tos_link_id': forms.CharField(required=False, - label=ugettext('Terms of Service Document link ID'), - help_text=soc.models.work.Work.link_id.help_text), - # add cleaning of the link id and feed url 'clean_link_id': cleaning.clean_link_id, 'clean_feed_url': cleaning.clean_feed_url, @@ -135,12 +130,6 @@ except db.Error: pass - try: - if entity.tos: - form.fields['tos_link_id'].initial = entity.tos.link_id - except db.Error: - pass - super(View, self)._editGet(request, entity, form) def _editPost(self, request, entity, fields): @@ -157,12 +146,4 @@ fields['home'] = home_doc - tos_link_id = fields['tos_link_id'] - - # TODO notify the user if tos_doc is not found - tos_doc = document_logic.logic.getFromFields( - scope_path=scope_path, link_id=tos_link_id) - - fields['tos'] = tos_doc - super(View, self)._editPost(request, entity, fields) diff -r 77aab03aa693 -r c532dd9def48 app/soc/views/models/program.py --- a/app/soc/views/models/program.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/views/models/program.py Wed Jan 28 20:21:15 2009 +0000 @@ -33,7 +33,7 @@ from soc.views.helper import decorators from soc.views.helper import redirects from soc.views.helper import widgets -from soc.views.models import presence +from soc.views.models import tossed from soc.views.models import document as document_view from soc.views.models import sponsor as sponsor_view from soc.views.sitemap import sidebar @@ -41,7 +41,7 @@ import soc.logic.models.program -class View(presence.View): +class View(tossed.View): """View methods for the Program model. """ diff -r 77aab03aa693 -r c532dd9def48 app/soc/views/models/site.py --- a/app/soc/views/models/site.py Wed Jan 28 18:24:20 2009 +0000 +++ b/app/soc/views/models/site.py Wed Jan 28 20:21:15 2009 +0000 @@ -27,14 +27,14 @@ from soc.logic import dicts from soc.views.helper import access from soc.views.models import document as document_view -from soc.views.models import presence +from soc.views.models import tossed import soc.models.site import soc.logic.models.site import soc.logic.dicts -class View(presence.View): +class View(tossed.View): """View methods for the Document model. """ diff -r 77aab03aa693 -r c532dd9def48 app/soc/views/models/tossed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/models/tossed.py Wed Jan 28 20:21:15 2009 +0000 @@ -0,0 +1,90 @@ +#!/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 Tossed. +""" + +__authors__ = [ + '"Sverre Rabbelier" ', + ] + + +from google.appengine.ext import db + +from django import forms +from django.utils.translation import ugettext + +from soc.logic import dicts +from soc.logic.models import document as document_logic +from soc.views.models import presence + +import soc.logic.models.tossed +import soc.models.work + + +class View(presence.View): + """View methods for the Tossed model. + """ + + def __init__(self, params=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: + params: a dict with params for this View + """ + + new_params = {} + new_params['logic'] = soc.logic.models.tossed.logic + + new_params['create_extra_dynafields'] = { + 'tos_link_id': forms.CharField(required=False, + label=ugettext('Terms of Service Document link ID'), + help_text=soc.models.work.Work.link_id.help_text), + } + + params = dicts.merge(params, new_params, sub_merge=True) + + super(View, self).__init__(params=params) + + def _editGet(self, request, entity, form): + """See base.View._editGet(). + """ + + try: + if entity.tos: + form.fields['tos_link_id'].initial = entity.tos.link_id + except db.Error: + pass + + super(View, self)._editGet(request, entity, form) + + def _editPost(self, request, entity, fields): + """See base.View._editPost(). + """ + + key_fields = self._logic.getKeyFieldsFromDict(fields) + scope_path = self._logic.getKeyNameForFields(key_fields) + + tos_link_id = fields['tos_link_id'] + + # TODO notify the user if tos_doc is not found + tos_doc = document_logic.logic.getFromFields( + scope_path=scope_path, link_id=tos_link_id) + + fields['tos'] = tos_doc + + super(View, self)._editPost(request, entity, fields)