app/soc/views/models/role.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 29 Nov 2008 19:44:48 +0000
changeset 613 4880ffa9f3ba
parent 572 1b3e7280743a
child 616 580b1c21b808
permissions -rw-r--r--
Moved getDjangoURLPatterns to sitemap.sitemap Third commit in a series that aims to improve the cohesion in the base.View class. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Sponsor profiles.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.api import users
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django import http
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from django.utils.translation import ugettext_lazy
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.models import request as request_model
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.logic.models import request as request_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.logic.models import user as user_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views import helper
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
    36
from soc.views import out_of_band
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.views.models import base
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
from soc.views.models import user as user_view
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
import soc.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
import soc.views.helper.widgets
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
class RequestForm(helper.forms.BaseForm):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    45
  """Django form displayed when creating a new invititation/request.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  class Meta:
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    """Inner Meta class that defines some behavior for the form.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    #: db.Model subclass for which the form will gather information
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
    model = soc.models.request.Request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
528
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 521
diff changeset
    55
    #: Exclude pretty much everything, model=None would 
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 521
diff changeset
    56
    #: also remove the help text etc. 
569
96d9655a7538 Remove inheritance_line from Form meta class excludes in all currently used forms.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 560
diff changeset
    57
    exclude = ['requester', 'to', 'role', 
528
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 521
diff changeset
    58
        'accepted', 'declined']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  requester = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
  role = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
  to = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
class RoleView(base.View):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    68
  """Views for all entities that inherit from Role.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
  All views that only Role entities have are defined in this subclass.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
  """
518
d9d31d316a74 Changes the list template to use an instruction_text property that sets the text above the list. This makes the create_invite template unneeded. The instruction_text comes in handy when defining special lists.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 512
diff changeset
    72
  
538
4d209757c835 Make it more obvious that a format string constant is a format string by
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
    73
  DEF_INVITE_INSTRUCTION_MSG_FMT = ugettext_lazy(
520
b0c623819b68 Split a too long line
Sverre Rabbelier <srabbelier@gmail.com>
parents: 518
diff changeset
    74
      'Please use this form to invite someone to become a %(name)s.')
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    76
  def __init__(self, original_params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    Args:
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    80
      original_params: This dictionary should be filled with the parameters
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    params = {}
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    84
    params = dicts.merge(original_params, params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    86
    base.View.__init__(self, params=params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
  def invite(self, request, page_name=None, params=None, **kwargs):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    """Displays the request promotion to Role page.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
    92
    if not params:
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
    93
      params = {}
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
    new_params = {}
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
    95
    link_id = kwargs['link_id']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
    97
    new_params['list_action'] = (self.getCreateRequestRedirect, link_id)
528
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 521
diff changeset
    98
    new_params['instruction_text'] = \
538
4d209757c835 Make it more obvious that a format string constant is a format string by
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
    99
        self.DEF_INVITE_INSTRUCTION_MSG_FMT % self._params
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   101
    params = dicts.merge(new_params, params)
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   102
    params = dicts.merge(new_params, user_view.view._params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    try:
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
      self.checkAccess('invite', request)
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   106
    except out_of_band.Error, error:
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   107
      return error.response(request)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
572
1b3e7280743a Made list pagination part of Lists
Sverre Rabbelier <srabbelier@gmail.com>
parents: 569
diff changeset
   109
    content = helper.lists.getListContent(request, params, user_logic.logic)
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   110
    contents = [content]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   112
    return self._list(request, params, contents, page_name)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   114
  def getCreateRequestRedirect(self, entity, group_scope):
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   115
    """Returns the edit redirect for the specified entity
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   118
    result ='/request/create/%s/%s/%s' % (
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   119
        self._params['url_name'], group_scope, entity.link_id)
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   120
    return result
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
  def getDjangoURLPatterns(self):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
   123
    """See base.View.getDjangoURLPatterns().
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
    params = {}
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
    default_patterns = self._params['django_patterns_defaults']
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
    default_patterns += [
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: 500
diff changeset
   129
        (r'^%(url_name)s/invite/%(lnp)s$',
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 538
diff changeset
   130
            'soc.views.models.%s.invite', 'Invite %(name_short)s')]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
    params['django_patterns_defaults'] = default_patterns
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
    patterns = super(RoleView, self).getDjangoURLPatterns(params)
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
    return patterns
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136