app/soc/views/models/role.py
author Todd Larsen <tlarsen@google.com>
Wed, 21 Jan 2009 00:27:39 +0000
changeset 858 e79e7a22326f
parent 837 bc1c951bf3a0
child 876 0c1329d4b514
permissions -rw-r--r--
Add an export() view, and implement it as text/text for Document. For every Model except Document, the public() view is displayed for any attempts to access the export() view. Currently, the permissions for export() are the same as for public(). This seems reasonable for Document, since anyone could extract the raw HTML from the page source anyway. The permissions should probably be different for other types of exports, such as vCard or iCard exports of profiles, CSV exports of lists, etc. Patch by: Todd Larsen Review by: to-be-reviewed
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
837
bc1c951bf3a0 Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 755
diff changeset
    17
"""Views for Role profiles.
495
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 django import forms
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django.utils.translation import ugettext_lazy
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic.models import user as user_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
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
    31
from soc.views import out_of_band
616
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    32
from soc.views.helper import access
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 616
diff changeset
    33
from soc.views.helper import redirects
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views.models import base
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.models import user as user_view
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
import soc.models.request
646
860e17e5118f Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 624
diff changeset
    38
import soc.views.helper.lists
860e17e5118f Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 624
diff changeset
    39
import soc.views.helper.responses
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
import soc.views.helper.widgets
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
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
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
    44
  """Django form displayed when creating a new invititation/request.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  """
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
  class Meta:
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    """Inner Meta class that defines some behavior for the form.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    """
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
    #: db.Model subclass for which the form will gather information
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    model = soc.models.request.Request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
528
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 521
diff changeset
    54
    #: 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
    55
    #: 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
    56
    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
    57
        'accepted', 'declined']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  requester = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
  role = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
  to = forms.CharField(widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
657
c781de4f6d39 Rename role.RoleView to role.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    66
class View(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
    67
  """Views for all entities that inherit from Role.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
  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
    70
  """
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
    71
  
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
    72
  DEF_INVITE_INSTRUCTION_MSG_FMT = ugettext_lazy(
520
b0c623819b68 Split a too long line
Sverre Rabbelier <srabbelier@gmail.com>
parents: 518
diff changeset
    73
      '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
    74
616
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    75
  def __init__(self, params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    """
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
    Args:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    79
      params: This dictionary should be filled with the parameters
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    82
    new_params = {}
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    83
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 708
diff changeset
    84
    patterns = [(r'^%(url_name)s/(?P<access_type>invite)/%(lnp)s$',
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    85
        'soc.views.models.%(module_name)s.invite',
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    86
        'Invite %(name_short)s')]
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    87
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    88
    new_params['extra_django_patterns'] = patterns
663
c2dcae606699 Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    89
    new_params['scope_redirect'] = redirects.getInviteRedirect
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    90
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    91
    params = dicts.merge(params, new_params)
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    92
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    93
    super(View, self).__init__(params=params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 708
diff changeset
    95
  def invite(self, request, access_type,
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 708
diff changeset
    96
             page_name=None, params=None, **kwargs):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
    """Displays the request promotion to Role page.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
    new_params = {}
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   101
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 616
diff changeset
   102
    group_scope = kwargs['link_id']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   104
    new_params['list_action'] = (redirects.getCreateRequestRedirect,
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 616
diff changeset
   105
        {'group_scope' : group_scope,
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   106
        'url_name' : self._params['url_name']})
647
355ac73823a1 Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   107
    new_params['list_description'] = \
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
   108
        self.DEF_INVITE_INSTRUCTION_MSG_FMT % self._params
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   109
    new_params['logic'] = user_logic.logic
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   111
    new_params = dicts.merge(params, new_params)
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   112
    params = dicts.merge(new_params, user_view.view._params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
    try:
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 708
diff changeset
   115
      access.checkAccess(access_type, request, rights=params['rights'])
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
   116
    except out_of_band.Error, error:
646
860e17e5118f Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 624
diff changeset
   117
      return helper.responses.errorResponse(error, request)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 647
diff changeset
   119
    content = helper.lists.getListContent(request, params)
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   120
    contents = [content]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 543
diff changeset
   122
    return self._list(request, params, contents, page_name)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   123