app/soc/views/models/group.py
author Chen Lunpeng <forever.clp@gmail.com>
Fri, 27 Mar 2009 13:16:27 +0000
changeset 2021 3ab5d0d73f38
parent 1990 fea8bdb43992
child 2076 1cd180cc56c9
permissions -rw-r--r--
Fixed some typo in app/soc/views/models/base.py Patch by: Chen Lunpeng 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
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
363
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 django import forms
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    27
from django import http
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    28
from django.utils.translation import ugettext
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
1722
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    30
from soc.logic import cleaning
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
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    36
from soc.views.helper import responses
755
1ed041c0cdc6 Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 681
diff changeset
    37
from soc.views.helper import widgets
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
    38
from soc.views.models import presence
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
    39
from soc.views.models import document as document_view
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    40
from soc.views.models.request import view as request_view
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
    41
from soc.views.sitemap import sidebar
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    43
import soc.views.helper
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
    45
class View(presence.View):
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    46
  """View methods for the Group model.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    49
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    50
  def __init__(self, params=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    """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
    52
    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
    53
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    55
      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
    56
    """
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    58
    new_params = {}
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    59
1640
c63fb0240203 Remove unused imports and variable, plus some style fixes in soc.views.models.group module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1430
diff changeset
    60
    new_params['extra_dynaexclude'] = ['founder', 'home', 'tos',
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
    61
                                       'member_template', 'status']
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1361
diff changeset
    62
    new_params['edit_extra_dynaproperties'] = {
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
1049
cc6aedbde28d Fixed the edit site view having a delete button
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1030
diff changeset
    68
    patterns = params.get('extra_django_patterns', [])
989
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
    patterns += [
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    71
        (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
    72
        '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
    73
        '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
    74
        (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
    75
        '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
    76
        '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
    77
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    78
    if params.get('group_applicant_url'):
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    79
      # add the applicant pattern
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    80
      patterns += [
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    81
          (r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    82
          'soc.views.models.%(module_name)s.applicant', 
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    83
          "%(name)s Creation via Accepted Application"),]
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
    84
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    85
    new_params['extra_django_patterns'] = patterns
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    86
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
    87
    # 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
    88
    new_params['public_template'] = 'soc/group/public.html'
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    90
    new_params['list_row'] = 'soc/group/list/row.html'
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    91
    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
    92
1722
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    93
    new_params['create_extra_dynaproperties'] = {
1990
fea8bdb43992 Automagically convert '+' to '00' in phone numbers
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1963
diff changeset
    94
       'clean_phone': cleaning.clean_phone_number('phone'),
1722
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    95
       'clean_contact_street': cleaning.clean_ascii_only('contact_street'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    96
       'clean_contact_city': cleaning.clean_ascii_only('contact_city'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    97
       'clean_contact_state': cleaning.clean_ascii_only('contact_state'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    98
       'clean_contact_postalcode': cleaning.clean_ascii_only('contact_postalcode'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    99
       'clean_shipping_street': cleaning.clean_ascii_only('shipping_street'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   100
       'clean_shipping_city': cleaning.clean_ascii_only('shipping_city'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   101
       'clean_shipping_state': cleaning.clean_ascii_only('shipping_state'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   102
       'clean_shipping_postalcode': cleaning.clean_ascii_only('shipping_postalcode'),
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   103
       }
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   104
7f285e96cb17 All address fields for roles and groups can now only use characters that can successfully be converted to ASCII.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   105
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   106
    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
   107
1060
eb6231138307 Added state and shipping address fields to group model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1049
diff changeset
   108
    params = dicts.merge(params, new_params, sub_merge=True)
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
   109
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
   110
    super(View, self).__init__(params=params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
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
   112
  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
   113
    """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
   114
    """
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   115
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
   116
    # 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
   117
    form.fields['founded_by'].initial = entity.founder.name
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   118
    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
   119
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
  def _editPost(self, request, entity, fields):
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
   121
    """See base.View._editPost().
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
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
   124
    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
   125
      # only if we are creating a new entity we should fill in founder
