app/soc/views/models/base.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 26 Nov 2008 15:52:38 +0000
changeset 588 d6ae9dd215fb
parent 587 7504504209a3
child 591 530fa94faffe
permissions -rw-r--r--
Fixes an error that occurs when moving the document by setting another link ID or Scope path. This is due to the fact that author is a required property in the Work model. Patch by: Lennard de Rijk
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
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    28
from django.conf.urls import defaults
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from django.utils.translation import ugettext_lazy
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
import soc.logic
539
e30462354e26 Allow for multiple list objects
Sverre Rabbelier <srabbelier@gmail.com>
parents: 537
diff changeset
    32
import soc.logic.lists
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
import soc.views.helper.lists
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
import soc.views.helper.responses
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    36
from soc.logic import dicts
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.logic import models
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
    38
from soc.models import linkable
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
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
    40
from soc.views import out_of_band
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
from soc.views.helper import access
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
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
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    53
  DEF_SUBMIT_MSG_PARAM_NAME = 's'
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
    54
  DEF_SUBMIT_MSG_PROFILE_SAVED = 0
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    55
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    56
  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
    57
      ' 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
    58
      ' <a href="%(create)s">Create '
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
    59
      'a New %(entity_type)s</a> page.')
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    60
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    61
  def __init__(self, params=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
    """
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
    63
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
    64
    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
    65
      params: This dictionary should be filled with the parameters
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    66
        specific to this entity, required fields are:
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    67
        rights: This dictionary should be filled with the access check
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    68
                functions that should be called
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    69
        name: the name of the entity (names should have sentence-style caps) 
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    70
        name_short: the short form name of the name ('org' vs 'organization')
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    71
        name_plural: the plural form of the name
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
    72
        url_name: the name of the entity used in urls
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    73
        edit_form: the class of the Django form to be used when editing
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    74
        create_form: the class of the Django form to be used when creating
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    75
        edit_template: the Django template to be used for editing
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    76
        public_template: the Django template to be used as public page 
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    77
        list_template: the Django template to be used as list page
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    78
        lists_template: the Django templates to search for the list page
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    79
        delete_redirect: the Django template to redirect to on delete
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    80
        create_redirect: the Django template to redirect to after creation
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    81
        save_message: the message to display when the entity is saved
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
    82
        edit_params: the params to use when editing
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
    83
        sidebar: the sidebar menu items for this view
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    84
        sidebar_defaults: a dictionary with defaults for the sidebar; each
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    85
          value in the dict is a two-tuple:
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    86
          (url_format,       # supplied a single positional url_name
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
    87
           menu_text_format) # supplied the params dict
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    90
    rights = {}
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    91
    rights['unspecified'] = []
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    92
    rights['any_access'] = [access.checkIsLoggedIn]
551
2ee7ad5266a8 Define a default for rights['public'] in views/models/base.py. Alter rights
Todd Larsen <tlarsen@google.com>
parents: 548
diff changeset
    93
    rights['public'] = [access.checkIsUser]
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    94
    rights['create'] = [access.checkIsDeveloper]
509
e8acc0a907fb Adds the rights['edit'] to models/base.py wich was left out in r1049.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 507
diff changeset
    95
    rights['edit'] = [access.checkIsDeveloper]
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    96
    rights['delete'] = [access.checkIsDeveloper]
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    97
    rights['list'] = [access.checkIsDeveloper]
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    99
    if 'rights' in params:
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
   100
      rights = dicts.merge(params['rights'], rights)
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
   101
492
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   102
    new_params = {}
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   103
    new_params['rights'] = rights
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   104
    new_params['create_redirect'] = '/%(url_name)s' % params
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   105
    new_params['edit_redirect'] = '/%(url_name)s/edit' % params
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   106
    new_params['missing_redirect'] = '/%(url_name)s/create' % params
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   107
    new_params['delete_redirect'] = '/%(url_name)s/list' % params
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   108
    new_params['invite_redirect'] = '/request/list'
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
   109
    
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   110
    new_params['sidebar'] = None
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   111
    new_params['sidebar_defaults'] = [
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   112
     ('/%s/create', 'New %(name)s', 'create'),
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   113
     ('/%s/list', 'List %(name_plural)s', 'list'),
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   114
    ]
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   115
    new_params['sidebar_additional'] = []
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   116
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   117
    new_params['key_fields_prefix'] = []
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   118
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   119
    new_params['django_patterns'] = None
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   120
    new_params['django_patterns_defaults'] = [
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
   121
        (r'^%(url_name)s/show/%(key_fields)s$', 
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   122
            'soc.views.models.%s.public', 'Show %(name_short)s'),
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
   123
        (r'^%(url_name)s/create$',
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   124
            'soc.views.models.%s.create', 'Create %(name_short)s'),
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
   125
        (r'^%(url_name)s/create/%(key_fields)s$',
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   126
            'soc.views.models.%s.create', 'Create %(name_short)s'),
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
   127
        (r'^%(url_name)s/delete/%(key_fields)s$',
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   128
            'soc.views.models.%s.delete', 'Delete %(name_short)s'),
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 500
diff changeset
   129
        (r'^%(url_name)s/edit/%(key_fields)s$',
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   130
            'soc.views.models.%s.edit', 'Edit %(name_short)s'),
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
   131
        (r'^%(url_name)s/list$',
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   132
            'soc.views.models.%s.list', 'List %(name_plural)s'),
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   133
        ]
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   134
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   135
    new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   136
    new_params['create_template'] = 'soc/models/edit.html'
553
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   137
    new_params['edit_template'] = 'soc/models/edit.html'
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   138
    new_params['list_template'] = 'soc/models/list.html'
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   139
    new_params['invite_template'] = 'soc/models/invite.html'
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   140
573
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   141
    new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   142
    new_params['error_edit'] = 'soc/%(module_name)s/error.html'  % params
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   143
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   144
    new_params['list_main'] = 'soc/list/main.html'
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   145
    new_params['list_pagination'] = 'soc/list/pagination.html'
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   146
    new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   147
    new_params['list_heading'] = 'soc/%(module_name)s/list/heading.html' % params
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   148
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   149
    new_params['list_action'] = (self.getEditRedirect, None)
553
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   150
    new_params['list_params'] = {
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   151
        'list_action': 'action',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   152
        'list_description': 'description',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   153
        'list_main': 'main',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   154
        'list_pagination': 'pagination',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   155
        'list_row': 'row',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   156
        'list_heading': 'heading',
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 552
diff changeset
   157
        }
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   158
539
e30462354e26 Allow for multiple list objects
Sverre Rabbelier <srabbelier@gmail.com>
parents: 537
diff changeset
   159
    description = ugettext_lazy('List of %(name)s in Google Open Source Programs.')
e30462354e26 Allow for multiple list objects
Sverre Rabbelier <srabbelier@gmail.com>
parents: 537
diff changeset
   160
    new_params['list_description'] = description % params
514
55bd39dab49c Move saved message to the base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 512
diff changeset
   161
    new_params['save_message'] = [ugettext_lazy('Profile saved.')]
55bd39dab49c Move saved message to the base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 512
diff changeset
   162
    new_params['edit_params'] = {
55bd39dab49c Move saved message to the base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 512
diff changeset
   163
        self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
55bd39dab49c Move saved message to the base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 512
diff changeset
   164
        }
55bd39dab49c Move saved message to the base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 512
diff changeset
   165
492
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   166
    self._params = dicts.merge(params, new_params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   167
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   168
  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
   169
    """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
   170
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   171
    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
   172
      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
   173
      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
   174
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
      kwargs: the Key Fields for the specified entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   178
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   179
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
    try:
428
e0d5de282004 Fixed typo in access check
Sverre Rabbelier <srabbelier@gmail.com>
parents: 418
diff changeset
   181
      self.checkAccess('public', request)
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   182
    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
   183
      return error.response(request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   184
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
    # create default template context for use with any templates
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   186
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   187
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   188
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   189
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   190
    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
   191
      #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
   192
      return http.HttpResponseRedirect('/')
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   193
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   194
    try:
435
829fe8302a8b Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
   195
      key_fields = self._logic.getKeyFieldsFromDict(kwargs)
829fe8302a8b Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
   196
      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
   197
    except out_of_band.Error, error:
573
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   198
      return error.response(request, template=params['error_public'],
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
   199
                            context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   200
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   201
    self._public(request, entity, context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   202
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   203
    context['entity'] = entity
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   204
    context['entity_type'] = params['name']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   205
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   206
    template = params['public_template']
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
    return helper.responses.respond(request, template, context)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   209
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   210
  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
   211
    """Displays the create page for this entity type.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
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
   213
    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
   214
      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
   215
      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
   216
      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
   217
      kwargs: not used for create()
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   218
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   219
492
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   220
    params = dicts.merge(params, self._params)
4abdeedfc08e Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents: 490
diff changeset
   221
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   222
    # 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
   223
    empty_kwargs = {}
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   224
    fields = self._logic.getKeyFieldNames()
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   225
    for field in fields:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   226
      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
   227
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   228
    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
   229
      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
   230
                       **empty_kwargs)
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   231
    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
   232
      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
   233
                       seed=kwargs, **empty_kwargs)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   234
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   235
  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
   236
    """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
   237
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   238
    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
   239
      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
   240
      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
   241
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   242
      kwargs: The Key Fields for the specified entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   243
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   244
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   245
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   246
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   247
    try:
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   248
      self.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
   249
    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
   250
      return error.response(request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   251
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
   252
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   253
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   254
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   255
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   256
    try:
439
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   257
      if all(kwargs.values()):
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   258
        key_fields = self._logic.getKeyFieldsFromDict(kwargs)
0658c3c9a9dc Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 438
diff changeset
   259
        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
   260
    except out_of_band.Error, error:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   261
      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
   262
        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
   263
          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
   264
            'entity_type_lower' : params['name'].lower(),
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   265
            '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
   266
            'create' : params['missing_redirect']})
573
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   267
        return error.response(request, template=params['error_public'],
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
   268
                              context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   269
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   270
    if request.method == 'POST':
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   271
      return self.editPost(request, entity, context, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   272
    else:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   273
      return self.editGet(request, entity, context, seed, 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 editPost(self, request, entity, context, 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
   276
    """Same as edit, but on POST.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   277
    """
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   278
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   279
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   280
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   281
    if entity:
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   282
      form = params['edit_form'](request.POST)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   283
    else:
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   284
      form = params['create_form'](request.POST)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   285
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   286
    if not form.is_valid():
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   287
      return self._constructResponse(request, entity, context, form, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   288
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   289
    key_name, fields = self.collectCleanedFields(form)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   290
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   291
    request.path = params['edit_redirect']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   292
    self._editPost(request, entity, fields)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   293
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   294
    if not key_name:
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   295
      key_fields =  self._logic.getKeyFieldsFromDict(fields)
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   296
      key_name = self._logic.getKeyNameForFields(key_fields)
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   297
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   298
    entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   299
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   300
    if not entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   301
      return http.HttpResponseRedirect('/')
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   302
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   303
    page_params = params['edit_params']
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   304
    new_suffix = self._logic.getKeySuffix(entity)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   305
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   306
    # redirect to (possibly new) location of the entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   307
    # (causes 'Profile saved' message to be displayed)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   308
    return helper.responses.redirectToChangedSuffix(
563
4a8565ce48c6 Fixed redirects to work consistently
Sverre Rabbelier <srabbelier@gmail.com>
parents: 560
diff changeset
   309
        request, None, new_suffix,
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   310
        params=page_params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   311
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   312
  def editGet(self, request, entity, context, seed, 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
   313
    """Same as edit, but on GET.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   314
    """
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   315
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   316
    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
   317
    suffix = self._logic.getKeySuffix(entity)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   318
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   319
    # 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
   320
    # someone bookmarked a POST page.
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 373
diff changeset
   321
    is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
   322
    if request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   323
      if (not entity) or (not is_self_referrer):
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   324
        return http.HttpResponseRedirect(request.path)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   325
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   326
    if entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   327
      # 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
   328
      context['notice'] = helper.requests.getSingleIndexedParamValue(
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
   329
          request, self.DEF_SUBMIT_MSG_PARAM_NAME,
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   330
          values=params['save_message'])
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   331
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   332
      # 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
   333
      form = params['edit_form'](instance=entity)
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   334
      if 'key_name' in form.fields:
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   335
        form.fields['key_name'].initial = entity.key().name()
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   336
      self._editGet(request, entity, form)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   337
    else:
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   338
      if seed:
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   339
        self._editSeed(request, seed)
490
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   340
        form = params['create_form'](initial=seed)
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   341
      else:
7cfa2ad62944 Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 482
diff changeset
   342
        form = params['create_form']()
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   343
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   344
    return self._constructResponse(request, entity, context, form, params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   345
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
   346
  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
   347
    """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
   348
    
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
   349
    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
   350
      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
   351
      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
   352
      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
   353
      filter: a dict for the properties that the entities should have
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   354
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   355
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   356
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   357
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   358
    try:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   359
      self.checkAccess('list', request)
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   360
    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
   361
      return error.response(request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   362
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   363
    content = helper.lists.getListContent(request, params, self._logic, filter)
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   364
    contents = [content]
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   365
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   366
    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
   367
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   368
  def _list(self, request, params, contents, page_name):
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   369
    """Returns the list page for the specified contents
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
    Args:
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   372
      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
   373
      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
   374
      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
   375
      page_name: the page name displayed in templates as page and header title
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   376
    """
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   377
555
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   378
    context = helper.responses.getUniversalContext(request)
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   379
    context['page_name'] = page_name
3cdfb42d941b Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   380
    context['list'] = soc.logic.lists.Lists(contents)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   381
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   382
    context['entity_type'] = params['name']
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   383
    context['entity_type_plural'] = params['name_plural']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   384
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   385
    template = params['list_template']
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   386
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   387
    return helper.responses.respond(request, template, context)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   388
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   389
  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
   390
    """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
   391
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   392
    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
   393
      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
   394
      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
   395
      params: a dict with params for this View
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   396
      kwargs: The Key Fields for the specified entity
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   397
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   398
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   399
    params = dicts.merge(params, self._params)
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   400
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   401
    try:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   402
      self.checkAccess('delete', request)
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   403
    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
   404
      return error.response(request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   405
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   406
    # create default template context for use with any templates
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   407
    context = helper.responses.getUniversalContext(request)
482
839740b061ad Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 471
diff changeset
   408
    context['page_name'] = page_name
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   409
    entity = None
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   410
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   411
    try:
438
af082c92ddda Quick fix to fix user profile creation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 435
diff changeset
   412
      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
   413
      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
   414
    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
   415
      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
   416
        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
   417
          'entity_type_lower' : params['name'].lower(),
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   418
          '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
   419
          'create' : params['missing_redirect']})
573
1b37588c4922 Moved the custom error.html page for Site to it's proper place
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
   420
      return error.response(request, template=params['error_edit'],
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
   421
                            context=context)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   422
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   423
    if not entity:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   424
      #TODO: Create a proper error page for this
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   425
      return http.HttpResponseRedirect('/')
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   426
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   427
    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
   428
      # 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
   429
      # can't delete the entity
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   430
      pass
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   431
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   432
    self._logic.delete(entity)
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   433
    redirect = params['delete_redirect']
363
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
    return http.HttpResponseRedirect(redirect)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   436
560
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   437
  def getEditRedirect(self, entity, _):
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   438
    """Returns the edit redirect for the specified entity
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   439
    """
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   440
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   441
    suffix = self._logic.getKeySuffix(entity)
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   442
    url_name = self._params['url_name']
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   443
    return '/%s/edit/%s' % (url_name, suffix)
a32be584ee04 Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents: 555
diff changeset
   444
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   445
  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
   446
    """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
   447
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   448
    Args:
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   449
      request: the django request object
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
   450
      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
   451
      fields: the new field values
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   452
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   453
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   454
    pass
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   455
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   456
  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
   457
    """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
   458
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   459
    Args:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   460
      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
   461
      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
   462
      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
   463
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   464
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   465
    pass
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   466
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   467
  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
   468
    """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
   469
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   470
    Args:
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   471
      request: the django request object
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   472
      entity: the entity to get
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   473
      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
   474
    """
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   475
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   476
    pass
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   477
497
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   478
  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
   479
    """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
   480
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   481
    Args:
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   482
      request: the django request object
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   483
      seed: the fields to seed the create page with
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   484
    """
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   485
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   486
    pass
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   487
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   488
  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
   489
    """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
   490
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   491
    Args:
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   492
      request: the django request object
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   493
      entity: the entity that is used
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   494
      context: the context to be used
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   495
      form: the form that will be used
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
   496
      params: a dict with params for this View
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   497
    """
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   498
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
   499
    suffix = self._logic.getKeySuffix(entity)
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   500
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   501
    context['form'] = form
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   502
    context['entity'] = entity
403
d3e545a8bd26 Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   503
    context['entity_suffix'] = suffix
455
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   504
    context['entity_type'] = params['name']
4d98832b43ba Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   505
    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
   506
    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
   507
    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
   508
576
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   509
    if entity:
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   510
      template = params['edit_template']
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   511
    else:
6614d3f545b7 Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 573
diff changeset
   512
      template = params['create_template']
399
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   513
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   514
    return helper.responses.respond(request, template, context)
b82852e6963e Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents: 389
diff changeset
   515
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   516
  def checkAccess(self, access_type, request, rights=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   517
    """Runs all the defined checks for the specified type
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   518
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   519
    Args:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   520
      access_type: the type of request (such as 'list' or 'edit')
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   521
      request: the Django request object
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   522
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   523
    Returns:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   524
      True: If all the required access checks have been made successfully
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   525
      False: If a check failed, in this case self._response will contain
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   526
             the response provided by the failed access check.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   527
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   528
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   529
    rights = dicts.merge(rights, self._params['rights'])
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   530
418
e035f31d131e Always check if a user filled in a user profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 410
diff changeset
   531
    # Call each access checker
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   532
    for check in rights['any_access']:
418
e035f31d131e Always check if a user filled in a user profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 410
diff changeset
   533
      check(request)
e035f31d131e Always check if a user filled in a user profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 410
diff changeset
   534
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   535
    if access_type not in rights:
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   536
      for check in rights['unspecified']:
528
5e6ae12cc495 Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 518
diff changeset
   537
        # No checks defined, so do the 'generic check' and bail out
554
68c7a1dd3c52 Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents: 553
diff changeset
   538
        check(request)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   539
      return
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   540
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   541
    for check in rights[access_type]:
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   542
      check(request)
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   543
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   544
  def collectCleanedFields(self, 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
   545
    """Collects all cleaned fields and returns them with the key_name.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   546
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   547
    Args:
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   548
      form: The form from which the cleaned fields should be collected
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   549
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   550
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   551
    fields = {}
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   552
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   553
    key_name = None
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   554
    if 'key_name' in form.cleaned_data:
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   555
      key_name = form.cleaned_data.pop('key_name')
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   556
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   557
    for field, value in form.cleaned_data.iteritems():
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   558
      fields[field] = value
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   559
459
2cfcedaf7c16 Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 458
diff changeset
   560
    return key_name, fields
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   561
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   562
  def getKeyFieldsPattern(self, params):
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   563
    """
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   564
    """
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   565
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   566
    names = self._logic.getKeyFieldNames()
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   567
    patterns = params['key_fields_prefix']
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   568
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   569
    for name in names:
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
   570
      pattern = r'(?P<%s>%s)' % (name, linkable.LINK_ID_PATTERN_CORE)
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   571
      patterns.append(pattern)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   572
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   573
    result = '/'.join(patterns)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   574
    return result
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   575
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   576
  def _getSidebarItems(self, 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
   577
    """Retrieves a list of sidebar entries for this view from self._params.
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   578
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   579
    If params['sidebar'] is None default entries will be constructed 
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   580
    """
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   581
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   582
    # Return the found result
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   583
    if params['sidebar']:
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   584
      return params['sidebar']
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   585
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   586
    # Construct defaults manualy
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   587
    defaults = params['sidebar_defaults']
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
    result = []
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   590
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   591
    for url, menu_text, access_type in defaults:
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
   592
      url = url % params['url_name'].lower()
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   593
      item = (url, menu_text % params, access_type)
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   594
      result.append(item)
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   595
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   596
    for item in params['sidebar_additional']:
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   597
      result.append(item)
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   598
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   599
    return result
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   600
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   601
  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
   602
    """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
   603
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   604
    Args:
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   605
      params: see __init__
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   606
    """
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   607
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   608
    params = dicts.merge(params, self._params)
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   609
    rights = params['rights']
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   610
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   611
    items = []
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   612
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   613
    for url, menu_text, access_type in self._getSidebarItems(params):
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   614
      try:
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   615
        self.checkAccess(access_type, request, rights)
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   616
        items.append({'url': url, 'title': menu_text})
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   617
      except out_of_band.Error:
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   618
        pass
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   619
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   620
    if not items:
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   621
      return
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   622
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   623
    res = {}
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   624
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 576
diff changeset
   625
    if 'sidebar_heading' not in params:
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   626
      params['sidebar_heading'] = params['name']
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   627
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   628
    res['heading'] = params['sidebar_heading']
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   629
    res['items'] = items
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   630
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
   631
    return res
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   632
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   633
  def getDjangoURLPatterns(self, 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
   634
    """Retrieves a list of sidebar entries for this view from self._params.
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   635
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   636
    If self._params['django_patterns'] is None default entries will be
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   637
    constructed.
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   638
    """
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   639
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   640
    params = dicts.merge(params, self._params)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   641
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   642
    # Return the found result
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   643
    if params['django_patterns']:
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   644
      return params['django_patterns']
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   645
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   646
    # Construct defaults manualy
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   647
    default_patterns = params['django_patterns_defaults']
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   648
    key_fields_pattern = self.getKeyFieldsPattern(params)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   649
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   650
    patterns = []
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   651
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   652
    for url, module, name in default_patterns:
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 539
diff changeset
   653
      name = name % params
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
   654
      module = module % params['module_name']
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   655
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   656
      url = url % {
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
   657
          'url_name': params['url_name'],
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
   658
          'lnp': linkable.LINK_ID_ARG_PATTERN,
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 528
diff changeset
   659
          'ulnp': linkable.LINK_ID_PATTERN_CORE,
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   660
          'key_fields': key_fields_pattern,
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   661
          }
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   662
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   663
      kwargs = {'page_name': name}
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   664
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   665
      item = (url, module, kwargs, name)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   666
      patterns.append(item)
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   667
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
   668
    return patterns