Added programs
authorSverre Rabbelier <srabbelier@gmail.com>
Mon, 01 Dec 2008 21:38:25 +0000
changeset 643 b57d538a9dd3
parent 642 671dc971c3d1
child 644 813892c894f4
Added programs Currently the programs are somewhat of empty, but due to the ease with which we can add new fields later, it is acceptable to commit it in it's current form. Patch by: Sverre Rabbelier
app/soc/logic/models/program.py
app/soc/models/program.py
app/soc/templates/soc/program/list/heading.html
app/soc/templates/soc/program/list/row.html
app/soc/templates/soc/program/public.html
app/soc/views/helper/redirects.py
app/soc/views/models/program.py
app/soc/views/sitemap/build.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/program.py	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,40 @@
+#!/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.
+
+"""Program (Model) query functions.
+"""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+from soc.logic.models import base
+
+import soc.models.program
+
+
+class Logic(base.Logic):
+  """Logic methods for the Document model
+  """
+
+  def __init__(self, model=soc.models.program.Program, base_model=None):
+    """Defines the name, key_name and model for this entity.
+    """
+    super(Logic, self).__init__(model=model, base_model=base_model)
+
+
+logic = Logic()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/program.py	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,33 @@
+#!/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 Program Model."""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+]
+
+
+from django.utils.translation import ugettext_lazy
+
+import soc.models.presence
+
+
+class Program(soc.models.presence.Presence):
+  """The Program model, representing a Program ran by a Sponsor
+  """
+
+  pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/program/list/heading.html	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,4 @@
+<tr align="left">
+  <th>Program Name</th>
+  <th>Organization</th>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/program/list/row.html	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,10 @@
+<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
+onclick="document.location.href='{{ list.redirect }}'" name="link_id">
+  <td align="right">
+   <div class="title">
+    <a class="noul"
+     href="{{ list.redirect }}">{{ list.item.link_id }}</a>
+   </div>
+  </td>
+  <td><div class="scope_path">{{ list.item.scope_path}}</div></td>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/program/public.html	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,29 @@
+{% 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_name }} for {{ entity.link_id }}
+{% endblock %}
+
+{% block body %}
+<p>
+ <table>
+  {% readonly_field_as_table_row entity.fields.link_id.label entity.link_id %}
+  {% readonly_field_as_table_row entity.fields.scope_path.label entity.scope_path %}
+  <!-- TODO(pawel.solyga) make this generic -->
+ </table>
+</p>
+{% endblock %}
--- a/app/soc/views/helper/redirects.py	Mon Dec 01 21:37:27 2008 +0000
+++ b/app/soc/views/helper/redirects.py	Mon Dec 01 21:38:25 2008 +0000
@@ -31,6 +31,14 @@
   
   return result
 