1127
69a9134c5c7e Fixed two small errors.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   126
      user = user_logic.logic.getForCurrentAccount()
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
   127
      fields['founder'] = user
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   128
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   129
    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
   130
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   131
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   132
  @decorators.merge_params
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   133
  @decorators.check_access
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   134
  def applicant(self, request, access_type,
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   135
                page_name=None, params=None, **kwargs):
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   136
    """Handles the creation of a group via an approved group application.
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   137
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   138
    Args:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   139
      request: the standard Django HTTP request object
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   140
      access_type : the name of the access type which should be checked
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   141
      page_name: the page name displayed in templates as page and header title
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   142
      params: a dict with params for this View
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   143
      kwargs: the Key Fields for the specified entity
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   144
    """
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   145
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   146
    # get the context for this webpage
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   147
    context = responses.getUniversalContext(request)
1361
228061de9e8d Fixed a copy/paste bug in group.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1357
diff changeset
   148
    responses.useJavaScript(context, params['js_uses_all'])
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   149
    context['page_name'] = page_name
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   150
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   151
    if request.method == 'POST':
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   152
      return self.applicantPost(request, context, params, **kwargs)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   153
    else:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   154
      # request.method == 'GET'
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   155
      return self.applicantGet(request, context, params, **kwargs)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   156
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   157
  def applicantGet(self, request, context, params, **kwargs):
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   158
    """Handles the GET request concerning the creation of a group via an
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   159
    approved group application.
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   160
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   161
    Args:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   162
      request: the standard Django HTTP request object
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   163
      context: dictionary containing the context for this view
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   164
      params: a dict with params for this View
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   165
      kwargs: the Key Fields for the specified entity
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   166
    """
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   167
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   168
    # find the application
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   169
    application_logic = params['application_logic']
1218
569a3fe9cb88 Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1153
diff changeset
   170
    application = application_logic.logic.getFromKeyFields(kwargs)
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   171
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   172
    # extract the application fields
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   173
    field_names = application.properties().keys()
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   174
    fields = dict( [(i, getattr(application, i)) for i in field_names] )
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   175
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   176
    # create the form using the fields from the application as the initial value
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   177
    form = params['applicant_create_form'](initial=fields)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   178
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   179
    # construct the appropriate response
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   180
    return super(View, self)._constructResponse(request, entity=None,
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   181
        context=context, form=form, params=params)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   182
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   183
  def applicantPost(self, request, context, params, **kwargs):
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   184
    """Handles the POST request concerning the creation of a group via an
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   185
    approved group application.
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   186
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   187
    Args:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   188
      request: the standard Django HTTP request object
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   189
      context: dictionary containing the context for this view
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   190
      params: a dict with params for this View
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   191
      kwargs: the Key Fields for the specified entity
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   192
    """
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   193
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   194
    # populate the form using the POST data
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   195
    form = params['applicant_create_form'](request.POST)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   196
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   197
    if not form.is_valid():
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   198
      # return the invalid form response
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   199
      return self._constructResponse(request, entity=None, context=context,
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   200
          form=form, params=params)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   201
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   202
    # collect the cleaned data from the valid form
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   203
    key_name, fields = soc.views.helper.forms.collectCleanedFields(form)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   204
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   205
    # do post processing
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   206
    self._applicantPost(request, context, fields)
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   207
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   208
    if not key_name:
1218
569a3fe9cb88 Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1153
diff changeset
   209
      key_name = self._logic.getKeyNameFromFields(fields)
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   210
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   211
    # create the group entity
1640
c63fb0240203 Remove unused imports and variable, plus some style fixes in soc.views.models.group module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1430
diff changeset
   212
    self._logic.updateOrCreateFromKeyName(fields, key_name)
1153
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   213
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   214
    # redirect to notifications list to see the admin invite
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   215
    return http.HttpResponseRedirect('/notification/list')
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   216
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   217
  def _applicantPost(self, request, context, fields):
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   218
    """Performs any required processing on the entity to post its edit page.
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   219
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   220
    Args:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   221
      request: the django request object
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   222
      context: the context for the webpage
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   223
      fields: the new field values
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   224
    """
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   225
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   226
     # fill in the founder of the group
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   227
    user = user_logic.logic.getForCurrentAccount()
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   228
    fields['founder'] = user
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   229
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   230
    # If scope_logic is not defined, this entity has no scope
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   231
    if not self._params['scope_logic']:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   232
      return
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   233
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   234
    # If this entity is unscoped, do not try to retrieve a scope
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   235
    if 'scope_path' not in fields:
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   236
      return
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   237
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   238
    scope = self._params['scope_logic'].logic.getFromKeyName(
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   239
        fields['scope_path'])
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   240
    fields['scope'] = scope
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   241
4804f7f5a7c0 Refactored applicant from club view to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1127
diff changeset
   242
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   243
  @decorators.merge_params
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   244
  @decorators.check_access
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   245
  def listRequests(self, request, access_type,
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   246
                   page_name=None, params=None, **kwargs):
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   247
    """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
   248
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   249
    Args:
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   250
      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
   251
      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
   252
      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
   253
      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
   254
      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
   255
    """
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   256
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   257
    # set the pagename to include the link_id
