app/soc/views/models/base.py
author Sverre Rabbelier <srabbelier@gmail.com>
Tue, 02 Dec 2008 22:04:38 +0000
changeset 653 5105939d3bb4
parent 652 02323664d532
child 662 0e89b027b140
permissions -rw-r--r--
Make the 'select entity' View generic This allows the selection of any entity from an arbitrary View by specifying the 'target view' and the redirect function. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
# 
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
# 
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Helpers functions for displaying views.
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: 428
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
516
ec1dcd70b97e The list method in models/base.py can now use a filter to make a selection of entities to show.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
    23
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
363
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
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import http
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django.utils.translation import ugettext_lazy
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    30
from soc.logic import dicts
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
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
    32
from soc.views import out_of_band
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
    33
from soc.views.helper import access
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
    34
from soc.views.helper import forms
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 612
diff changeset
    35
from soc.views import sitemap
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
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: 639
diff changeset
    37
import soc.logic
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: 639
diff changeset
    38
import soc.logic.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: 639
diff changeset
    39
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: 639
diff changeset
    40
import soc.views.helper.responses
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: 639
diff changeset
    41
import soc.views.helper.params
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: 639
diff changeset
    42
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
    44
class View(object):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  """Views for entity classes.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  The View class functions specific to Entity classes by relying
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  on the the child-classes to define the following fields:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
  self._logic: the logic singleton for this entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    53
  DEF_CREATE_NEW_ENTITY_MSG_FMT = ugettext_lazy(
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
    54
      ' You can create a new %(entity_type)s by visiting'
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    55
      ' <a href="%(create)s">Create '
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
    56
      'a New %(entity_type)s</a> page.')
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    57
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    58
  def __init__(self, params=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
    """
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
    60
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
    61
    Args:
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
    62
      params: This dictionary should be filled with the parameters
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    63
        specific to this entity. See the methods in this class on
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    64
        the fields it should contain, and how they are used.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
    67
    self._params = helper.params.constructParams(params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
    68
    self._logic = params['logic']
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
    69
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    70
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
    71
  def public(self, request, page_name=None, params=None, **kwargs):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
    72
    """Displays the public page for the entity specified by **kwargs.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    74
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    75
      rights: The rights dictionary is used to check if the user has
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    76
        the required rights to view the public page for this entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    77
        See checkAccess for more details on how the rights dictionary
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    78
        is used to check access rights.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    79
      error_public: The error_public value is used as template when
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    80
        the key values (as defined by the page's url) do not
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    81
        correspond to an existing entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    82
      name: The name value is used to set the entity_type in the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    83
        context so that the template can refer to it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    84
      public_template: The public_template value is used as template
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    85
        to display the public page of the found entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
    86
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
    Args:
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
    88
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
    89
      page_name: the page name displayed in templates as page and header title
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
    90
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
      kwargs: the Key Fields for the specified entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
    94
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
    95
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
    try:
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
    97
      access.checkAccess('public', 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
    98
    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: 639
diff changeset
    99
      return helper.responses.errorResponse(error, request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    # create default template context for use with any templates
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   103
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   106
    if not all(kwargs.values()):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   107
      #TODO: Change this into a proper redirect
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   108
      return http.HttpResponseRedirect('/')
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   109
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
    try:
435
829fe8302a8b Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
   111
      key_fields = self._logic.getKeyFieldsFromDict(kwargs)
829fe8302a8b Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
   112
      entity = self._logic.getIfFields(key_fields)
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
   113
    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: 639
diff changeset
   114
      return helper.responses.errorResponse(
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: 639
diff changeset
   115
          error, request, template=params['error_public'], context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   117
    self._public(request, entity, context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
    context['entity'] = entity
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   120
    context['entity_type'] = params['name']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   122
    template = params['public_template']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
    return helper.responses.respond(request, template, context)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   126
  def create(self, request, page_name=None, params=None, **kwargs):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   127
    """Displays the create page for this entity type.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   129
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   130
      The params dictionary is passed on to edit, see the docstring
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   131
      for edit on how it uses it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   132
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   133
    Args:
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   134
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   135
      page_name: the page name displayed in templates as page and header title
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
   136
      params: a dict with params for this View
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   137
      kwargs: not used for create()
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
492
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   140
    params = dicts.merge(params, self._params)
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   141
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
    # Create page is an edit page with no key fields
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   143
    empty_kwargs = {}
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   144
    fields = self._logic.getKeyFieldNames()
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   145
    for field in fields:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   146
      empty_kwargs[field] = None
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   147
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   148
    if not kwargs:
537
f2bd9c465a6d Fix getKeyValues() method footprint mismatches in soc.logic.models.site.Logic
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
   149
      return self.edit(request, page_name=page_name, params=params,
f2bd9c465a6d Fix getKeyValues() method footprint mismatches in soc.logic.models.site.Logic
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
   150
                       **empty_kwargs)
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   151
    else:
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
   152
      return self.edit(request, page_name=page_name, params=params,
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
   153
                       seed=kwargs, **empty_kwargs)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   155
  def edit(self, request, page_name=None, params=None, seed=None, **kwargs):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   156
    """Displays the edit page for the entity specified by **kwargs.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   158
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   159
      The params dictionary is passed on to either editGet or editPost
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   160
      depending on the method type of the request. See the docstring
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   161
      for editGet and editPost on how they use it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   162
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   163
      rights: The rights dictionary is used to check if the user has
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   164
        the required rights to edit (or create) a new entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   165
        See checkAccess for more details on how the rights dictionary
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   166
        is used to check access rights.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   167
      name: The name value is used to construct the message_fmt of the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   168
        raised error when there key_values do not define an existing
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   169
        entity. See DEF_CREATE_NEW_ENTITY_MSG_FMT on how the name
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   170
        (and the lower() version of it) is used.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   171
      missing_redirect: The missing_redirect value is also used to
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   172
        construct the message_fmt mentioned above.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   173
      error_public: The error_public value is used as the template for
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   174
        the error response mentioned above.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   175
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
    Args:
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   177
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   178
      page_name: the page name displayed in templates as page and header title
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
   179
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
      kwargs: The Key Fields for the specified entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   182
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   183
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   184
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
    try:
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   186
      access.checkAccess('edit', 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
   187
    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: 639
diff changeset
   188
      return helper.responses.errorResponse(error, request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   189
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   190
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   191
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   192
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   193
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   194
    try:
439
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   195
      if all(kwargs.values()):
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   196
        key_fields = self._logic.getKeyFieldsFromDict(kwargs)
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   197
        entity = self._logic.getIfFields(key_fields)
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
   198
    except out_of_band.Error, error:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   199
      if not seed:
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
   200
        error.message_fmt = (
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
   201
          error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   202
            'entity_type_lower' : params['name'].lower(),
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   203
            'entity_type' : params['name'],
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
   204
            'create' : params['missing_redirect']})
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: 639
diff changeset
   205
        return helper.responses.errorResponse(
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: 639
diff changeset
   206
            error, request, template=params['error_public'], context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   207
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   208
    if request.method == 'POST':
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   209
      return self.editPost(request, entity, context, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   210
    else:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   211
      return self.editGet(request, entity, context, seed, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   213
  def editPost(self, request, entity, context, params):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   214
    """Processes POST requests for the specified entity.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   215
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   216
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   217
      The params dictionary is passed to _constructResponse when the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   218
      form is not valid (see edit_form and create_form below). See
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   219
      the docstring of _constructResponse on how it uses it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   220
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   221
      edit_form: The edit_form value is used as form when there is an
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   222
        existing entity. It is provided with with the request.POST
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   223
        dictionary on construction. The collectCleanedFields method
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   224
        is called with the newly constructed form. If the form is
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   225
        not valid, it is passed as argument to _constructResponse.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   226
      create_form: The create_form value is used in a similar way to
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   227
        edit_form, only it is used when there is no existing entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   228
      edit_redirect: The edit_redirect value is used as the first part
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   229
        of the url if the form was valid. The last part of the url is
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   230
        created using the getKeySuffix method of the _logic object.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   231
      edit_params: The edit_params dictionary is used as argument to
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   232
        redirectToChangedSuffix, it will be appended to the url in the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   233
        standard ?key=value format.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   234
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   235
    Args:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   236
      request: a django request object
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   237
      entity: the entity that will be modified or created, may be None
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   238
      context: the context dictionary that will be provided to Django
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   239
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   240
    """
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   241
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   242
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   243
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   244
    if entity:
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   245
      form = params['edit_form'](request.POST)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   246
    else:
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   247
      form = params['create_form'](request.POST)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   248
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   249
    if not form.is_valid():
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   250
      return self._constructResponse(request, entity, context, form, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   251
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   252
    key_name, fields = forms.collectCleanedFields(form)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   253
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   254
    request.path = params['edit_redirect']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   255
    self._editPost(request, entity, fields)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   256
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   257
    if not key_name:
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   258
      key_fields =  self._logic.getKeyFieldsFromDict(fields)
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   259
      key_name = self._logic.getKeyNameForFields(key_fields)
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   260
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   261
    entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   262
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   263
    if not entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   264
      return http.HttpResponseRedirect('/')
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   265
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   266
    page_params = params['edit_params']
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   267
    new_suffix = self._logic.getKeySuffix(entity)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   268
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   269
    # redirect to (possibly new) location of the entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   270
    # (causes 'Profile saved' message to be displayed)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   271
    return helper.responses.redirectToChangedSuffix(
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   272
        request, None, new_suffix,
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   273
        params=page_params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   274
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   275
  def editGet(self, request, entity, context, seed, params):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   276
    """Processes GET requests for the specified entity.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   277
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   278
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   279
      The params dictionary is passed to _constructResponse, see the
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   280
      docstring  of _constructResponse on how it uses it.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   281
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   282
      save_message: The save_message list is used as argument to
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   283
        getSingleIndexedParamValue when an existing entity was saved.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   284
      edit_form: The edit_form is used as form if there is an existing
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   285
        entity. The existing entity is passed as instance to it on
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   286
        construction. If key_name is part of it's fields it will be
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   287
        set to the entity's key().name() value. It is also passed as
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   288
        argument to the _editGet method. See the docstring for
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   289
        _editGet on how it uses it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   290
      create_form: The create_form is used as form if there was no
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   291
        existing entity. If the seed argument is present, it is passed
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   292
        as the 'initial' argument on construction. Otherwise, it is
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   293
        called with no arguments.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
   294
      submit_msg_param_name: The submit_msg_param_name value is used
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
   295
        as the key part in the ?key=value construct for the submit
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
   296
        message parameter (see also save_message).
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   297
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   298
    Args:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   299
      request: the django request object
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   300
      entity: the entity that will be edited, may be None
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   301
      context: the context dictionary that will be provided to django
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   302
      seed: if no entity is provided, the initial values for the new entity
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   303
      params: a dict with paras for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   304
    """
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   305
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   306
    params = dicts.merge(params, self._params)
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   307
    suffix = self._logic.getKeySuffix(entity)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   308
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   309
    # Remove the params from the request, this is relevant only if
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   310
    # someone bookmarked a POST page.
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
   311
    is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
   312
    if request.GET.get(params['submit_msg_param_name']):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   313
      if (not entity) or (not is_self_referrer):
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   314
        return http.HttpResponseRedirect(request.path)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   315
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   316
    if entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   317
      # Note: no message will be displayed if parameter is not present
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   318
      context['notice'] = helper.requests.getSingleIndexedParamValue(
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 610
diff changeset
   319
          request, params['submit_msg_param_name'],
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   320
          values=params['save_message'])
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   321
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   322
      # populate form with the existing entity
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   323
      form = params['edit_form'](instance=entity)
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   324
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   325
      if 'key_name' in form.fields:
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   326
        form.fields['key_name'].initial = entity.key().name()
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   327
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   328
      self._editGet(request, entity, form)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   329
    else:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   330
      if seed:
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   331
        self._editSeed(request, seed)
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   332
        form = params['create_form'](initial=seed)
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   333
      else:
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   334
        form = params['create_form']()
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   335
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   336
    return self._constructResponse(request, entity, context, form, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   337
516
ec1dcd70b97e The list method in models/base.py can now use a filter to make a selection of entities to show.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   338
  def list(self, request, page_name=None, params=None, filter=None):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   339
    """Displays the list page for the entity type.
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   340
    
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   341
    Args:
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   342
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   343
      page_name: the page name displayed in templates as page and header title
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
   344
      params: a dict with params for this View
516
ec1dcd70b97e The list method in models/base.py can now use a filter to make a selection of entities to show.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   345
      filter: a dict for the properties that the entities should have
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   346
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   347
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   348
      The params dictionary is passed as argument to getListContent in
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   349
      the soc.views.helper.list module. See the docstring for getListContent 
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   350
      on how it uses it. The params dictionary is also passed as argument to 
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   351
      the _list method. See the docstring for _list on how it uses it.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   352
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   353
      rights: The rights dictionary is used to check if the user has
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   354
        the required rights to list all entities of this View's type.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   355
        See checkAccess for more details on how the rights dictionary
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   356
        is used to check access rights.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   357
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   358
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   359
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   360
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   361
    try:
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   362
      access.checkAccess('list', 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
   363
    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: 639
diff changeset
   364
      return helper.responses.errorResponse(error, request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   365
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   366
    content = helper.lists.getListContent(request, params, filter)
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   367
    contents = [content]
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   368
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   369
    return self._list(request, params, contents, page_name)
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   370
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   371
  def _list(self, request, params, contents, page_name):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   372
    """Returns the list page for the specified contents.
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   373
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   374
    Args:
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   375
      request: the standard Django HTTP request object
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   376
      params: a dict with params for this View
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   377
      contents: a list of content dicts
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   378
      page_name: the page name displayed in templates as page and header title
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   379
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   380
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   381
      name: The name value is used to set the entity_type in the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   382
        context so that the template can refer to it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   383
      name_plural: The name_plural value is used to set
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   384
        the entity_type_plural value in the context so that the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   385
        template can refer to it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   386
      list_template: The list_template value is used as template for
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   387
        to display the list of all entities for this View.
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   388
    """
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   389
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   390
    context = helper.responses.getUniversalContext(request)
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   391
    context['page_name'] = page_name
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   392
    context['list'] = soc.logic.lists.Lists(contents)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   393
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   394
    context['entity_type'] = params['name']
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   395
    context['entity_type_plural'] = params['name_plural']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   396
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   397
    template = params['list_template']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   398
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   399
    return helper.responses.respond(request, template, context)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   400
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   401
  def delete(self, request, page_name=None, params=None, **kwargs):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   402
    """Shows the delete page for the entity specified by **kwargs.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   403
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   404
    Args:
373
dcd7013ae0d5 Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents: 363
diff changeset
   405
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   406
      page_name: the page name displayed in templates as page and header title
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
   407
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   408
      kwargs: The Key Fields for the specified entity
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   409
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   410
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   411
      rights: The rights dictionary is used to check if the user has
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   412
        the required rights to delete the specified entity. See checkAccess 
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   413
        for more details on how the rights dictionary is used to check access 
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   414
        rights.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   415
      name: used in the same way as in edit(), see it's docstring for
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   416
        a more detailed explanation on how it is used.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   417
      missing_redirect: see name
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   418
      error_edit: see name
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   419
      delete_redirect: The delete_redirect value is used as the url to
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   420
        redirect to after having successfully deleted the entity.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   421
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   422
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   423
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   424
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   425
    try:
612
3cca81b1e5a1 Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   426
      access.checkAccess('delete', 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
   427
    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: 639
diff changeset
   428
      return helper.responses.errorResponse(error, request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   429
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   430
    # create default template context for use with any templates
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   431
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   432
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   433
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   434
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   435
    try:
438
af082c92ddda Quick fix to fix user profile creation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 435
diff changeset
   436
      key_fields = self._logic.getKeyFieldsFromDict(kwargs)
435
829fe8302a8b Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
   437
      entity = self._logic.getIfFields(key_fields)
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
   438
    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
   439
      error.message_fmt = (
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
   440
        error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   441
          'entity_type_lower' : params['name'].lower(),
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   442
          'entity_type' : params['name'],
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
   443
          'create' : params['missing_redirect']})
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: 639
diff changeset
   444
      return helper.responses.errorResponse(
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: 639
diff changeset
   445
          error, request, template=params['error_edit'], context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   446
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   447
    if not entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   448
      #TODO: Create a proper error page for this
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   449
      return http.HttpResponseRedirect('/')
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   450
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   451
    if not self._logic.isDeletable(entity):
389
9b873166d7d5 Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 387
diff changeset
   452
      # TODO: Update the notice area telling the user that they
9b873166d7d5 Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 387
diff changeset
   453
      # can't delete the entity
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   454
      pass
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   455
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   456
    self._logic.delete(entity)
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   457
    redirect = params['delete_redirect']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   458
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   459
    return http.HttpResponseRedirect(redirect)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   460
653
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   461
  def select(self, request, view, redirect, page_name=None, params=None):
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   462
    """Displays a list page allowing the user to select an entity
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   463
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   464
    After having selected the Sponsor, the user is redirected to the
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   465
    'create a new program' page with the scope_path set appropriately.
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   466
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   467
    Params usage:
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   468
      The params dictionary is also passed to getListContent from
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   469
        the helper.list module, please refer to its docstring also.
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   470
      The params dictionary is passed to self._list as well, refer
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   471
        to its docstring for details on how it uses it.
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   472
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   473
    Args:
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   474
      request: the standard Django HTTP request object
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   475
      page_name: the page name displayed in templates as page and header title
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   476
      params: a dict with params for this View
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   477
    """
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   478
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   479
    params = dicts.merge(params, view.getParams())
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   480
    params = dicts.merge(params, self._params)
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   481
    params['list_action'] = (redirect, self._params)
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   482
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   483
    content = helper.lists.getListContent(request, params)
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   484
    contents = [content]
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   485
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   486
    return self._list(request, params, contents, page_name)
5105939d3bb4 Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   487
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   488
  def _editPost(self, request, entity, fields):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   489
    """Performs any required processing on the entity to post its edit page.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   490
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   491
    Args:
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   492
      request: the django request object
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   493
      entity: the entity to create or update from POST contents
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   494
      fields: the new field values
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   495
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   496
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   497
    pass
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   498
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   499
  def _public(self, request, entity, context):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   500
    """Performs any required processing to get an entities public page.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   501
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   502
    Args:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   503
      request: the django request object
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   504
      entity: the entity to make public
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   505
      context: the context object
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   506
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   507
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   508
    pass
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   509
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   510
  def _editGet(self, request, entity, form):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   511
    """Performs any required processing on the form to get its edit page.
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   512
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   513
    Args:
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   514
      request: the django request object
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   515
      entity: the entity to get
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   516
      form: the django form that will be used for the page
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   517
    """
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   518
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   519
    pass
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   520
497
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   521
  def _editSeed(self, request, seed):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   522
    """Performs any required processing on the form to get its edit page.
497
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   523
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   524
    Args:
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   525
      request: the django request object
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   526
      seed: the fields to seed the create page with
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   527
    """
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   528
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   529
    pass
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   530
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   531
  def _constructResponse(self, request, entity, context, form, params):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   532
    """Updates the context and returns a response for the specified arguments.
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   533
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   534
    Args:
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   535
      request: the django request object
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   536
      entity: the entity that is used and set in the context
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   537
      context: the context to be used
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   538
      form: the form that will be used and set in the context
471
dcb1f7821b39 Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 459
diff changeset
   539
      params: a dict with params for this View
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   540
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   541
    Params usage:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   542
      name: The name_plural value is used to set the entity_type
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   543
       value in the context so that the template can refer to it.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   544
      name_plural: same as name, but used to set entity_type_plural
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   545
      name_short: same as name, but used to set entity_type_short
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   546
      url_name: same as name, but used to set entity_type_url
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   547
      edit_template: The edit_template value is used as template when
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   548
        there is an existing entity to display the edit page for the
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   549
        specified entity.
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   550
      create_template: similar to edit_template, but is used when
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   551
        there is no existing entity.
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   552
    """
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   553
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   554
    suffix = self._logic.getKeySuffix(entity)
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   555
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   556
    context['form'] = form
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   557
    context['entity'] = entity
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   558
    context['entity_suffix'] = suffix
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   559
    context['entity_type'] = params['name']
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   560
    context['entity_type_plural'] = params['name_plural']
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   561
    context['entity_type_short'] = params['name_short']
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
   562
    context['entity_type_url'] = params['url_name']
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   563
576
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   564
    if entity:
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   565
      template = params['edit_template']
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   566
    else:
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   567
      template = params['create_template']
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   568
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   569
    return helper.responses.respond(request, template, context)
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   570
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   571
  def getParams(self):
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   572
    """Returns this view's params attribute
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   573
    """
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   574
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   575
    return self._params
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   576
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   577
  def getSidebarLinks(self, request, params=None):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
diff changeset
   578
    """Returns an dictionary with one sidebar entry.
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   579
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   580
    Args:
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   581
      request: the django request object
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   582
      params: a dict with params for this View
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   583
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   584
    Params usage:
614
53a3e46fc512 Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
   585
      The params dictionary is passed as argument to getSidebarItems
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   586
      from the soc.views.sitemap.sidebar module, see the docstring
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   587
      of _getSidebarItems on how it uses it.
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   588
    """
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   589
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   590
    params = dicts.merge(params, self._params)
615
1d09147de51f Fixed a bug in latest commit
Sverre Rabbelier <srabbelier@gmail.com>
parents: 614
diff changeset
   591
    return sitemap.sidebar.getSidebarLinks(request, params)
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   592
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   593
  def getDjangoURLPatterns(self, params=None):
614
53a3e46fc512 Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
   594
    """Retrieves a list of sidebar entries for this view
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   595
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   596
    Params usage:
614
53a3e46fc512 Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
   597
      The params dictionary is passed to the getDjangoURLPatterns
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   598
      function in the soc.views.sitemap.sitemap module, see the
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 632
diff changeset
   599
      docstring of getDjangoURLPatterns on how it uses it.
610
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   600
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   601
    Args:
e0bd276ffd82 Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 606
diff changeset
   602
      params: a dict with params for this View
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   603
    """
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   604
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   605
    params = dicts.merge(params, self._params)
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 612
diff changeset
   606
    return sitemap.sitemap.getDjangoURLPatterns(params)