app/soc/views/models/request.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 21 Jan 2009 19:32:00 +0000
changeset 882 267e31f1a0b6
parent 876 0c1329d4b514
child 890 b3bf833c4580
permissions -rw-r--r--
Added club_app model and logic. Patch by: Lennard de Rijk
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 Requests.
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
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
    '"Pawel Solyga" <pawel.solyga@gmail.com>',
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
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 google.appengine.api import users
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from django import forms
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from django.utils.translation import ugettext_lazy
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
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 sponsor as sponsor_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
557
c6d9f8581730 Added missing import
Lennard de Rijk <ljvderijk@gmail.com>
parents: 556
diff changeset
    36
from soc.views import out_of_band
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    37
from soc.views.helper import access
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    38
from soc.views.helper import decorators
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 618
diff changeset
    39
from soc.views.helper import redirects
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
from soc.views.models import base
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
import soc.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
import soc.logic.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
import soc.logic.dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
import soc.views.helper
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: 629
diff changeset
    46
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: 629
diff changeset
    47
import soc.views.helper.responses
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
import soc.views.helper.widgets
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    50
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
class CreateForm(helper.forms.BaseForm):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  """Django form displayed when Developer creates a Request.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  class Meta:
629
492df53e4a0f Add missing dots and fix too long line in soc.views.helper.dynaform module. Remove unused imports in soc.views.models.document module. Fix too long lines. Add missing docstring for Meta classes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 626
diff changeset
    56
    """Inner Meta class that defines some behavior for the form.
492df53e4a0f Add missing dots and fix too long line in soc.views.helper.dynaform module. Remove unused imports in soc.views.models.document module. Fix too long lines. Add missing docstring for Meta classes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 626
diff changeset
    57
    """
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
    model = soc.models.request.Request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    60
    #: list of model fields which will *not* be gathered by the form
569
96d9655a7538 Remove inheritance_line from Form meta class excludes in all currently used forms.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 562
diff changeset
    61
    exclude = ['scope', 'scope_path', 'link_id', 'role', 'declined']
495
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
  role = 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
  user = forms.CharField(
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
    66
      label=soc.models.request.Request.link_id.verbose_name,
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
    67
      help_text=soc.models.request.Request.link_id.help_text,
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
    68
      widget=helper.widgets.ReadOnlyInput())
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
  group = forms.CharField(
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
    71
      label=soc.models.request.Request.scope.verbose_name,
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
    72
      help_text=soc.models.request.Request.scope.help_text,
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
      widget=helper.widgets.ReadOnlyInput())
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
  def clean_user(self):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    self.cleaned_data['requester'] =  user_logic.logic.getForFields(
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    77
        {'link_id': self.cleaned_data['user']}, unique=True)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
    return self.cleaned_data['user']
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
  def clean_group(self):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    self.cleaned_data['to'] = sponsor_logic.logic.getFromFields(
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    82
        link_id=self.cleaned_data['group'])
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    return self.cleaned_data['group']
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    85
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
class EditForm(CreateForm):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
  """Django form displayed when Developer edits a Request.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
  pass
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
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
    94
  """View methods for the Docs model.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    97
  def __init__(self, params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
    """Defines the fields and methods required for the base View class
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
    to provide the user with list, public, create, edit and delete views.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   102
      params: a dict with params for this View
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
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
   105
    rights = {}
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
   106
    rights['listSelf'] = [access.checkIsUser]
720
9eb2522dfa83 Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents: 710
diff changeset
   107
    rights['create'] = [access.checkCanInvite]
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
   108
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   109
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   110
    new_params['rights'] = rights
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   111
    new_params['logic'] = soc.logic.models.request.logic
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   113
    new_params['name'] = "Request"
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   115
    new_params['edit_form'] = EditForm
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   116
    new_params['create_form'] = CreateForm
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   118
    new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', 'list')]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   120
    new_params['save_message'] = [ugettext_lazy('Request saved.')]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   122
    params = dicts.merge(params, new_params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   124
    super(View, self).__init__(params=params)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   125
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   126
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   127
  @decorators.check_access
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   128
  def listSelf(self, request, access_type,
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   129
               page_name=None, params=None, **kwargs):
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   130
    """Displays the unhandled requests for this user.
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   131
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   132
    Args:
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   133
      request: the standard Django HTTP request object
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   134
      page_name: the page name displayed in templates as page and header title
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   135
      params: a dict with params for this View
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   136
      kwargs: not used
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   137
    """
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   138
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   139
    # get the current user
521
07b2c382a4d6 Minor improvements to roles page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 519
diff changeset
   140
    properties = {'account': users.get_current_user()}
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   141
    user_entity = user_logic.logic.getForFields(properties, unique=True)
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   142
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   143
    # construct the Unhandled Requests list
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   144
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   145
    # only select the requests for this user that haven't been handled yet
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   146
    filter = {'link_id': user_entity.link_id,
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   147
              'group_accepted' : True}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   148
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   149
    uh_params = params.copy()
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 618
diff changeset
   150
    uh_params['list_action'] = (redirects.inviteAcceptedRedirect, None)
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   151
    uh_params['list_description'] = ugettext_lazy(
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   152
        "An overview of your unhandled requests.")
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   153
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   154
    uh_list = helper.lists.getListContent(
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   155
        request, uh_params, filter, 0)
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   156
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   157
    # construct the Open Requests list
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   158
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   159
    # only select the requests for the user
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   160
    # that haven't been accepted by an admin yet
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   161
    filter = {'link_id' : user_entity.link_id,
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   162
              'group_accepted' : False}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   163
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   164
    ar_params = params.copy()
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   165
    ar_params['list_description'] = ugettext_lazy(
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   166
        "List of your pending requests.")
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   167
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   168
    ar_list = helper.lists.getListContent(
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   169
        request, ar_params, filter, 1)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   170
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   171
    # fill contents with all the needed lists
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   172
    contents = [uh_list, ar_list]
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   173
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   174
    # call the _list method from base to display the list
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   175
    return self._list(request, params, contents, page_name)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
  def _editSeed(self, request, seed):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
    """See base.View._editGet().
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   179
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
    # fill in the email field with the data from the entity
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   182
    seed['user'] = seed['link_id']
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   183
    seed['group'] = seed['scope_path']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   184
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
  def _editGet(self, request, entity, form):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   186
    """See base.View._editGet().
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   187
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   188
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   189
    # fill in the email field with the data from the entity
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   190
    form.fields['user'].initial = entity.link_id
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   191
    form.fields['group'].initial = entity.scope_path
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   192
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   193
    super(View, self)._editGet(request, entity, form)
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   194
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   195
  def _editPost(self, request, entity, fields):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   196
    """See base.View._editPost().
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   197
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   198
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   199
    # fill in the account field with the user created from email
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   200
    fields['link_id'] = fields['requester'].link_id
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   201
    fields['scope_path'] = fields['to'].link_id
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   202
    fields['scope'] = fields['to']
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   203
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   204
    super(View, self)._editPost(request, entity, fields)
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   205
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   206
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   207
view = View()
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   208
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   209
create = view.create
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   210
edit = view.edit
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   211
delete = view.delete
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
list = view.list
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   213
list_self = view.listSelf
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   214
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 822
diff changeset
   215
export = view.export
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 822
diff changeset
   216