Moved listRequests from club to group view.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 25 Jan 2009 16:43:15 +0000
changeset 989 f52654ea6350
parent 988 e35b3d98d469
child 990 fd1e6afb2d62
Moved listRequests from club to group view. Added a TODO for adding request list to sidebar entry for every group. And for setting the rights for Sponsor view. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/models/club.py
app/soc/views/models/group.py
app/soc/views/models/sponsor.py
--- a/app/soc/views/models/club.py	Sun Jan 25 16:29:36 2009 +0000
+++ b/app/soc/views/models/club.py	Sun Jan 25 16:43:15 2009 +0000
@@ -27,7 +27,6 @@
 
 from django import http
 from django import forms
-from django.utils.translation import ugettext
 
 from soc.logic import dicts
 from soc.logic.models import user as user_logic
@@ -38,18 +37,15 @@
 from soc.views.helper import access
 from soc.views.helper import decorators
 from soc.views.helper import dynaform
-from soc.views.helper import lists as list_helper
-from soc.views.helper import redirects
 from soc.views.helper import responses
 from soc.views.helper import widgets
-from soc.views.models import base
-from soc.views.models.request import view as request_view
+from soc.views.models import group
 
 import soc.logic.models.club
 import soc.views.helper
 
 
-class View(base.View):
+class View(group.View):
   """View methods for the Club model.
   """
 
@@ -78,10 +74,7 @@
 
     patterns += [(r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
         'soc.views.models.%(module_name)s.applicant', 
-        "%(name)s Creation via Accepted Application"),
-        (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$',
-        'soc.views.models.%(module_name)s.list_requests',
-        'List of requests for %(name)s')]
+        "%(name)s Creation via Accepted Application"),]
 
     new_params['extra_django_patterns'] = patterns
 
@@ -91,6 +84,9 @@
                                    required=False),
         }
 
+    # set the role names for the request overview
+    new_params['role_names'] =  ['club_admin', 'club_member']
+
     params = dicts.merge(params, new_params)
 
     super(View, self).__init__(params=params)
@@ -194,82 +190,6 @@
     return http.HttpResponseRedirect('/notification/list')
 
 
-  @decorators.merge_params
-  @decorators.check_access
-  def listRequests(self, request, access_type,
-                page_name=None, params=None, **kwargs):
-    """Gives an overview of all the requests for a specific club.
-
-    Args:
-      request: the standard Django HTTP request object
-      access_type : the name of the access type which should be checked
-      page_name: the page name displayed in templates as page and header title
-      params: a dict with params for this View
-      kwargs: the Key Fields for the specified entity
-    """
-
-    # set the pagename to include the link_id
-    page_name = '%s %s' %(page_name, kwargs['link_id'])
-
-    club_roles = ['club_admin', 'club_member']
-
-    # list all incoming requests
-    filter = {
-        'role': club_roles,
-        'state': 'new'
-        }
-
-    # create the list parameters
-    inc_req_params = request_view.getParams()
-
-    # define the list redirect action to the request processing page
-    inc_req_params['list_action'] = (redirects.getProcessRequestRedirect, None)
-    inc_req_params['list_description'] = ugettext(
-        "An overview of the club's incoming requests.")
-    
-    inc_req_content = list_helper.getListContent(
-        request, inc_req_params, filter, 0)
-
-    # list all outstanding invites
-    filter = {
-        'role': club_roles,
-        'state': 'group_accepted'
-        }
-
-    # create the list parameters
-    out_inv_params = request_view.getParams()
-
-    # define the list redirect action to the request processing page
-    out_inv_params['list_action'] = (redirects.getProcessRequestRedirect, None)
-    out_inv_params['list_description'] = ugettext(
-        "An overview of the club's outstanding invites.")
-
-    out_inv_content = list_helper.getListContent(
-        request, out_inv_params, filter, 1)
-
-    # list all ignored requests
-    filter = {
-        'role': club_roles,
-        'state': 'ignored'
-        }
-
-    # create the list parameters
-    ignored_params = request_view.getParams()
-
-    # define the list redirect action to the request processing page
-    ignored_params['list_action'] = (redirects.getProcessRequestRedirect, None)
-    ignored_params['list_description'] = ugettext(
-        "An overview of the club's ignored requests.")
-    
-    ignored_content = list_helper.getListContent(
-        request, ignored_params, filter, 2)
-
-
-    contents = [inc_req_content, out_inv_content, ignored_content]
-
-    return self._list(request, params, contents, page_name)
-
-
   def _editGet(self, request, entity, form):
     """See base.View._editGet().
     """