+def getCreateProgramRedirect(entity, params):
+  """Returns the create program redirect for the specified entity.
+  """
+
+  result ='/%s/create/%s' % (
+     params['url_name'], entity.link_id)
+
+  return result
 
 def getEditRedirect(entity, params):
   """Returns the edit redirect for the specified entity.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/program.py	Mon Dec 01 21:38:25 2008 +0000
@@ -0,0 +1,160 @@
+#!/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 Programs.
+"""
+
+__authors__ = [
+    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+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 cleaning
+from soc.logic.models import sponsor as sponsor_logic
+from soc.views.helper import redirects
+from soc.views.models import base
+from soc.views.models import sponsor as sponsor_view
+from soc.views import helper
+
+import soc.logic.models.program
+
+
+class View(base.View):
+  """View methods for the Sponsor model.
+  """
+
+  DEF_CREATE_INSTRUCTION_MSG_FMT = ugettext_lazy(
+      'Please use this form to select a Sponsor for the new Program')
+
+  def __init__(self, original_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:
+      original_params: a dict with params for this View 
+    """    
+
+    params = {}
+    params['logic'] = soc.logic.models.program.logic
+
+    params['name'] = "Program"
+    params['name_short'] = "Program"
+    params['name_plural'] = "Programs"
+    params['url_name'] = "program"
+    params['module_name'] = "program"
+
+    params['extra_dynaexclude'] = ['home']
+    params['create_extra_dynafields'] = {
+        'scope_path': forms.CharField(widget=forms.HiddenInput,
+                                   required=False),
+         'clean_link_id': cleaning.clean_link_id,
+        }
+
+    params = dicts.merge(original_params, params)
+
+    base.View.__init__(self, params=params)
+
+  def create(self, request, page_name=None, params=None, **kwargs):
+    """Specialized create view to enforce needing a scope_path
+
+    This view simply gives control to the base.View.create if the
+    scope_path is specified in kwargs. If it is not present, it
+    instead displays the result of self.selectSponsor. Refer to the
+    respective docstrings on what they do.
+
+    Args: 
+      see base.View.create
+    """
+
+    if 'scope_path' in kwargs:
+      return super(View, self).create(request, page_name=page_name,
+          params=params, **kwargs)
+
+    params = dicts.merge(params, self._params)
+    return self.selectSponsor(request, page_name, params)
+
+  def selectSponsor(self, request, page_name, params):
+    """Displays a list page allowing the user to select a Sponsor
+
+    After having selected the Sponsor, the user is redirected to the
+    'create a new program' page with the scope_path set appropriately.
+
+    Params usage:
+      The params dictionary is passed to getCreateProgramRedirect from
+        the redirects module, please see the docstring for
+        getCreateProgramRedirect on how it uses it.
+      The params dictionary is also passed to getListContent from
+        the helper.list module, please refer to its docstring also.
+      The params dictionary is passed to self._list as well, refer
+        to its docstring for details on how it uses it.
+
+    Args:
+      request: the standard Django HTTP request object
+      page_name: the page name displayed in templates as page and header title
+      params: a dict with params for this View
+    """
+
+    new_params = {}
+    new_params['list_action'] = (redirects.getCreateProgramRedirect, params)
+    new_params['instruction_text'] = \
+        self.DEF_CREATE_INSTRUCTION_MSG_FMT % self._params
+
+    params = dicts.merge(new_params, params)
+    params = dicts.merge(params, sponsor_view.view._params)
+
+    content = helper.lists.getListContent(request, params, sponsor_logic.logic)
+    contents = [content]
+
+    return self._list(request, params, contents, page_name)
+
+  def _editGet(self, request, entity, form):
+    """See base.View._editGet().
+    """
+
+    # fill in the email field with the data from the entity
+    form.fields['scope_path'].initial = entity.scope_path
+
+  def getDjangoURLPatterns(self, params=None):
+    """See base.View.getDjangoURLPatterns().
+    """
+
+    default_patterns = self._params['django_patterns_defaults']
+    default_patterns += [
+        (r'^%(url_name)s/create/(?P<scope_path>%(ulnp)s)$',
+            'soc.views.models.%s.create', 'Create %(name_short)s')]
+
+    params = {}
+    params['django_patterns_defaults'] = default_patterns
+
+    params = dicts.merge(params, self._params)
+    patterns = super(View, self).getDjangoURLPatterns(params)
+
+    return patterns
+
+
+view = View()
+
+create = view.create
+delete = view.delete
+edit = view.edit
+list = view.list
+public = view.public
--- a/app/soc/views/sitemap/build.py	Mon Dec 01 21:37:27 2008 +0000
+++ b/app/soc/views/sitemap/build.py	Mon Dec 01 21:38:25 2008 +0000
@@ -32,6 +32,7 @@
 from soc.views.models import user_self
 from soc.views.models import site
 from soc.views.models import sponsor
+from soc.views.models import program
 
 from soc.views.sitemap import sidebar
 from soc.views.sitemap import sitemap
@@ -45,6 +46,7 @@
 sidebar.addMenu(sponsor.view.getSidebarLinks)
 sidebar.addMenu(host.view.getSidebarLinks)
 sidebar.addMenu(request.view.getSidebarLinks)
+sidebar.addMenu(program.view.getSidebarLinks)
 
 sitemap.addPages(presence.view.getDjangoURLPatterns())
 sitemap.addPages(site.view.getDjangoURLPatterns())
@@ -54,6 +56,7 @@
 sitemap.addPages(sponsor.view.getDjangoURLPatterns())
 sitemap.addPages(host.view.getDjangoURLPatterns())
 sitemap.addPages(request.view.getDjangoURLPatterns())
+sitemap.addPages(program.view.getDjangoURLPatterns())
 
 
 def getPatterns():