diff -r 3cca81b1e5a1 -r 4880ffa9f3ba app/soc/views/sitemap/sitemap.py --- a/app/soc/views/sitemap/sitemap.py Sat Nov 29 19:00:03 2008 +0000 +++ b/app/soc/views/sitemap/sitemap.py Sat Nov 29 19:44:48 2008 +0000 @@ -28,3 +28,54 @@ def addPages(pages): global SITEMAP SITEMAP += pages + + +def getDjangoURLPatterns(params): + """Retrieves a list of sidebar entries for this view from self._params. + + Params usage: + The params dictionary is passed to the getKeyFieldsPatterns + method, see it's docstring on how it is used. + django_patterns: The django_patterns value is returned directly + if it is non-False. + django_patterns_defaults: The dajngo_patterns_defaults value is + used to construct the url patterns. It is expected to be a + list of tuples. The tuples should contain an url, a module + name, and the name of the url. The name is used as the + page_name passed as keyword argument, but also as the name + by which the url is known to Django internally. + url_name: The url_name argument is passed as argument to each + url, together with the link_id pattern, the link_id core + pattern, and the key fields for this View. + + Args: + params: a dict with params for this View + """ + + # Return the found result + if params['django_patterns']: + return params['django_patterns'] + + # Construct defaults manualy + default_patterns = params['django_patterns_defaults'] + key_fields_pattern = params['key_fields_pattern'] + + patterns = [] + + for url, module, name in default_patterns: + name = name % params + module = module % params['module_name'] + + url = url % { + 'url_name': params['url_name'], + 'lnp': params['link_id_arg_pattern'], + 'ulnp': params['link_id_pattern_core'], + 'key_fields': key_fields_pattern, + } + + kwargs = {'page_name': name} + + item = (url, module, kwargs, name) + patterns.append(item) + + return patterns