app/soc/views/helper/params.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 11 Aug 2009 10:22:01 -0700
changeset 2754 efbce6839e90
parent 2385 174e946039e0
child 2894 4af34d6e2a2d
permissions -rw-r--r--
Project Survey results view now doesn't list all for plain users.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 616
diff changeset
    17
"""Params related methods.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
1345
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
    25
import copy
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
    26
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 934
diff changeset
    28
from django.utils.translation import ugettext
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from soc.logic import cleaning
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
    32
from soc.models import linkable
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views import helper
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views.helper import access
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.helper import dynaform
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views.helper import redirects
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    37
from soc.views.helper import widgets
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 934
diff changeset
    40
DEF_LIST_DESCRIPTION_FMT = ugettext(
1457
9fd31955cc49 Make use of site_name where possible
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1432
diff changeset
    41
    'List of %(name_plural)s.')
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 934
diff changeset
    43
DEF_CREATE_INSTRUCTION_MSG_FMT = ugettext(
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
    44
      'Please use this form to select a %(name).')
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
    45
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
DEF_SUBMIT_MSG_PARAM_NAME = 's'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
DEF_SUBMIT_MSG_PROFILE_SAVED = 0
1594
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
    48
DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY = 1
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    51
# list with all js scripts used for documentary purposes
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    52
DEF_JS_USES_LIST = [
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    53
    'jq',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    54
    'jq_ajaqQueue',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    55
    'jq_autocomplete',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    56
    'jq_bgiframe',
1707
2e7b76f20878 Add the jquery-purr plugin
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1679
diff changeset
    57
    'jq_purr',
1727
718744a10daa Added the spin jquery plugin
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1707
diff changeset
    58
    'jq_spin',
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    59
    'jq_datetimepicker',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    60
    'jq_progressbar',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    61
    'jq_thickbox',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    62
    'jq_ui_core',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    63
    'menu',
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1480
diff changeset
    64
    'bulk_review',
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    65
    'tinymce',
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    66
    ]
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    67
1432
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    68
DEF_FIELD_INIT_PARAMS = ['required', 'widget', 'label', 'initial', 'help_text',
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    69
                         'error_messages', 'show_hidden_initial']
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    70
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
    71
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
def constructParams(params):
689
46db8c4bbffc Add missing dots in docstrings in modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 680
diff changeset
    73
  """Constructs a new params dictionary based on params.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    The params dictionary is passed to getCreateForm and getEditForm,
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 616
diff changeset
    77
    see their docstring on how they use it.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    rights: The rights value is merged with a default rights
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
      dictionary and then used as rights value.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    url_name: The url_name value is used in constructing several
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
      redirects as the first part of the url.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    module_name: The module_name value is used in constructing the
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
      location of several templates. It is expected that it matches
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
      the part after "/templates/soc/" for this View.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    name_plural: The name_plural argument is provided to the
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
      LIST_DESCRIPTION when constructing the list_description field.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
    extra_dynainclude: The extra_dynainclude value is used when
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
      constructing the create_dynainclude value.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
    extra_dynaexclude: The extra_dynaexclude value is used when
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
      constructing the create_dynaexclude value.
867
f4ea0da41915 Edited the method used to clean link_id in params.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 859
diff changeset
    92
    logic: The logic value is used as argument to save the scope_logic
