Presence is now a 'abstract' View, pull in members from program
authorSverre Rabbelier <srabbelier@gmail.com>
Thu, 22 Jan 2009 16:04:48 +0000
changeset 901 d580a057103d
parent 900 0b416bb14970
child 902 0cc7a76f0eb3
Presence is now a 'abstract' View, pull in members from program This is signified by the removal of params['name'] and other values that are required by params.py, but also by the removal of the 'view' definition at the bottom of the file. Patch by: Sverre Rabbelier
app/soc/views/models/presence.py
app/soc/views/models/program.py
app/soc/views/models/site.py
app/soc/views/sitemap/build.py
--- a/app/soc/views/models/presence.py	Thu Jan 22 16:03:17 2009 +0000
+++ b/app/soc/views/models/presence.py	Thu Jan 22 16:04:48 2009 +0000
@@ -27,6 +27,7 @@
 from django import forms
 from django.utils.translation import ugettext_lazy
 
+from soc.logic import cleaning
 from soc.logic import dicts
 from soc.logic import validate
 from soc.logic.models import document as document_logic
@@ -42,79 +43,6 @@
 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): scope_path will be a hard-coded read-only
-  #   field for some (most?) User Roles
-  home_scope_path = forms.CharField(required=False,
-      label=ugettext_lazy('home page Document scope path'),
-      help_text=soc.models.work.Work.scope_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.  See:
-  #     http://code.google.com/p/soc/issues/detail?id=151
-  home_link_id = forms.CharField(required=False,
-      label=ugettext_lazy('home page Document link ID'),
-      help_text=soc.models.work.Work.link_id.help_text)
-
-  # TODO(tlarsen): scope_path will be a hard-coded read-only
-  #   field for some (most?) User Roles
-  tos_scope_path = forms.CharField(required=False,
-      label=ugettext_lazy('Terms of Service Document scope path'),
-      help_text=soc.models.work.Work.scope_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
-  #   See:
-  #     http://code.google.com/p/soc/issues/detail?id=151
-  tos_link_id = forms.CharField(required=False,
-      label=ugettext_lazy('Terms of Service Document link ID'),
-      help_text=soc.models.work.Work.link_id.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.presence.Presence
-
-    #: list of model fields which will *not* be gathered by the form
-    exclude = ['scope',
-      # TODO(tlarsen): this needs to be enabled once a button to a list
-      #   selection "interstitial" page is implemented, see:
-      #     http://code.google.com/p/soc/issues/detail?id=151
-      'home', 'tos']
-
-
-class EditForm(CreateForm):
-  """Django form displayed a Document is edited.
-  """
-
-  pass
-
-
 class View(base.View):
   """View methods for the Presence model.
   """
@@ -127,25 +55,26 @@
       params: a dict with params for this View
     """
 
-    rights = {}
-    rights['any_access'] = [access.allow]
-    rights['show'] = [access.allow]
+    new_params = {}
+
+    new_params['extra_dynaexclude'] = ['home', 'tos']
 
-    new_params = {}
-    new_params['logic'] = soc.logic.models.presence.logic
-    new_params['rights'] = rights
+    new_params['create_extra_dynafields'] = {
+        # override some editors
+        'home_link_id': forms.CharField(required=False,
+            label=ugettext_lazy('Home page Document link ID'),
+            help_text=soc.models.work.Work.link_id.help_text),
 
-    new_params['name'] = "Home Settings"
-    new_params['url_name'] = "home/settings"
-    new_params['module_name'] = "presence"
+        'tos_link_id': forms.CharField(required=False,
+            label=ugettext_lazy('Terms of Service Document link ID'),
+            help_text=soc.models.work.Work.link_id.help_text),
 
-    new_params['edit_form'] = EditForm
-    new_params['create_form'] = CreateForm
+        # add cleaning of the link id and feed url
+        'clean_link_id': cleaning.clean_link_id,
+        'clean_feed_url': cleaning.clean_feed_url,
+        }
 
-    # Disable the presence sidebar until we have some use for it
-    new_params['sidebar_defaults'] = []
-
-    params = dicts.merge(params, new_params)
+    params = dicts.merge(params, new_params, sub_merge=True)
 
     super(View, self).__init__(params=params)
 
@@ -171,11 +100,12 @@
 
     try:
       if entity.home:
-        form.fields['home_scope_path'].initial = entity.home.scope_path
         form.fields['home_link_id'].initial = entity.home.link_id
+    except db.Error:
+      pass
 
+    try:
       if entity.tos:
-        form.fields['tos_scope_path'].initial = entity.tos.scope_path
         form.fields['tos_link_id'].initial = entity.tos.link_id
     except db.Error:
       pass
@@ -186,33 +116,21 @@
     """See base.View._editPost().
     """
 
-    home_scope_path = fields['home_scope_path']
+    scope_path = entity.key().name()
     home_link_id = fields['home_link_id']
 
     # TODO notify the user if home_doc is not found
     home_doc = document_logic.logic.getFromFields(
-      scope_path=home_scope_path, link_id=home_link_id)
+      scope_path=scope_path, link_id=home_link_id)
 
     fields['home'] = home_doc
 
-    tos_scope_path = fields['tos_scope_path']
     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=tos_scope_path, link_id=tos_link_id)
+      scope_path=scope_path, link_id=tos_link_id)
 
     fields['tos'] = tos_doc
 
     super(View, self)._editPost(request, entity, fields)
-
-
-view = View()
-
-create = view.create
-edit = view.edit
-delete = view.delete
-list = view.list
-public = view.public
-export = view.export
-
--- a/app/soc/views/models/program.py	Thu Jan 22 16:03:17 2009 +0000
+++ b/app/soc/views/models/program.py	Thu Jan 22 16:04:48 2009 +0000
@@ -25,14 +25,13 @@
 
 from django import forms
 
-from soc.logic import cleaning
 from soc.logic import dicts
 from soc.logic.models import program as program_logic
 from soc.views import helper
 from soc.views.helper import access
 from soc.views.helper import redirects
 from soc.views.helper import widgets
-from soc.views.models import base
+from soc.views.models import presence
 from soc.views.models import document as document_view
 from soc.views.models import sponsor as sponsor_view
 from soc.views.sitemap import sidebar
@@ -40,7 +39,7 @@
 import soc.logic.models.program
 
 
-class View(base.View):
+class View(presence.View):
   """View methods for the Program model.
   """
 
@@ -67,19 +66,16 @@
 
     new_params['edit_template'] = 'soc/program/edit.html'
 
-    new_params['extra_dynaexclude'] = ['timeline',
-      # TODO(tlarsen): these need to be enabled once a button to a list
-      #   selection "interstitial" page is implemented, see:
-      #   http://code.google.com/p/soc/issues/detail?id=151
-      'home', 'tos']
+    new_params['extra_dynaexclude'] = ['timeline']
 
     new_params['create_extra_dynafields'] = {
         'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
             attrs={'rows':10, 'cols':40})),
+
         'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
-        'workflow' : forms.ChoiceField(choices=[('gsoc','Project-based'), 
+
+        'workflow' : forms.ChoiceField(choices=[('gsoc','Project-based'),
             ('ghop','Task-based')], required=True),
-        'clean_link_id': cleaning.clean_link_id,
         }
 
     new_params['edit_extra_dynafields'] = {
@@ -102,6 +98,8 @@
       # use the timeline from the entity
       fields['timeline'] = entity.timeline
 
+    super(View, self)._editPost(request, entity, fields)
+
   def _createTimelineForType(self, fields):
     """Creates and stores a timeline model for the given type of program.
     """
--- a/app/soc/views/models/site.py	Thu Jan 22 16:03:17 2009 +0000
+++ b/app/soc/views/models/site.py	Thu Jan 22 16:04:48 2009 +0000
@@ -34,33 +34,6 @@
 import soc.logic.dicts
 
 
-class CreateForm(presence.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.Site
-
-    #: list of model fields which will *not* be gathered by the form
-    exclude = ['scope', 'scope_path', 'link_id',
-      # TODO(tlarsen): this needs to be enabled once a button to a list
-      #   selection "interstitial" page is implemented, see:
-      #     http://code.google.com/p/soc/issues/detail?id=151
-      'home', 'tos']
-
-  link_id = forms.CharField(widget=forms.HiddenInput)
-
-
-class EditForm(CreateForm):
-  """Django form displayed a Document is edited.
-  """
-
-  pass
-
-
 class View(presence.View):
   """View methods for the Document model.
   """
@@ -87,9 +60,6 @@
     new_params['url_name'] = "site/settings"
     new_params['module_name'] = "site"
 
-    new_params['edit_form'] = EditForm
-    new_params['create_form'] = CreateForm
-
     new_params['sidebar_defaults'] = [('/%s/edit', 'Edit %(name)s', 'edit')]
     new_params['sidebar_heading'] = new_params['name_short']
 
--- a/app/soc/views/sitemap/build.py	Thu Jan 22 16:03:17 2009 +0000
+++ b/app/soc/views/sitemap/build.py	Thu Jan 22 16:04:48 2009 +0000
@@ -31,7 +31,6 @@
 from soc.views.models import host
 from soc.views.models import notification
 from soc.views.models import organization
-from soc.views.models import presence
 from soc.views.models import program
 from soc.views.models import request
 from soc.views.models import site
@@ -45,7 +44,6 @@
 
 
 sidebar.addMenu(user_self.view.getSidebarMenus)
-sidebar.addMenu(presence.view.getSidebarMenus)
 sidebar.addMenu(club.view.getSidebarMenus)
 sidebar.addMenu(club_admin.view.getSidebarMenus)
 sidebar.addMenu(club_app.view.getSidebarMenus)
@@ -66,7 +64,6 @@
 sitemap.addPages(host.view.getDjangoURLPatterns())
 sitemap.addPages(notification.view.getDjangoURLPatterns())
 sitemap.addPages(organization.view.getDjangoURLPatterns())
-sitemap.addPages(presence.view.getDjangoURLPatterns())
 sitemap.addPages(program.view.getDjangoURLPatterns())
 sitemap.addPages(request.view.getDjangoURLPatterns())
 sitemap.addPages(site.view.getDjangoURLPatterns())