Added club_app model and logic.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 21 Jan 2009 19:32:00 +0000
changeset 882 267e31f1a0b6
parent 881 1ad41c8d05e9
child 883 1e0af43577ee
Added club_app model and logic. Patch by: Lennard de Rijk
app/soc/logic/models/club.py
app/soc/logic/models/club_app.py
app/soc/models/club_app.py
app/soc/views/helper/access.py
app/soc/views/models/club.py
app/soc/views/models/club_app.py
--- a/app/soc/logic/models/club.py	Wed Jan 21 18:50:22 2009 +0000
+++ b/app/soc/logic/models/club.py	Wed Jan 21 19:32:00 2009 +0000
@@ -24,7 +24,7 @@
 
 
 from soc.logic.models import group
-from soc.logic.models import group_app as group_app_logic
+from soc.logic.models import club_app as club_app_logic
 from soc.logic.models import request as request_logic
 
 import soc.models.club
@@ -48,7 +48,7 @@
     """
 
     # Find their application
-    application = group_app_logic.logic.getFromFields(link_id=entity.link_id)
+    application = club_app_logic.logic.getFromFields(link_id=entity.link_id)
 
     if application:
       # only if there is an application send out the invites
@@ -66,7 +66,7 @@
 
       # set the application to completed  
       fields = {'application_completed' : True}
-      group_app_logic.logic.updateModelProperties(application, fields)
+      club_app_logic.logic.updateModelProperties(application, fields)
 
 
 logic = Logic()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/club_app.py	Wed Jan 21 19:32:00 2009 +0000
@@ -0,0 +1,43 @@
+#!/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 Application (Model) query functions.
+"""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+  ]
+
+
+from soc.logic.models import group_app
+
+import soc.models.club_app
+import soc.models.group_app
+
+
+class Logic(group_app.Logic):
+  """Logic methods for the Club Application model.
+  """
+
+  def __init__(self, model=soc.models.club_app.ClubApplication,
+               base_model=soc.models.group_app.GroupApplication):
+    """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/club_app.py	Wed Jan 21 19:32:00 2009 +0000
@@ -0,0 +1,32 @@
+#!/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 Application Model."""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+]
+
+
+import soc.models.group_app
+
+
+class ClubApplication(soc.models.group_app.GroupApplication):
+  """Model of a Club Application.
+  
+  This model is used to apply as a Club.
+  """
+  pass
--- a/app/soc/views/helper/access.py	Wed Jan 21 18:50:22 2009 +0000
+++ b/app/soc/views/helper/access.py	Wed Jan 21 19:32:00 2009 +0000
@@ -40,7 +40,7 @@
 from soc.logic import dicts
 from soc.logic.models import host as host_logic
 from soc.logic.models import notification as notification_logic
-from soc.logic.models import group_app  as group_app_logic
+from soc.logic.models import club_app  as club_app_logic
 from soc.logic.models import user as user_logic
 from soc.logic.models import request as request_logic
 from soc.views import helper
@@ -390,9 +390,9 @@
       'application_completed': False,
       }
 
-  group_app = group_app_logic.logic.getForFields(properties, unique=True)
+  club_app = club_app_logic.logic.getForFields(properties, unique=True)
 
-  if group_app:
+  if club_app:
     return
 
   # TODO(srabbelier) Make this give a proper error message
@@ -443,7 +443,7 @@
   deny(request, args, kwargs)
 
 
-def checkIsMyApplication(request, args, kwargs):
+def checkIsMyApplication(app_logic):
   """Returns an alternate HTTP response if this request is for a Application belonging
      to the current user.
 
@@ -456,35 +456,32 @@
   Returns:
     None if the current User is allowed to access this Application.
   """
-  
-  try:
-    # if the current user is a developer we allow access
-    checkIsDeveloper(request, args, kwargs)
-    return
-  except out_of_band.Error:
-    pass
+
+  def wrapper(request, args, kwargs):
+    try:
+      # if the current user is a developer we allow access
+      checkIsDeveloper(request, args, kwargs)
+      return
+    except out_of_band.Error:
+      pass
+
+    checkIsUser(request, args, kwargs)
 
-  checkIsUser(request, args, kwargs)
+    properties = dicts.filter(kwargs, ['link_id'])
+
+    application = app_logic.logic.getForFields(properties, unique=True)
+    user = user_logic.logic.getForCurrentAccount()
 