f4ea0da41915 Edited the method used to clean link_id in params.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 859
diff changeset
    93
      and create a create form.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
    96
  logic = params['logic']
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
    97
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
    98
  rights = access.Checker(params)
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
  rights['unspecified'] = []
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   100
  rights['any_access'] = ['checkIsLoggedIn']
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   101
  rights['show'] = ['checkIsUser']
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   102
  rights['create'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   103
  rights['edit'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   104
  rights['delete'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   105
  rights['list'] = ['checkIsDeveloper']
1227
38afecddfbed Make picker work generically
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1101
diff changeset
   106
  rights['pick'] = ['checkIsUser'] # TODO(SRabbelier): proper check
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
  new_params = {}
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   109
  new_params['scope_logic'] = logic.getScopeLogic()
671
2c02178037ff Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   110
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   111
  if 'name_short' not in params:
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   112
    params['name_short'] = params['name']
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   113
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   114
  if 'name_plural' not in params:
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   115
    params['name_plural'] = params['name'] + 's'
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   116
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   117
  if 'module_name' not in params:
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   118
    params['module_name'] = params['name_short'].replace(' ', '_').lower()
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   119
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   120
  if 'url_name' not in params:
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   121
    params['url_name'] = params['module_name']
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 778
diff changeset
   122
1101
6c0f9b73b053 Made presence document retrievel specify prefix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1094
diff changeset
   123
  if 'document_prefix' not in params:
1295
b3b2025f4ffb Document prefix in params now defaults to url_name.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1268
diff changeset
   124
    params['document_prefix'] = params['url_name']
1101
6c0f9b73b053 Made presence document retrievel specify prefix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1094
diff changeset
   125
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1480
diff changeset
   126
  # Do not expand edit_redirect to allow it to be overwritten without suffix
735
28225172af06 Make it possible to redirect anywhere after editPost
Sverre Rabbelier <srabbelier@gmail.com>
parents: 710
diff changeset
   127
  new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s'
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
  new_params['missing_redirect'] = '/%(url_name)s/create' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
  new_params['delete_redirect'] = '/%(url_name)s/list' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
  new_params['invite_redirect'] = '/request/list'
2330
068540d91bde Now clicking cancel button returns user to previous page. Fixes issue 569.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2295
diff changeset
   131
  # new_params['cancel_redirect'] = '/%(url_name)s/list' % params
1991
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1975
diff changeset
   132
  new_params['public_redirect'] = None
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
  new_params['sidebar'] = None
1024
2a0ae6483825 Group dynamically generated menu items
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
   135
  new_params['sidebar_grouping'] = 'main'
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
  new_params['sidebar_defaults'] = [
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   137
      ('/%s/create', 'New %(name)s', 'create'),
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   138
      ('/%s/list', 'List %(name_plural)s', 'list'),
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   139
      ]
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
  new_params['sidebar_additional'] = []
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   142
  names_sans_link_id = [i for i in logic.getKeyFieldNames() if i != 'link_id']
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   143
  sans_link_id_pattern = getPattern(names_sans_link_id,
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   144
                              linkable.SCOPE_PATH_ARG_PATTERN)
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   145
616
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
   146
  new_params['link_id_arg_pattern'] = linkable.LINK_ID_ARG_PATTERN
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
   147
  new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE
680
7f047b2a2d3a Added a new create regexp in urls for just scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 679
diff changeset
   148
  new_params['scope_path_pattern'] = getScopePattern(params)
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   149
  new_params['sans_link_id_pattern'] = sans_link_id_pattern
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   151
  new_params['django_patterns'] = None
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 652
diff changeset
   152
  new_params['extra_django_patterns'] = []
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   153
  new_params['django_patterns_defaults'] = []
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   154
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   155
  # Defines the module package that the view is in. If it is not
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   156
  # already defined in the respective view, it defaults to 
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   157
  # soc.views.models
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   158
  if not params.get('module_package'):
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   159
    new_params['module_package'] = 'soc.views.models'
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   160
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   161
  if not params.get('no_edit'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   162
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   163
        (r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   164
          '%(module_package)s.%(module_name)s.edit', 'Edit %(name_short)s')]
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   165
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   166
  if not params.get('no_delete'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   167
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   168
        (r'^%(url_name)s/(?P<access_type>delete)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   169
          '%(module_package)s.%(module_name)s.delete', 'Delete %(name_short)s')]
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   170
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   171
  if not params.get('no_show'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   172
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   173
        (r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   174
          '%(module_package)s.%(module_name)s.public', 'Show %(name_short)s')]
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   175
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   176
  if not params.get('no_admin'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   177
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   178
        (r'^%(url_name)s/(?P<access_type>admin)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   179
          '%(module_package)s.%(module_name)s.admin', 
1630
850c08c90345 Fix too long lines in soc.views.helper.params module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
   180
          'Show %(name_short)s (admin)')]
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
1319
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   182
  if not params.get('no_create_raw'):
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   183
    new_params['django_patterns_defaults'] += [
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   184
        (r'^%(url_name)s/(?P<access_type>create)$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   185
          '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]
1319
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   186
1093
05ac761edb27 Made the /create/<scope> url conditional
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1092
diff changeset
   187
  if not params.get('no_create_with_scope'):
05ac761edb27 Made the /create/<scope> url conditional
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1092
diff changeset
   188
    new_params['django_patterns_defaults'] += [
05ac761edb27 Made the /create/<scope> url conditional
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1092
diff changeset
   189
        (r'^%(url_name)s/(?P<access_type>create)/%(scope)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   190
        '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]
1093
05ac761edb27 Made the /create/<scope> url conditional
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1092
diff changeset
   191
761
da4d499a9598 Allow disabling of the create url with key_fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 735
diff changeset
   192
  if not params.get('no_create_with_key_fields'):
da4d499a9598 Allow disabling of the create url with key_fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 735
diff changeset
   193
    new_params['django_patterns_defaults'] += [
da4d499a9598 Allow disabling of the create url with key_fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 735
diff changeset
   194
        (r'^%(url_name)s/(?P<access_type>create)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   195
        '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]
761
da4d499a9598 Allow disabling of the create url with key_fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 735
diff changeset
   196
1319
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   197
  if not params.get('no_list_raw'):
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   198
    new_params['django_patterns_defaults'] += [
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   199
        (r'^%(url_name)s/(?P<access_type>list)$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   200
          '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')]
1319
042347748c45 Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   201
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   202
  if params.get('pickable'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   203
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   204
        (r'^%(url_name)s/(?P<access_type>pick)$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   205
          '%(module_package)s.%(module_name)s.pick', 'Pick %(name_short)s')]
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   206
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   207
  if params.get('export_content_type'):
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   208
    new_params['django_patterns_defaults'] += [
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   209
        (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   210
          '%(module_package)s.%(module_name)s.export', 'Export %(name_short)s')]
1480
d2d9087d712f Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1458
diff changeset
   211
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   212
  if params.get('sans_link_id_create'):
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   213
    new_params['django_patterns_defaults'] += [
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   214
        (r'^%(url_name)s/(?P<access_type>create)/%(sans_link_id)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   215
         '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   216
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   217
  if params.get('sans_link_id_list'):
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   218
    new_params['django_patterns_defaults'] += [
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   219
        (r'^%(url_name)s/(?P<access_type>list)/%(sans_link_id)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   220
         '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')]
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   221
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   222
  if params.get('sans_link_id_public_list'):
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   223
    new_params['django_patterns_defaults'] += [
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   224
        (r'^%(url_name)s/(?P<access_type>list_public)/%(sans_link_id)s$',
2385
174e946039e0 Introduced 'module_package' key in params dict to support modules in melange
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2372
diff changeset
   225
         '%(module_package)s.%(module_name)s.list_public', 
1630
850c08c90345 Fix too long lines in soc.views.helper.params module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
   226
         'List %(name_plural)s')]
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   227
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   228
  new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
2372
f1cbafd21f75 Removed unecessary use of %.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2330
diff changeset
   229
  new_params['export_template'] = 'soc/export.html'
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   230
  new_params['create_template'] = 'soc/models/edit.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   231
  new_params['edit_template'] = 'soc/models/edit.html'
1343
4ba39392c854 Hook up the admin view everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1338
diff changeset
   232
  new_params['admin_template'] = 'soc/models/admin.html'
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   233
  new_params['list_template'] = 'soc/models/list.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   234
  new_params['invite_template'] = 'soc/models/invite.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   235
1677
b2cf6ad50a2a Make it possible to add some default values to the context
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1649
diff changeset
   236
  new_params['context'] = None
b2cf6ad50a2a Make it possible to add some default values to the context
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1649
diff changeset
   237
1796
5cd78a7aacdd Allow for query caching in pick
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1727
diff changeset
   238
  new_params['cache_pick'] = False
5cd78a7aacdd Allow for query caching in pick
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1727
diff changeset
   239
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   240
  new_params['export_content_type'] = None
1400
842958b8a55d Rebased my double work on top of Todd recent commit
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1357
diff changeset
   241
  new_params['export_extension'] = '.txt'
1806
d321d5123928 Added generic csv export to all list views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1805
diff changeset
   242
  new_params['csv_fieldnames'] = []
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   243
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
   244
  # TODO: Use only the js modules needed instead of js_uses_all
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
   245
  new_params['js_uses_all'] = DEF_JS_USES_LIST
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
   246
  new_params['js_uses_list'] = ['jq', 'menu']
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
   247
  new_params['js_uses_show'] = ['jq', 'menu']
2295
8566fb2b8012 Replace BeautyTips tooltips with purr info box for all form fields with help text.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1991
diff changeset
   248
  new_params['js_uses_edit'] = ['jq', 'menu', 'tinymce', 'jq_purr',
8566fb2b8012 Replace BeautyTips tooltips with purr info box for all form fields with help text.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1991
diff changeset
   249
                                'jq_spin', 'jq_autocomplete']
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1345
diff changeset
   250
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   251
  new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   252
  new_params['error_export'] = new_params['error_public']
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   253
  new_params['error_edit'] = new_params['error_public']
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   254
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   255
  new_params['list_main'] = 'soc/list/main.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   256
  new_params['list_pagination'] = 'soc/list/pagination.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   257
  new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   258
  new_params['list_heading'] = 'soc/%(module_name)s/list/heading.html' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   259
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   260
  new_params['list_action'] = (redirects.getEditRedirect, params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   261
  new_params['list_params'] = {
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   262
      'list_action': 'action',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   263
      'list_description': 'description',
1679
2b28763da7a4 Add item info to the list iterator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1677
diff changeset
   264
      'list_info': 'info',
1809
66aec0241d61 Make it possible to specify the key order for csv export
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1806
diff changeset
   265
      'list_key_order': 'key_order',
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   266
      'list_main': 'main',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   267
      'list_pagination': 'pagination',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   268
      'list_row': 'row',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   269
      'list_heading': 'heading',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   270
      }
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   271
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
   272
  new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params
1458
ec06d3ee73e4 Make it possible to display a message when there are no lists
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1457
diff changeset
   273
  new_params['no_lists_msg'] = ""
1594
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   274
  new_params['save_message'] = [ugettext('%(name)s saved.' % params),
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   275
                                ugettext('Cannot delete %(name)s.' % params)]
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   276
  new_params['submit_msg_param_name'] = DEF_SUBMIT_MSG_PARAM_NAME
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   277
  new_params['edit_params'] = {
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   278
      DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_PROFILE_SAVED,
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   279
      }
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   280
1594
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   281
  new_params['cannot_delete_params'] = {
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   282
      DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY,
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   283
      }
b80bf089d5f7 Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1535
diff changeset
   284
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   285
  new_params['dynabase'] = helper.forms.BaseForm
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   286
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   287
  create_dynaproperties = {
1079
be1aacb33b0f Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1035
diff changeset
   288
      'clean_link_id': cleaning.clean_link_id('link_id'),
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   289
      'clean_feed_url': cleaning.clean_feed_url,
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   290
      }
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   291
  create_dynaproperties.update(params.get('create_extra_dynaproperties', {}))
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   292
1432
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   293
  # dynafields override any dynaproperties
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   294
  create_dynafields = getDynaFields(params.get('create_dynafields', {}))
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   295
  create_dynaproperties = dicts.merge(create_dynafields, create_dynaproperties)
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   296
1268
9d092b702f92 Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1267
diff changeset
   297
  new_params['references'] = []
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   298
  new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', [])
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   299
  new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   300
      params.get('extra_dynaexclude', [])
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   301
  new_params['create_dynaproperties'] = create_dynaproperties
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   302
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   303
  edit_dynaproperties = {
1079
be1aacb33b0f Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1035
diff changeset
   304
      'clean_link_id': cleaning.clean_link_id('link_id'),
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   305
      'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   306
      }
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   307
  edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {}))
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   308
1432
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   309
  # dynafields override any dynaproperties
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   310
  edit_dynafields = getDynaFields(params.get('edit_dynafields', {}))
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   311
  edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties)
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   312
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   313
  new_params['edit_dynainclude'] = None
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   314
  new_params['edit_dynaexclude'] = None
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   315
  new_params['edit_dynaproperties'] = edit_dynaproperties
1975
e9bc96529849 Fix broken list_msg that caused 500 errors on many pages that contain list. Also make sure not to display list_msg if it is None.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1809
diff changeset
   316
  new_params['list_msg'] = None
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   317
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   318
  params = dicts.merge(params, new_params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   319
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   320
  # These need to be constructed separately, because they require
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   321
  # parameters that can be defined either in params, or new_params.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   322
  if not 'create_form' in params:
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   323
    params['create_form'] = getCreateForm(params, logic.getModel())
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   324
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   325
  if not 'edit_form' in params:
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   326
    params['edit_form'] = getEditForm(params, params['create_form'])
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   327
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   328
  if not 'admin_form' in params:
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   329
    params['admin_form'] = getAdminForm(params['edit_form'])
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   330
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   331
  if not 'key_fields_pattern' in params:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   332
    params['key_fields_pattern'] = getKeyFieldsPattern(params)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   333
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   334
  # merge already done by access.Checker
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   335
  params['rights'] = rights
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   336
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   337
  return params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   338
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 660
diff changeset
   339
1432
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   340
def getDynaFields(fields):
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   341
  """Constructs a new DynaField using params.
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   342
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   343
  Args:
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   344
    params: the params dictionary used to extract the dyanfields
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   345
    param_name: the name of the parameter to use
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   346
  """
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   347
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   348
  dynafields = {}
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   349
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   350
  # generate the dynafields
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   351
  for field in fields:
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   352
    base = field.pop('base')
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   353
    name = field.pop('name')
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   354
    passthrough = field.pop('passthrough', DEF_FIELD_INIT_PARAMS)
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   355
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   356
    dynafield = dynaform.newDynaField(field, base, passthrough)
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   357
    dynafields[name] = dynafield()
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   358
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   359
  return dynafields
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   360
cc58eb1136d6 Hook up dynafields in params.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   361
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   362
def getCreateForm(params, model):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 616
diff changeset
   363
  """Constructs a new CreateForm using params.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   364
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   365
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   366
    dynabase: The dynabase value is used as the base argument to
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   367
      dynaform.newDynaForm.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   368
    logic: The logic value is used to get the model argument to newDynaForm.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   369
    create_dynainclude: same as dynabase, but as dynainclude argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   370
    create_dynaexclude: same as dynabase, but as dynaexclude argument
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   371
    create_dynaproperties: same as dynabase, but as dynaproperties argument
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   372
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   373
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   374
  create_form = dynaform.newDynaForm(
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   375
    dynabase = params['dynabase'],
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   376
    dynamodel = model,
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   377
    dynainclude = params['create_dynainclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   378
    dynaexclude = params['create_dynaexclude'],
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   379
    dynaproperties = params['create_dynaproperties'],
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   380
    )
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   381
1267
157c12589f79 Make it possible to put fields at the end of the form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1227
diff changeset
   382
  if 'extra_key_order' in params:
157c12589f79 Make it possible to put fields at the end of the form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1227
diff changeset
   383
    for field in params['extra_key_order']:
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   384
      if field in create_form.base_fields.keyOrder:
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1319
diff changeset
   385
        create_form.base_fields.keyOrder.remove(field)
1267
157c12589f79 Make it possible to put fields at the end of the form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1227
diff changeset
   386
    create_form.base_fields.keyOrder.extend(params['extra_key_order'])
157c12589f79 Make it possible to put fields at the end of the form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1227
diff changeset
   387
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   388
  return create_form
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   389
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 660
diff changeset
   390
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   391
def getEditForm(params, base_form):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 616
diff changeset
   392
  """Constructs a new EditForm using params.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   393
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   394
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   395
    create_form: The dynabase value is used as the dynaform argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   396
      to dyanform.extendDynaForm.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   397
    edit_dynainclude: same as create_form, but as dynainclude argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   398
    edit_dynaexclude: same as create_form, but as dynaexclude argument
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   399
    edit_dynaproperties: same as create_form, but as dynaproperties argument
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   400
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   401
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   402
  edit_form = dynaform.extendDynaForm(
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 761
diff changeset
   403
    dynaform = base_form,
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   404
    dynainclude = params['edit_dynainclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   405
    dynaexclude = params['edit_dynaexclude'],
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1400
diff changeset
   406
    dynaproperties = params['edit_dynaproperties'],
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   407
    )
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   408
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   409
  return edit_form
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   410
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 660
diff changeset
   411
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   412
def getAdminForm(base_form):
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   413
  """Constructs a new AdminForm from base_form.
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   414
  """
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   415
1345
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   416
  # extend _and_ deepcopy the base_fields to do a proper copy
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   417
  admin_form = dynaform.extendDynaForm(dynaform = base_form)
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   418
  admin_form.base_fields = copy.deepcopy(admin_form.base_fields)
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   419
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   420
  # replace all widgets with PTW's
1649
495171ad94c0 Rename unused loop variables to _ in soc.views.helper.params module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1630
diff changeset
   421
  for _, value in admin_form.base_fields.iteritems():
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   422
    if not isinstance(value, forms.fields.Field):
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   423
      continue
1345
1c5c6271f02e Fixed a bug in admin_form generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   424
1338
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   425
    value.widget = widgets.PlainTextWidget()
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   426
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   427
  return admin_form
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   428
4b8546a3b20c Add an AdminForm that renders all fields as PTW's
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
   429
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   430
def getKeyFieldsPattern(params):
639
1f92bd41b914 Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 616
diff changeset
   431
  """Returns the Django pattern for this View's entity.
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   432
  """
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   433
673
2433d5c1d7e6 Partial revert
Sverre Rabbelier <srabbelier@gmail.com>
parents: 672
diff changeset
   434
  names = params['logic'].getKeyFieldNames()
1094
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   435
  scope_path_pattern = params['scope_path_pattern']
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   436
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   437
  return getPattern(names, scope_path_pattern)
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   438
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   439
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   440
def getPattern(names, scope_path_pattern):
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   441
  """Returns the Django patterns for the specified names.
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   442
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   443
  Args:
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   444
    names: the field names that should be included in the pattern
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   445
    scope_path_pattern: the pattern to use if the name is 'scope_path'
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   446
  """
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   447
1092
b03895bba47a Removed unused key_fields_prefix variable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1087
diff changeset
   448
  patterns = []
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   449
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   450
  for name in names:
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   451
    if name == 'scope_path':
1094
e143974a6e27 Factor out the getPattern logic from params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1093
diff changeset
   452
      pattern = scope_path_pattern
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   453
    else:
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   454
      pattern = r'(?P<%s>%s)' % (name, linkable.LINK_ID_PATTERN_CORE)
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   455
    patterns.append(pattern)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   456
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   457
  result = '/'.join(patterns)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   458
  return result
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   459
837
bc1c951bf3a0 Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
   460
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   461
def getScopePattern(params):
689
46db8c4bbffc Add missing dots in docstrings in modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 680
diff changeset
   462
  """Returns the Scope pattern for this entity.
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   463
  """
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   464
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   465
  logic = params['logic']
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   466
  depth = logic.getScopeDepth()
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   467
  if depth is None:
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   468
    return linkable.SCOPE_PATH_ARG_PATTERN
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   469
1649
495171ad94c0 Rename unused loop variables to _ in soc.views.helper.params module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1630
diff changeset
   470
  regexps = [linkable.LINK_ID_PATTERN_CORE for _ in range(depth)]
679
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   471
  regexp = '/'.join(regexps)
77a286ff6667 Introduce dynamic scope_path regexps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 673
diff changeset
   472
  return r'(?P<scope_path>%s)' % regexp