app/soc/views/helper/params.py
author Sverre Rabbelier <srabbelier@gmail.com>
Tue, 02 Dec 2008 22:04:15 +0000
changeset 652 02323664d532
parent 642 671dc971c3d1
child 660 5a381b290691
permissions -rw-r--r--
Cleanups in preparation of general selector view Renamed LIST... to DEF_LIST since it is a global definition. Renamed getCreateProgramRedirect to getCreateRedirect since it will work on all entities as it uses params. Added a getParams method to base.View Updated selectSponsor as appropriate. Patch by: Sverre Rabbelier
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
#
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
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
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from django import forms
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django.utils.translation import ugettext_lazy
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import cleaning
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
    30
from soc.models import linkable
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.views import helper
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import access
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views.helper import dynaform
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views.helper import redirects
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
    37
DEF_LIST_DESCRIPTION_FMT = ugettext_lazy(
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
    'List of %(name_plural)s in Google Open Source Programs.')
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
    40
DEF_CREATE_INSTRUCTION_MSG_FMT = ugettext_lazy(
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
    41
      '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
    42
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
DEF_SUBMIT_MSG_PARAM_NAME = 's'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
DEF_SUBMIT_MSG_PROFILE_SAVED = 0
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
def constructParams(params):
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  """Constructs a new params dictionary based on params
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
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    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
    52
    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
    53
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
    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
    55
      dictionary and then used as rights value.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
    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
    57
      redirects as the first part of the url.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
    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
    59
      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
    60
      the part after "/templates/soc/" for this View.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
    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
    62
      LIST_DESCRIPTION when constructing the list_description field.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    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
    64
      constructing the create_dynainclude value.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    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
    66
      constructing the create_dynaexclude value.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    logic: The logic value is used as argument to clean_new_link_id
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
      from the cleaning module.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
  rights = {}
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
  rights['unspecified'] = []
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
  rights['any_access'] = [access.checkIsLoggedIn]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
  rights['public'] = [access.checkIsUser]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
  rights['create'] = [access.checkIsDeveloper]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
  rights['edit'] = [access.checkIsDeveloper]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
  rights['delete'] = [access.checkIsDeveloper]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
  rights['list'] = [access.checkIsDeveloper]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
  if 'rights' in params:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    rights = dicts.merge(params['rights'], rights)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
  new_params = {}
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
  new_params['rights'] = rights
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
  new_params['create_redirect'] = '/%(url_name)s' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
  new_params['edit_redirect'] = '/%(url_name)s/edit' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
  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
    88
  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
    89
  new_params['invite_redirect'] = '/request/list'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
  new_params['sidebar'] = None
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
  new_params['sidebar_defaults'] = [
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
    93
      ('/%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
    94
      ('/%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
    95
      ]
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
  new_params['sidebar_additional'] = []
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
  new_params['key_fields_prefix'] = []
616
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 613
diff changeset
    99
  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
   100
  new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
  new_params['django_patterns'] = None
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
  new_params['django_patterns_defaults'] = [
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
      (r'^%(url_name)s/show/%(key_fields)s$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
          'soc.views.models.%s.public', 'Show %(name_short)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
      (r'^%(url_name)s/create$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
          'soc.views.models.%s.create', 'Create %(name_short)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
      (r'^%(url_name)s/create/%(key_fields)s$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
          'soc.views.models.%s.create', 'Create %(name_short)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
      (r'^%(url_name)s/delete/%(key_fields)s$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
          'soc.views.models.%s.delete', 'Delete %(name_short)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
      (r'^%(url_name)s/edit/%(key_fields)s$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
          'soc.views.models.%s.edit', 'Edit %(name_short)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
      (r'^%(url_name)s/list$',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
          'soc.views.models.%s.list', 'List %(name_plural)s'),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
      ]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
  new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
  new_params['create_template'] = 'soc/models/edit.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
  new_params['edit_template'] = 'soc/models/edit.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
  new_params['list_template'] = 'soc/models/list.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
  new_params['invite_template'] = 'soc/models/invite.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
  new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
  new_params['error_edit'] = 'soc/%(module_name)s/error.html'  % params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
  new_params['list_main'] = 'soc/list/main.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
  new_params['list_pagination'] = 'soc/list/pagination.html'
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
  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
   130
  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
   131
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
  new_params['list_action'] = (redirects.getEditRedirect, params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
  new_params['list_params'] = {
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
      'list_action': 'action',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
      'list_description': 'description',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
      'list_main': 'main',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
      'list_pagination': 'pagination',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
      'list_row': 'row',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
      'list_heading': 'heading',
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
      }
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
652
02323664d532 Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 642
diff changeset
   142
  new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
  new_params['save_message'] = [ugettext_lazy('Profile saved.')]
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
  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
   145
  new_params['edit_params'] = {
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
      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
   147
      }
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
  new_params['dynabase'] = helper.forms.BaseForm
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   151
  create_dynafields = {
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
      'clean_link_id': cleaning.clean_new_link_id(params['logic']),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   153
      'clean_feed_url': cleaning.clean_feed_url,
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
      }
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   155
  create_dynafields.update(params.get('create_extra_dynafields', {}))
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   157
  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
   158
  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
   159
      params.get('extra_dynaexclude', [])
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   160
  new_params['create_dynafields'] = create_dynafields
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   161
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   162
  edit_dynafields = {
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   163
      'clean_link_id': cleaning.clean_link_id,
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   164
      'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   165
      }
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   166
  edit_dynafields.update(params.get('edit_extra_dynafields', {}))
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   167
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   168
  new_params['edit_dynainclude'] = None
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   169
  new_params['edit_dynaexclude'] = None
642
671dc971c3d1 Allow for extra dynamic fields for the create form
Sverre Rabbelier <srabbelier@gmail.com>
parents: 639
diff changeset
   170
  new_params['edit_dynafields'] = edit_dynafields
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   171
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   172
  params = dicts.merge(params, new_params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   173
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   174
  # 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
   175
  # 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
   176
  if not 'create_form' in params:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
    params['create_form'] = getCreateForm(params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   179
  if not 'edit_form' in params:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
    params['edit_form'] = getEditForm(params)
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   182
  if not 'key_fields_pattern' in params:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   183
    params['key_fields_pattern'] = getKeyFieldsPattern(params)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   184
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
  return params
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   186
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   187
def getCreateForm(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
   188
  """Constructs a new CreateForm using params.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   189
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   190
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   191
    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
   192
      dynaform.newDynaForm.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   193
    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
   194
    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
   195
    create_dynaexclude: same as dynabase, but as dynaexclude argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   196
    create_dynafields: same as dynabase, but as dynafields argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   197
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   198
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   199
  create_form = dynaform.newDynaForm(
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   200
    dynabase = params['dynabase'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   201
    dynamodel = params['logic'].getModel(),
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   202
    dynainclude = params['create_dynainclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   203
    dynaexclude = params['create_dynaexclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   204
    dynafields = params['create_dynafields'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   205
    )
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   206
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   207
  return create_form
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   208
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   209
def getEditForm(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
   210
  """Constructs a new EditForm using params.
611
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   211
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
  Params usage:
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   213
    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
   214
      to dyanform.extendDynaForm.
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   215
    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
   216
    edit_dynaexclude: same as create_form, but as dynaexclude argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   217
    edit_dynafields: same as create_form, but as dynafields argument
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   218
  """
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   219
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   220
  edit_form = dynaform.extendDynaForm(
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   221
    dynaform = params['create_form'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   222
    dynainclude = params['edit_dynainclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   223
    dynaexclude = params['edit_dynaexclude'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   224
    dynafields = params['edit_dynafields'],
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   225
    )
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   226
2ec30182e5f1 Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   227
  return edit_form
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   228
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   229
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
   230
  """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
   231
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   232
  Params usage:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   233
    key_fields_prefix: The key_fields_prefix value is used as the
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
   234
      first part of the returned pattern.
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   235
  """
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   236
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   237
  names = params['logic'].getKeyFieldNames()
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   238
  patterns = params['key_fields_prefix']
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   239
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   240
  for name in names:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   241
    pattern = r'(?P<%s>%s)' % (name, linkable.LINK_ID_PATTERN_CORE)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   242
    patterns.append(pattern)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   243
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   244
  result = '/'.join(patterns)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 611
diff changeset
   245
  return result