app/soc/views/models/group.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 26 Jan 2009 09:44:00 +0000
changeset 998 125257161908
parent 994 f05c02ba40fc
child 1002 11a2aff6c3ad
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    17
"""Views for Groups.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import users
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django import forms
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    29
from django.utils.translation import ugettext
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 363
diff changeset
    31
from soc.logic import dicts
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
    32
from soc.logic.models import user as user_logic
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    33
from soc.views.helper import decorators
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    34
from soc.views.helper import lists as list_helper
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    35
from soc.views.helper import redirects
755
1ed041c0cdc6 Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 681
diff changeset
    36
from soc.views.helper import widgets
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.views.models import base
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    38
from soc.views.models.request import view as request_view
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
class View(base.View):
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    42
  """View methods for the Group model.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
  """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    45
  # TODO(ljvderijk) add sidebar entry for listRequests to each group
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    46
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    47
  def __init__(self, params=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    """Defines the fields and methods required for the base View class
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    to provide the user with list, public, create, edit and delete views.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    52
      params: a dict with params for this View
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    53
    """
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    55
    new_params = {}
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    56
809
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    57
    new_params['extra_dynaexclude'] = ['founder',
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    58
      # TODO(tlarsen): these need to be enabled once a button to a list
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    59
      #   selection "interstitial" page is implemented, see:
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    60
      #     http://code.google.com/p/soc/issues/detail?id=151
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    61
      'home', 'tos', 'member_template']
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 662
diff changeset
    62
    new_params['edit_extra_dynafields'] = {
755
1ed041c0cdc6 Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 681
diff changeset
    63
        'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    64
                                   required=False),
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    65
        }
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    67
    #set the extra_django_patterns and include the one from params
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    68
    patterns = params.get('extra_django_patterns')
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    69
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    70
    if not patterns:
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    71
      patterns = []
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    72
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    73
    patterns += [
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    74
        (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$',
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    75
        'soc.views.models.%(module_name)s.list_requests',
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    76
        'List of requests for %(name)s'),
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    77
        (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$',
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    78
        'soc.views.models.%(module_name)s.list_roles',
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    79
        'List of roles for %(name)s')]
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    80
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    81
    new_params['extra_django_patterns'] = patterns
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    82
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
    83
    # TODO(tlarsen): Add support for Django style template lookup
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    84
    new_params['public_template'] = 'soc/group/public.html'
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    86
    new_params['list_row'] = 'soc/group/list/row.html'
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    87
    new_params['list_heading'] = 'soc/group/list/heading.html'
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
    88
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    89
    new_params['role_views'] = {}
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
    90
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    91
    params = dicts.merge(params, new_params)
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    92
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    93
    super(View, self).__init__(params=params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    95
  def _editGet(self, request, entity, form):
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    96
    """See base.View._editGet().
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    97
    """
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    98
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    99
    # fill in the founded_by with data from the entity
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   100
    form.fields['founded_by'].initial = entity.founder.name
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   101
    super(View, self)._editGet(request, entity, form)
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   102
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
  def _editPost(self, request, entity, fields):
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
   104
    """See base.View._editPost().
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   107
    if not entity:
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   108
      # only if we are creating a new entity we should fill in founder
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
   109
      account = users.get_current_user()
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
   110
      user = user_logic.logic.getForFields({'account': account}, unique=True)
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   111
      fields['founder'] = user
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   112
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   113
    super(View, self)._editPost(request, entity, fields)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 809