1640
c63fb0240203 Remove unused imports and variable, plus some style fixes in soc.views.models.group module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1430
diff changeset
   258
    page_name = '%s %s' % (page_name, kwargs['link_id'])
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   259
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   260
    # 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
   261
    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
   262
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   263
    group_entity = group_logic.getFromKeyFields(kwargs)
994
f05c02ba40fc listRequests now only shows the requests that concerns the given group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 993
diff changeset
   264
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   265
    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
   266
    
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   267
    # list all incoming requests
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   268
    filter = {
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   269
        'scope': group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   270
        'role': role_names,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
   271
        'status': 'new'
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   272
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   273
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   274
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   275
    inc_req_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   276
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   277
    # 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
   278
    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
   279
    inc_req_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   280
        "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
   281
    
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   282
    inc_req_content = list_helper.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1640
diff changeset
   283
        request, inc_req_params, filter, idx=0)
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   284
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   285
    # list all outstanding invites
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   286
    filter = {
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   287
        'scope': group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   288
        'role': role_names,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
   289
        'status': 'group_accepted'
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   290
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   291
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   292
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   293
    out_inv_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   294
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   295
    # 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
   296
    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
   297
    out_inv_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   298
        "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
   299
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   300
    out_inv_content = list_helper.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1640
diff changeset
   301
        request, out_inv_params, filter, idx=1)
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   302
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   303
    # list all ignored requests
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   304
    filter = {
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   305
        'scope': group_entity,
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   306
        'role': role_names,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
   307
        'status': 'ignored'
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   308
        }
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   309
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   310
    # create the list parameters
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   311
    ignored_params = request_view.getParams()
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   312
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   313
    # 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
   314
    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
   315
    ignored_params['list_description'] = ugettext(
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   316
        "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
   317
    
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   318
    ignored_content = list_helper.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1640
diff changeset
   319
        request, ignored_params, filter, idx=2)
989
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   320
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   321
    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
   322
f52654ea6350 Moved listRequests from club to group view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   323
    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
   324
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   325
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   326
  @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
   327
  @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
   328
  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
   329
                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
   330
    """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
   331
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   332
    Args:
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   333
      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
   334
      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
   335
      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
   336
      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
   337
      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
   338
    """
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   339
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   340
    # set the pagename to include the link_id
1640
c63fb0240203 Remove unused imports and variable, plus some style fixes in soc.views.models.group module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1430
diff changeset
   341
    page_name = '%s %s' % (page_name, kwargs['link_id'])
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   342
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   343
    # 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
   344
    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
   345
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   346
    group_entity = group_logic.getFromKeyFields(kwargs)
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   347
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   348
    # 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
   349
    filter = {
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   350
        'scope' : group_entity,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
   351
        'status': 'active'
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   352
        }
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   353
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   354
    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
   355
    contents = []
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   356
    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
   357
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   358
    # 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
   359
    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
   360
      # 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
   361
      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
   362
1065
b661dc8ffd5f Added manage redirect.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1060
diff changeset
   363
      list_params['list_action'] = (redirects.getManageRedirect, list_params)
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   364
      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
   365
          "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
   366
          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
   367
    
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   368
      new_list_content = list_helper.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1640