-  # Mine the url for params
-  try:
-    callback, args, kwargs = urlresolvers.resolve(request.path)
-  except Exception:
+    # We need to check to see if the key's are equal since the User
+    # objects are different and the default __eq__ method does not check
+    # if the keys are equal (which is what we want).
+    if user.key() == application.applicant.key():
+      return None
+
+    # TODO(srabbelier) Make this give a proper error message
     deny(request, args, kwargs)
 
-  properties = dicts.filter(kwargs, ['link_id'])
-
-  application = group_app_logic.logic.getForFields(properties, unique=True)
-  user = user_logic.logic.getForCurrentAccount()
-
-  # We need to check to see if the key's are equal since the User
-  # objects are different and the default __eq__ method does not check
-  # if the keys are equal (which is what we want).
-  if user.key() == application.applicant.key():
-    return None
-
-  # TODO(srabbelier) Make this give a proper error message
-  deny(request, args, kwargs)
+  return wrapper
 
 
 def checkCanInvite(request, args, kwargs):
--- a/app/soc/views/models/club.py	Wed Jan 21 18:50:22 2009 +0000
+++ b/app/soc/views/models/club.py	Wed Jan 21 19:32:00 2009 +0000
@@ -30,7 +30,7 @@
 
 from soc.logic import dicts
 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_app as club_app_logic
 from soc.logic.models import club as club_logic
 from soc.views import out_of_band
 from soc.views.helper import access
@@ -59,6 +59,8 @@
     rights = {}
     rights['create'] = [access.checkIsHost]
     rights['edit'] = [access.checkIsClubAdminForClub]
+    rights['delete'] = [access.checkIsHost]
+    rights['list'] = [access.checkIsHost]
     rights['applicant'] = [access.checkIsClubAppAccepted]
 
     new_params = {}
@@ -130,8 +132,8 @@
     """
 
     # find the application
-    key_fields = group_app_logic.logic.getKeyFieldsFromDict(kwargs)
-    application = group_app_logic.logic.getFromFields(**key_fields)
+    key_fields = club_app_logic.logic.getKeyFieldsFromDict(kwargs)
+    application = club_app_logic.logic.getFromFields(**key_fields)
 
     # extract the application fields
     field_names = application.properties().keys()
--- a/app/soc/views/models/club_app.py	Wed Jan 21 18:50:22 2009 +0000
+++ b/app/soc/views/models/club_app.py	Wed Jan 21 19:32:00 2009 +0000
@@ -30,8 +30,8 @@
 from soc.logic import cleaning
 from soc.logic import dicts
 from soc.logic.helper import notifications
+from soc.logic.models import club_app as club_app_logic
 from soc.logic.models import user as user_logic
-from soc.models import group_app as group_app_model
 from soc.views import helper
 from soc.views import out_of_band
 from soc.views.helper import access
@@ -57,24 +57,26 @@
 
     rights = {}
     rights['create'] = [access.checkIsUser]
-    rights['delete'] = [access.checkIsMyApplication]
-    rights['edit'] = [access.checkIsMyApplication]
+    rights['delete'] = [access.checkIsMyApplication(club_app_logic.logic)]
+    rights['edit'] = [access.checkIsMyApplication(club_app_logic.logic)]
     rights['list'] = [access.checkIsUser]
-    rights['public'] = [access.checkIsMyApplication]
+    rights['public'] = [access.checkIsMyApplication(club_app_logic.logic)]
     rights['review'] = [access.checkIsDeveloper]
 
     new_params = {}
 
     new_params['rights'] = rights
+    new_params['logic'] = club_app_logic.logic
 
     new_params['create_template'] = 'soc/models/twoline_edit.html'
     new_params['edit_template'] = 'soc/models/twoline_edit.html'
 
     new_params['extra_dynaexclude'] = ['applicant', 'backup_admin',
-        'reviewed', 'accepted', 'application_completed']
+        'reviewed', 'accepted', 'application_completed', 
+        'created_on', 'last_modified_on']
     new_params['create_extra_dynafields'] = {
         'backup_admin_link_id': forms.CharField(
-              label=group_app_model.GroupApplication.backup_admin.verbose_name
+              label=soc.models.club_app.ClubApplication.backup_admin.verbose_name
               ),
         'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
         }