--- a/app/soc/views/models/group.py	Sun Jan 25 16:29:36 2009 +0000
+++ b/app/soc/views/models/group.py	Sun Jan 25 16:43:15 2009 +0000
@@ -19,23 +19,31 @@
 
 __authors__ = [
     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+    '"Lennard de Rijk" <ljvderijk@gmail.com>',
   ]
 
 
 from google.appengine.api import users
 
 from django import forms
+from django.utils.translation import ugettext
 
 from soc.logic import dicts
 from soc.logic.models import user as user_logic
+from soc.views.helper import decorators
+from soc.views.helper import lists as list_helper
+from soc.views.helper import redirects
 from soc.views.helper import widgets
 from soc.views.models import base
+from soc.views.models.request import view as request_view
 
 
 class View(base.View):
   """View methods for the Group model.
   """
 
+  # TODO(ljvderijk) add sidebar entry for listRequests to each group
+
   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.
@@ -56,6 +64,19 @@
                                    required=False),
         }
 
+    #set the extra_django_patterns and include the one from params
+    patterns = params.get('extra_django_patterns')
+
+    if not patterns:
+      patterns = []
+
+    patterns += [
+        (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$',
+        'soc.views.models.%(module_name)s.list_requests',
+        'List of requests for %(name)s')]
+
+    new_params['extra_django_patterns'] = patterns
+
     # TODO(tlarsen): Add support for Django style template lookup
     new_params['public_template'] = 'soc/group/public.html'
 
@@ -86,3 +107,76 @@
 
     super(View, self)._editPost(request, entity, fields)
 
+  @decorators.merge_params
+  @decorators.check_access
+  def listRequests(self, request, access_type,
+                page_name=None, params=None, **kwargs):
+    """Gives an overview of all the requests for a specific group.
+
+    Args:
+      request: the standard Django HTTP request object
+      access_type : the name of the access type which should be checked
+      page_name: the page name displayed in templates as page and header title
+      params: a dict with params for this View
+      kwargs: the Key Fields for the specified entity
+    """
+
+    # set the pagename to include the link_id
+    page_name = '%s %s' %(page_name, kwargs['link_id'])
+
+    role_names = params['role_names']
+
+    # list all incoming requests
+    filter = {
+        'role': role_names,
+        'state': 'new'
+        }
+
+    # create the list parameters
+    inc_req_params = request_view.getParams()
+
+    # define the list redirect action to the request processing page
+    inc_req_params['list_action'] = (redirects.getProcessRequestRedirect, None)
+    inc_req_params['list_description'] = ugettext(
+        "An overview of the %(name)s's incoming requests." % params)
+    
+    inc_req_content = list_helper.getListContent(
+        request, inc_req_params, filter, 0)
+
+    # list all outstanding invites
+    filter = {
+        'role': role_names,
+        'state': 'group_accepted'
+        }
+
+    # create the list parameters
+    out_inv_params = request_view.getParams()
+
+    # define the list redirect action to the request processing page
+    out_inv_params['list_action'] = (redirects.getProcessRequestRedirect, None)
+    out_inv_params['list_description'] = ugettext(
+        "An overview of the %(name)s's outstanding invites." % params)
+
+    out_inv_content = list_helper.getListContent(
+        request, out_inv_params, filter, 1)
+
+    # list all ignored requests
+    filter = {
+        'role': role_names,
+        'state': 'ignored'
+        }
+
+    # create the list parameters
+    ignored_params = request_view.getParams()
+
+    # define the list redirect action to the request processing page
+    ignored_params['list_action'] = (redirects.getProcessRequestRedirect, None)
+    ignored_params['list_description'] = ugettext(
+        "An overview of the %(name)s's ignored requests." % params)
+    
+    ignored_content = list_helper.getListContent(
+        request, ignored_params, filter, 2)
+
+    contents = [inc_req_content, out_inv_content, ignored_content]
+
+    return self._list(request, params, contents, page_name)
--- a/app/soc/views/models/sponsor.py	Sun Jan 25 16:29:36 2009 +0000
+++ b/app/soc/views/models/sponsor.py	Sun Jan 25 16:43:15 2009 +0000
@@ -47,9 +47,14 @@
     new_params = {}
     new_params['logic'] = soc.logic.models.sponsor.logic
 
+    # TODO(ljvderijk) Set rights for the different views including list_requests
+
     new_params['name'] = "Program Owner"
     new_params['module_name'] = "sponsor"
 
+    # set the role names for the request overview
+    new_params['role_names'] =  ['host']
+
     params = dicts.merge(params, new_params)
 
     super(View, self).__init__(params=params)
@@ -61,6 +66,7 @@
 delete = view.delete
 edit = view.edit
 list = view.list
+list_requests = view.listRequests
 public = view.public
 export = view.export
 pick = view.pick