diff changeset
   369
          request, list_params, filter, idx=index)
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   370
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   371
      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
   372
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   373
      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
   374
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   375
    # 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
   376
    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
   377
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   378
  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
   379
    """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
   380
    
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   381
    Args:
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   382
      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
   383
      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
   384
    """
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   385
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 994
diff changeset
   386
    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
   387
    role_views[role_name] = role_view
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   388
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1003
diff changeset
   389
  def getExtraMenus(self, id, user, params=None):
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   390
    """Returns the extra menu's for this view.
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   391
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   392
    A menu item is generated for each group that the user has an active
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   393
    role for. The public page for each group is added as menu item,
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   394
    as well as all public documents for that group.
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   395
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   396
    Args:
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   397
      params: a dict with params for this View.
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   398
    """
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   399
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   400
    params = dicts.merge(params, self._params)
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   401
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   402
    # set fields to match every active role this user has
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1003
diff changeset
   403
    fields = {'user': user,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1075
diff changeset
   404
              'status': 'active'}
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   405
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   406
    # get the role views and start filling group_entities
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   407
    role_views = self._params['role_views']
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   408
    role_descriptions = {}
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   409
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   410
    for role_name in role_views.keys():
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   411
      role_view = role_views[role_name]
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   412
      role_view_params = role_view.getParams()
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   413
      role_logic = role_view_params['logic']
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   414
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   415
      roles = role_logic.getForFields(fields)
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   416
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   417
      for role in roles:
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   418
        group_key_name = role.scope.key().name()
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   419
        existing_role_descriptions = role_descriptions.get(group_key_name)
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   420
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   421
        if existing_role_descriptions:
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   422
          # add this description to existing roles
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   423
          existing_roles = existing_role_descriptions['roles']
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   424
          existing_roles[role_name] = role
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   425
        else:
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   426
          # create a description of this role
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   427
          role_description = {'roles': {role_name: role},
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   428
              'group': role.scope}
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   429
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   430
          # add the new entry to our dictionary
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   431
          role_descriptions[group_key_name] = role_description
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   432
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   433
    # get the document view params to add the group's documents to the menu
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   434
    doc_params = document_view.view.getParams()
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   435
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   436
    menus = []
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   437
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   438
    # for each role description in our collection
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   439
    for role_description in role_descriptions.itervalues():
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   440
      #start with an empty menu
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   441
      menu = {}
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   442
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   443
      # get the group for this role description
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   444
      group_entity = role_description['group']
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   445
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   446
      # set the menu header name
1065
b661dc8ffd5f Added manage redirect.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1060
diff changeset
   447
      menu['heading'] = group_entity.short_name
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   448
1003
b13da1ddcd50 Added sidebar entries for club entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1002
diff changeset
   449
      # get the documents for this group entity
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   450
      doc_items = document_view.view.getMenusForScope(group_entity, params)
1023
d849b47645f9 Bugfixes after recent refactoring
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1017
diff changeset
   451
      doc_items = sidebar.getSidebarMenu(id, user, doc_items,
d849b47645f9 Bugfixes after recent refactoring
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1017
diff changeset
   452
                                         params=doc_params)
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   453
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   454
      # get the group specific items
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   455
      group_items = self._getExtraMenuItems(role_description, params)
1023
d849b47645f9 Bugfixes after recent refactoring
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1017
diff changeset
   456
      group_items = sidebar.getSidebarMenu(id, user, group_items,
d849b47645f9 Bugfixes after recent refactoring
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1017
diff changeset
   457
                                           params=self._params)
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   458
1003
b13da1ddcd50 Added sidebar entries for club entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1002
diff changeset
   459
      # add the items together
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   460
      menu['items'] = doc_items + group_items
1065
b661dc8ffd5f Added manage redirect.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1060
diff changeset
   461
      menu['group'] = params['name_plural']
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   462
1003
b13da1ddcd50 Added sidebar entries for club entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1002
diff changeset
   463
      # append this as a new menu
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   464
      menus.append(menu)
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   465
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   466
    return menus
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   467
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   468
  def _getExtraMenuItems(self, role_description, params=None):
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1024
diff changeset
   469
    """Used to implement group instance specific needs for the side menu.
1002
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   470
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   471
    Args:
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   472
      role_description : dict containing all the roles which is a dict of 
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   473
                         name and the role entity to which it belongs. Also
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   474
                         group contains the group entity to which these roles
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   475
                         belong.
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   476
      params: a dict with params for this View.
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   477
    """
11a2aff6c3ad Added sidebar support for group instances.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 998
diff changeset
   478
    return []