diff changeset
   114
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   115
  @decorators.merge_params
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   116
  @decorators.check_access
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   117
  def listRequests(self, request, access_type,
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   118
                page_name=None, params=None, **kwargs):
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   119
    """Gives an overview of all the requests for a specific group.
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   120
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   121
    Args:
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   122
      request: the standard Django HTTP request object
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   123
      access_type : the name of the access type which should be checked
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   124
      page_name: the page name displayed in templates as page and header title
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   125
      params: a dict with params for this View
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   126
      kwargs: the Key Fields for the specified entity
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   127
    """
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   128
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   129
    # set the pagename to include the link_id
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   130
    page_name = '%s %s' %(page_name, kwargs['link_id'])
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   131
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   132
    # get the group from the request
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   133
    group_logic = params['logic']
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   134
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   135
    group_entity = group_logic.getFromFields(**kwargs)
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   136
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   137
    role_names = params['role_views'].keys()
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   138
    
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   139
    # list all incoming requests
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   140
    filter = {
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   141
        'scope' : group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   142
        'role': role_names,
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   143
        'state': 'new'
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   144
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   145
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   146
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   147
    inc_req_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   148
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   149
    # define the list redirect action to the request processing page
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   150
    inc_req_params['list_action'] = (redirects.getProcessRequestRedirect, None)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   151
    inc_req_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   152
        "An overview of the %(name)s's incoming requests." % params)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   153
    
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   154
    inc_req_content = list_helper.getListContent(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   155
        request, inc_req_params, filter, 0)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   156
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   157
    # list all outstanding invites
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   158
    filter = {
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   159
        'scope' : group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   160
        'role': role_names,
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   161
        'state': 'group_accepted'
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   162
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   163
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   164
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   165
    out_inv_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   166
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   167
    # define the list redirect action to the request processing page
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   168
    out_inv_params['list_action'] = (redirects.getProcessRequestRedirect, None)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   169
    out_inv_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   170
        "An overview of the %(name)s's outstanding invites." % params)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   171
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   172
    out_inv_content = list_helper.getListContent(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   173
        request, out_inv_params, filter, 1)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   174
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   175
    # list all ignored requests
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   176
    filter = {
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   177
        'scope' : group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   178
        'role': role_names,
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   179
        'state': 'ignored'
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   180
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   181
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   182
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   183
    ignored_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   184
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   185
    # define the list redirect action to the request processing page
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   186
    ignored_params['list_action'] = (redirects.getProcessRequestRedirect, None)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   187
    ignored_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   188
        "An overview of the %(name)s's ignored requests." % params)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   189
    
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   190
    ignored_content = list_helper.getListContent(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   191
        request, ignored_params, filter, 2)
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   192
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   193
    contents = [inc_req_content, out_inv_content, ignored_content]
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   194
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   195
    return self._list(request, params, contents, page_name)
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   196
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   197
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   198
  @decorators.merge_params
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   199
  @decorators.check_access
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   200
  def listRoles(self, request, access_type,
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   201
                page_name=None, params=None, **kwargs):
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   202
    """Gives an overview of all the roles in a specific group.
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   203
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   204
    Args:
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   205
      request: the standard Django HTTP request object
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   206
      access_type : the name of the access type which should be checked
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   207
      page_name: the page name displayed in templates as page and header title
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   208
      params: a dict with params for this View
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   209
      kwargs: the Key Fields for the specified entity
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   210
    """
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   211
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   212
    # set the pagename to include the link_id
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   213
    page_name = '%s %s' %(page_name, kwargs['link_id'])
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   214
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   215
    # get the group from the request
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   216
    group_logic = params['logic']
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   217
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   218
    group_entity = group_logic.getFromFields(**kwargs)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   219
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   220
    # create the filter
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   221
    filter = {
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   222
        'scope' : group_entity,
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   223
        'state': 'active'
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   224
        }
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   225
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   226
    role_views = params['role_views']
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   227
    contents = []
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   228
    index = 0
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   229
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   230
    # for each role we create a separate list
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   231
    for role_name in role_views.keys():
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   232
      # create the list parameters
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   233
      list_params = role_views[role_name].getParams().copy()
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   234
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   235
      # TODO(ljvderijk) define the list redirect action to the managing page
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   236
      list_params['list_action'] = (redirects.getEditRedirect, list_params)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   237
      list_params['list_description'] = ugettext(
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   238
          "An overview of the %s for this %s." % (
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   239
          list_params['name_plural'], params['name']))
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   240
    
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   241
      new_list_content = list_helper.getListContent(
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   242
          request, list_params, filter, index)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   243
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   244
      contents += [new_list_content]
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   245
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   246
      index += 1
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   247
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   248
    # call the _list method from base.View to show the list
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   249
    return self._list(request, params, contents, page_name)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   250
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   251
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   252
  def registerRole(self, role_name, role_view):
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   253
    """Adds a role to the role_views param.
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   254
    
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   255
    Args:
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   256
      role_name: The name of the role that needs to be added
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   257
      role_view: The view that needs to be added to role_views.
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   258
    """
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   259
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   260
    role_views = self._params['role_views']
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   261
    role_views[role_name] = role_view