Added Club Admin model, logic, and view
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 10 Jan 2009 18:18:10 +0000
changeset 802 95c534d02e39
parent 801 06a84103ed8b
child 803 9d0ed410bfd5
Added Club Admin model, logic, and view Patch by: Sverre Rabbelier
app/soc/logic/models/club_admin.py
app/soc/models/club_admin.py
app/soc/views/helper/access.py
app/soc/views/models/club.py
app/soc/views/models/club_admin.py
app/soc/views/sitemap/build.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/club_admin.py	Sat Jan 10 18:18:10 2009 +0000
@@ -0,0 +1,45 @@
+#!/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.
+
+"""Club Admin (Model) query functions.
+"""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+from soc.logic.models import role
+from soc.logic.models import club as club_logic
+
+import soc.models.club_admin
+import soc.models.role
+
+
+class Logic(role.Logic):
+  """Logic methods for the Club Admin model.
+  """
+
+  def __init__(self, model=soc.models.club_admin.ClubAdmin,
+               base_model=soc.models.role.Role, scope_logic=club_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()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/club_admin.py	Sat Jan 10 18:18:10 2009 +0000
@@ -0,0 +1,39 @@
+#!/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 Club Admin Model."""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.role
+import soc.models.club
+
+
+class ClubAdmin(soc.models.role.Role):
+  """Admin for a specific Club.
+  """
+
+  #: A many:1 relationship associating Admins with specific Club
+  #: details and capabilities. The back-reference in the Club model
+  #: is a Query named 'admins'.
+  org = db.ReferenceProperty(
+      reference_class=soc.models.club.Club,
+      required=True, collection_name='admins')
--- a/app/soc/views/helper/access.py	Sat Jan 10 18:17:44 2009 +0000
+++ b/app/soc/views/helper/access.py	Sat Jan 10 18:18:10 2009 +0000
@@ -321,6 +321,25 @@
 
   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
 
+def checkIsApplied(request):
+  """Returns an alternate HTTP response if Google Account has no Club App
+     entity for the specified Club.
+
+  Args:
+    request: a Django HTTP request
+
+   Raises:
+     AccessViolationResponse: if the required authorization is not met
+
+  Returns:
+    None if Club App  exists for the specified program, or a subclass
+    of django.http.HttpResponse which contains the alternate response
+    should be returned by the calling view.
+  """
+
+  #TODO(srabbelier): implement this
+  pass
+
 def checkIsMyNotification(request):
   """Returns an alternate HTTP response if this request is for a Notification belonging
      to the current user.
--- a/app/soc/views/models/club.py	Sat Jan 10 18:17:44 2009 +0000
+++ b/app/soc/views/models/club.py	Sat Jan 10 18:18:10 2009 +0000
@@ -31,6 +31,7 @@
 from soc.logic.models import user as user_logic
 from soc.logic.models import group_app as group_app_logic
 from soc.logic.models import club as club_logic
+from soc.views.helper import access
 from soc.views.helper import widgets
 from soc.views.models import base
 
@@ -49,9 +50,12 @@
       params: a dict with params for this View
     """
 
+    rights = {}
+    rights['create'] = [access.checkIsApplied]
+
     new_params = {}
-    
     new_params['logic'] = soc.logic.models.club.logic
+    new_params['rights'] = rights
 
     new_params['name'] = "Club"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/club_admin.py	Sat Jan 10 18:18:10 2009 +0000
@@ -0,0 +1,70 @@
+#!/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 Club Admins.
+"""
+
+__authors__ = [
+    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+from django import forms
+
+from soc.logic import cleaning
+from soc.logic import dicts
+from soc.views.helper import redirects
+from soc.views.models import base
+from soc.views.models import club as club_view
+
+import soc.logic.models.club_admin
+
+
+class View(base.View):
+  """View methods for the Program 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.club_admin.logic
+
+    new_params['scope_view'] = club_view
+    new_params['scope_redirect'] = redirects.getCreateRedirect
+
+    new_params['name'] = "Club Admin"
+
+    new_params['extra_dynaexclude'] = ['user', 'org']
+
+    params = dicts.merge(params, new_params)
+
+    super(View, self).__init__(params=params)
+
+
+
+view = View()
+
+create = view.create
+delete = view.delete
+edit = view.edit
+list = view.list
+public = view.public
--- a/app/soc/views/sitemap/build.py	Sat Jan 10 18:17:44 2009 +0000
+++ b/app/soc/views/sitemap/build.py	Sat Jan 10 18:18:10 2009 +0000
@@ -26,6 +26,7 @@
 
 from soc.views.models import club
 from soc.views.models import club_app
+from soc.views.models import club_admin
 from soc.views.models import document
 from soc.views.models import host
 from soc.views.models import notification
@@ -46,6 +47,7 @@
 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)
 sidebar.addMenu(site.view.getSidebarMenus)
 sidebar.addMenu(user.view.getSidebarMenus)
@@ -58,6 +60,7 @@
 sidebar.addMenu(organization.view.getSidebarMenus)
 
 sitemap.addPages(club.view.getDjangoURLPatterns())
+sitemap.addPages(club_admin.view.getDjangoURLPatterns())
 sitemap.addPages(club_app.view.getDjangoURLPatterns())
 sitemap.addPages(document.view.getDjangoURLPatterns())
 sitemap.addPages(host.view.getDjangoURLPatterns())