app/soc/views/models/base.py
changeset 502 e1e24c0a4e82
parent 500 44ea4620c5c0
child 507 3603fdafabf7
equal deleted inserted replaced
501:be89bf307478 502:e1e24c0a4e82
    52 
    52 
    53   DEF_SUBMIT_MSG_PARAM_NAME = 's'
    53   DEF_SUBMIT_MSG_PARAM_NAME = 's'
    54   DEF_SUBMIT_MSG_PROFILE_SAVED = 0
    54   DEF_SUBMIT_MSG_PROFILE_SAVED = 0
    55 
    55 
    56   DEF_CREATE_NEW_ENTITY_MSG = ugettext_lazy(
    56   DEF_CREATE_NEW_ENTITY_MSG = ugettext_lazy(
    57       ' You can create a new %(entity_type_lower)s by visiting'
    57       ' You can create a new %(entity_type)s by visiting'
    58       ' <a href="%(create)s">Create '
    58       ' <a href="%(create)s">Create '
    59       'a New %(entity_type)s</a> page.')
    59       'a New %(entity_type)s</a> page.')
    60 
    60 
    61   def __init__(self, params=None, rights=None):
    61   def __init__(self, params=None, rights=None):
    62     """
    62     """
    67       params: This dictionary should be filled with the parameters
    67       params: This dictionary should be filled with the parameters
    68         specific to this entity, required fields are:
    68         specific to this entity, required fields are:
    69         name: the name of the entity (names should have sentence-style caps) 
    69         name: the name of the entity (names should have sentence-style caps) 
    70         name_short: the short form name of the name ('org' vs 'organization')
    70         name_short: the short form name of the name ('org' vs 'organization')
    71         name_plural: the plural form of the name
    71         name_plural: the plural form of the name
       
    72         url_name: the name of the entity used in urls
    72         edit_form: the class of the Django form to be used when editing
    73         edit_form: the class of the Django form to be used when editing
    73         create_form: the class of the Django form to be used when creating
    74         create_form: the class of the Django form to be used when creating
    74         edit_template: the Django template to be used for editing
    75         edit_template: the Django template to be used for editing
    75         public_template: the Django template to be used as public page 
    76         public_template: the Django template to be used as public page 
    76         list_template: the Django template to be used as list page
    77         list_template: the Django template to be used as list page
    85 
    86 
    86     new_rights = {}
    87     new_rights = {}
    87     new_rights['any_access'] = [access.checkIsUser]
    88     new_rights['any_access'] = [access.checkIsUser]
    88 
    89 
    89     new_params = {}
    90     new_params = {}
    90     new_params['create_redirect'] = '/%s' % params['name_short'].lower()
    91     new_params['create_redirect'] = '/%s' % params['url_name']
    91     new_params['missing_redirect'] = '/%s/create' % params['name_short'].lower()
    92     new_params['missing_redirect'] = '/%s/create' % params['url_name']
    92 
    93     
    93     new_params['sidebar'] = None
    94     new_params['sidebar'] = None
    94     new_params['sidebar_defaults'] = [
    95     new_params['sidebar_defaults'] = [
    95      ('/%s/create', 'New %(name)s'),
    96      ('/%s/create', 'New %(name)s'),
    96      ('/%s/list', 'List %(plural)s'),
    97      ('/%s/list', 'List %(plural)s'),
    97     ]
    98     ]
    99 
   100 
   100     new_params['key_fields_prefix'] = []
   101     new_params['key_fields_prefix'] = []
   101 
   102 
   102     new_params['django_patterns'] = None
   103     new_params['django_patterns'] = None
   103     new_params['django_patterns_defaults'] = [
   104     new_params['django_patterns_defaults'] = [
   104         (r'^%(name_lower)s/show/%(key_fields)s$', 
   105         (r'^%(url_name)s/show/%(key_fields)s$', 
   105             'soc.views.models.%s.public', 'Show %(name)s'),
   106             'soc.views.models.%s.public', 'Show %(name)s'),
   106         (r'^%(name_lower)s/create$',
   107         (r'^%(url_name)s/create$',
   107             'soc.views.models.%s.create', 'Create %(name)s'),
   108             'soc.views.models.%s.create', 'Create %(name)s'),
   108         (r'^%(name_lower)s/create/%(key_fields)s$',
   109         (r'^%(url_name)s/create/%(key_fields)s$',
   109             'soc.views.models.%s.create', 'Create %(name)s'),
   110             'soc.views.models.%s.create', 'Create %(name)s'),
   110         (r'^%(name_lower)s/delete/%(key_fields)s$',
   111         (r'^%(url_name)s/delete/%(key_fields)s$',
   111             'soc.views.models.%s.delete', 'Delete %(name)s'),
   112             'soc.views.models.%s.delete', 'Delete %(name)s'),
   112         (r'^%(name_lower)s/edit/%(key_fields)s$',
   113         (r'^%(url_name)s/edit/%(key_fields)s$',
   113             'soc.views.models.%s.edit', 'Edit %(name)s'),
   114             'soc.views.models.%s.edit', 'Edit %(name)s'),
   114         (r'^%(name_lower)s/list$',
   115         (r'^%(url_name)s/list$',
   115             'soc.views.models.%s.list', 'List %(name_plural)s'),
   116             'soc.views.models.%s.list', 'List %(name_plural)s'),
   116         ]
   117         ]
   117 
   118 
   118     new_params['list_redirect_action'] = params['name_short'] + '/edit'
   119     new_params['list_redirect_action'] = '/' + params['url_name'] + '/edit'
   119 
   120 
   120     self._rights = dicts.merge(rights, new_rights)
   121     self._rights = dicts.merge(rights, new_rights)
   121     self._params = dicts.merge(params, new_params)
   122     self._params = dicts.merge(params, new_params)
   122 
   123 
   123   def public(self, request, page_name=None, params=None, **kwargs):
   124   def public(self, request, page_name=None, params=None, **kwargs):
   461     context['entity'] = entity
   462     context['entity'] = entity
   462     context['entity_suffix'] = suffix
   463     context['entity_suffix'] = suffix
   463     context['entity_type'] = params['name']
   464     context['entity_type'] = params['name']
   464     context['entity_type_plural'] = params['name_plural']
   465     context['entity_type_plural'] = params['name_plural']
   465     context['entity_type_short'] = params['name_short']
   466     context['entity_type_short'] = params['name_short']
       
   467     context['entity_type_url'] = params['url_name']
   466 
   468 
   467     template = params['edit_template']
   469     template = params['edit_template']
   468 
   470 
   469     return helper.responses.respond(request, template, context)
   471     return helper.responses.respond(request, template, context)
   470 
   472 
   539     defaults = params['sidebar_defaults']
   541     defaults = params['sidebar_defaults']
   540 
   542 
   541     result = []
   543     result = []
   542 
   544 
   543     for url, title in defaults:
   545     for url, title in defaults:
   544       url = url % params['name_short'].lower()
   546       url = url % params['url_name'].lower()
   545 
   547 
   546       title = title % {
   548       title = title % {
   547           'name': params['name'],
   549           'name': params['name'],
   548           'plural': params['name_plural']
   550           'plural': params['name_plural']
   549           }
   551           }
   593     key_fields_pattern = self.getKeyFieldsPattern(params)
   595     key_fields_pattern = self.getKeyFieldsPattern(params)
   594 
   596 
   595     patterns = []
   597     patterns = []
   596 
   598 
   597     for url, module, name in default_patterns:
   599     for url, module, name in default_patterns:
   598       name_short_lower = params['name_short'].lower()
   600       name_short = params['name_short']
   599       name_plural_lower = params['name_plural'].lower() 
   601       name_plural = params['name_plural']
   600 
   602 
   601       name = name % {
   603       name = name % {
   602           'name': name_short_lower, 
   604           'name': name_short, 
   603           'name_plural': name_plural_lower,
   605           'name_plural': name_plural,
   604           }
   606           }
   605 
   607 
   606       module = module % name_short_lower
   608       module = module % params['module_name']
   607 
   609 
   608       url = url % {
   610       url = url % {
   609           'name_lower': name_short_lower,
   611           'url_name': params['url_name'],
   610           'lnp': path_link_name.LINKNAME_ARG_PATTERN,
   612           'lnp': path_link_name.LINKNAME_ARG_PATTERN,
   611           'ulnp': path_link_name.LINKNAME_PATTERN_CORE,
   613           'ulnp': path_link_name.LINKNAME_PATTERN_CORE,
   612           'key_fields': key_fields_pattern,
   614           'key_fields': key_fields_pattern,
   613           }
   615           }
   614 
   616