Implemented the listing of all the roles in for a specific group.
Removed a TODO about removing the tolist assignment in soc/views/models/host.py because this list is now obsolete.
Added a TODO to change the redirect of the member listing once the manage page is done.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/views/models/club.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/club.py Mon Jan 26 09:44:00 2009 +0000
@@ -42,8 +42,6 @@
from soc.views.models import group
import soc.logic.models.club
-import soc.logic.models.club_admin
-import soc.logic.models.club_member
import soc.views.helper
@@ -65,6 +63,7 @@
rights['delete'] = [access.checkIsDeveloper]
rights['list'] = [access.checkIsDeveloper]
rights['list_requests'] = [access.checkIsClubAdminForClub]
+ rights['list_roles'] = [access.checkIsClubAdminForClub]
rights['applicant'] = [access.checkIsApplicationAccepted(club_app_logic)]
new_params = {}
@@ -86,11 +85,6 @@
required=False),
}
- # set the roles logic
- new_params['roles_logic'] = {
- 'club_admin': soc.logic.models.club_admin.logic,
- 'club_member': soc.logic.models.club_admin.logic}
-
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -223,6 +217,7 @@
edit = view.edit
list = view.list
list_requests = view.listRequests
+list_roles = view.listRoles
public = view.public
export = view.export
pick = view.pick
--- a/app/soc/views/models/club_admin.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/club_admin.py Mon Jan 26 09:44:00 2009 +0000
@@ -84,6 +84,9 @@
super(View, self).__init__(params=params)
+ # register the role with the group_view
+ params['group_view'].registerRole(params['module_name'], self)
+
# create and store the special form for invited users
updated_fields = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
--- a/app/soc/views/models/club_member.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/club_member.py Mon Jan 26 09:44:00 2009 +0000
@@ -85,6 +85,9 @@
super(View, self).__init__(params=params)
+ # register the role with the group_view
+ params['group_view'].registerRole(params['module_name'], self)
+
# create and store the special form for invited users
updated_fields = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
--- a/app/soc/views/models/group.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/group.py Mon Jan 26 09:44:00 2009 +0000
@@ -73,7 +73,10 @@
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')]
+ 'List of requests for %(name)s'),
+ (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$',
+ 'soc.views.models.%(module_name)s.list_roles',
+ 'List of roles for %(name)s')]
new_params['extra_django_patterns'] = patterns
@@ -83,6 +86,8 @@
new_params['list_row'] = 'soc/group/list/row.html'
new_params['list_heading'] = 'soc/group/list/heading.html'
+ new_params['role_views'] = {}
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -129,7 +134,7 @@
group_entity = group_logic.getFromFields(**kwargs)
- role_names = params['roles_logic'].keys()
+ role_names = params['role_views'].keys()
# list all incoming requests
filter = {
@@ -188,3 +193,69 @@
contents = [inc_req_content, out_inv_content, ignored_content]
return self._list(request, params, contents, page_name)
+
+
+ @decorators.merge_params
+ @decorators.check_access
+ def listRoles(self, request, access_type,
+ page_name=None, params=None, **kwargs):
+ """Gives an overview of all the roles in 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'])
+
+ # get the group from the request
+ group_logic = params['logic']
+
+ group_entity = group_logic.getFromFields(**kwargs)
+
+ # create the filter
+ filter = {
+ 'scope' : group_entity,
+ 'state': 'active'
+ }
+
+ role_views = params['role_views']
+ contents = []
+ index = 0
+
+ # for each role we create a separate list
+ for role_name in role_views.keys():
+ # create the list parameters
+ list_params = role_views[role_name].getParams().copy()
+
+ # TODO(ljvderijk) define the list redirect action to the managing page
+ list_params['list_action'] = (redirects.getEditRedirect, list_params)
+ list_params['list_description'] = ugettext(
+ "An overview of the %s for this %s." % (
+ list_params['name_plural'], params['name']))
+
+ new_list_content = list_helper.getListContent(
+ request, list_params, filter, index)
+
+ contents += [new_list_content]
+
+ index += 1
+
+ # call the _list method from base.View to show the list
+ return self._list(request, params, contents, page_name)
+
+
+ def registerRole(self, role_name, role_view):
+ """Adds a role to the role_views param.
+
+ Args:
+ role_name: The name of the role that needs to be added
+ role_view: The view that needs to be added to role_views.
+ """
+
+ role_views = self._params['role_views']
+ role_views[role_name] = role_view
--- a/app/soc/views/models/host.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/host.py Mon Jan 26 09:44:00 2009 +0000
@@ -42,9 +42,6 @@
import soc.views.helper
import soc.views.models.sponsor
-# TODO(pawel.solyga): Rename all list methods and functions to something else
-# and remove this tolist assignment
-tolist = list
class View(role.View):
"""View methods for the Host model.
@@ -62,7 +59,7 @@
rights['create'] = [access.checkIsHost]
rights['edit'] = [access.checkIsMyActiveRole(soc.logic.models.host)]
rights['invite'] = [access.checkIsHost]
- rights['list'] = [access.checkIsHost]
+ rights['list'] = [access.checkIsDeveloper]
rights['accept_invite'] = [access.checkCanCreateFromRequest('host')]
rights['process_request'] = [access.checkIsHost,
access.checkCanProcessRequest('host')]
@@ -96,6 +93,9 @@
super(View, self).__init__(params=params)
+ # register the role with the group_view
+ params['group_view'].registerRole(params['module_name'], self)
+
# create and store the special form for invited users
updated_fields = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
@@ -107,28 +107,6 @@
params['invited_create_form'] = invited_create_form
-
- def list(self, request, access_type, page_name=None,
- params=None, filter=None):
- """See base.View.list.
-
- Passes a filter to base.View.list so that only hosts from a sponsor
- that this user is host for are listed.
- """
-
- user = user_logic.logic.getForCurrentAccount()
-
- # Don't bother looking up everything if there's no user
- if user and (not accounts.isDeveloper(user=user)):
- hosts = host_logic.logic.getForFields({'user': user})
- sponsors = tolist((host.scope for host in hosts))
-
- new_filter = {'scope': sponsors}
- filter = dicts.merge(filter, new_filter)
-
- return super(View, self).list(request, access_type, page_name=page_name,
- params=params, filter=filter)
-
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
--- a/app/soc/views/models/sponsor.py Sun Jan 25 23:35:39 2009 +0000
+++ b/app/soc/views/models/sponsor.py Mon Jan 26 09:44:00 2009 +0000
@@ -30,7 +30,6 @@
import soc.models.sponsor
import soc.logic.dicts
-import soc.logic.models.host
import soc.logic.models.sponsor
@@ -52,6 +51,7 @@
rights['delete'] = [access.checkIsDeveloper]
rights['list'] = [access.checkIsDeveloper]
rights['list_requests'] = [access.checkIsHostForSponsor]
+ rights['list_roles'] = [access.checkIsHostForSponsor]
new_params = {}
new_params['logic'] = soc.logic.models.sponsor.logic
@@ -60,9 +60,6 @@
new_params['name'] = "Program Owner"
new_params['module_name'] = "sponsor"
- # set the roles logic
- new_params['roles_logic'] = {'host': soc.logic.models.host.logic}
-
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -75,6 +72,7 @@
edit = view.edit
list = view.list
list_requests = view.listRequests
+list_roles = view.listRoles
public = view.public
export = view.export
pick = view.pick