541 else: |
541 else: |
542 template = params['create_template'] |
542 template = params['create_template'] |
543 |
543 |
544 return helper.responses.respond(request, template, context) |
544 return helper.responses.respond(request, template, context) |
545 |
545 |
546 def _getSidebarItems(self, params): |
|
547 """Retrieves a list of sidebar entries for this view |
|
548 |
|
549 Params usage: |
|
550 The params dictionary is provided to the menu_text's format. |
|
551 |
|
552 sidebar: The sidebar value is returned directly if non-False |
|
553 sidebar_defaults: The sidebar_defaults are used to construct the |
|
554 sidebar items for this View. It is expected to be a tuple of |
|
555 three items, the item's url, it's menu_text, and it's |
|
556 access_type, see getSidebarLinks on how access_type is used. |
|
557 sidebar_additional: The sidebar_additional values are appended |
|
558 to the list of items verbatim, and should be in the format |
|
559 expected by getSidebarLinks. |
|
560 |
|
561 Args: |
|
562 params: a dict with params for this View. |
|
563 """ |
|
564 |
|
565 # Return the found result |
|
566 if params['sidebar']: |
|
567 return params['sidebar'] |
|
568 |
|
569 # Construct defaults manualy |
|
570 defaults = params['sidebar_defaults'] |
|
571 |
|
572 result = [] |
|
573 |
|
574 for url, menu_text, access_type in defaults: |
|
575 url = url % params['url_name'].lower() |
|
576 item = (url, menu_text % params, access_type) |
|
577 result.append(item) |
|
578 |
|
579 for item in params['sidebar_additional']: |
|
580 result.append(item) |
|
581 |
|
582 return result |
|
583 |
|
584 def getSidebarLinks(self, request, params=None): |
546 def getSidebarLinks(self, request, params=None): |
585 """Returns an dictionary with one sidebar entry. |
547 """Returns an dictionary with one sidebar entry. |
586 |
548 |
587 Calls _getSidebarItems to retrieve the items that should be in the |
549 Args: |
588 menu. Expected is a tuple with an url, a menu_text, and an |
550 request: the django request object |
589 access_type. The access_type is then passed to checkAccess, if it |
551 params: a dict with params for this View |
590 raises out_of_band.Error, the item will not be added. |
552 |
591 |
553 Params usage: |
592 Args: |
554 The params dictionary is passed as argument to getSidebarItems |
593 request: the django request object |
555 from the soc.views.sitemap.sidebar module, see the docstring |
594 params: a dict with params for this View |
556 of _getSidebarItems on how it uses it. |
595 |
557 """ |
596 Params usage: |
558 |
597 The params dictionary is passed as argument to _getSidebarItems, |
559 params = dicts.merge(params, self._params) |
598 see the docstring of _getSidebarItems on how it uses it. |
560 return sitemap.sidebar.getSidebarLinks(params) |
599 |
|
600 rights: The rights dictionary is used to check if the user has |
|
601 the required rights to see a sidebar item. |
|
602 See checkAccess for more details on how the rights dictionary |
|
603 is used to check access rights. |
|
604 sidebar_heading: The sidebar_heading value is used to set the |
|
605 heading variable in the result. |
|
606 name: The name value is used if sidebar_heading is not present. |
|
607 |
|
608 Returns: A dictionary is returned with it's 'heading' value set |
|
609 as explained above. It's 'items' value is constructed by |
|
610 calling _getSidebarItems. It constists of dictionaries with a |
|
611 url and a title field. |
|
612 """ |
|
613 |
|
614 params = dicts.merge(params, self._params) |
|
615 rights = params['rights'] |
|
616 |
|
617 items = [] |
|
618 |
|
619 for url, menu_text, access_type in self._getSidebarItems(params): |
|
620 try: |
|
621 access.checkAccess(access_type, request, rights) |
|
622 items.append({'url': url, 'title': menu_text}) |
|
623 except out_of_band.Error: |
|
624 pass |
|
625 |
|
626 if not items: |
|
627 return |
|
628 |
|
629 res = {} |
|
630 |
|
631 if 'sidebar_heading' not in params: |
|
632 params['sidebar_heading'] = params['name'] |
|
633 |
|
634 res['heading'] = params['sidebar_heading'] |
|
635 res['items'] = items |
|
636 |
|
637 return res |
|
638 |
561 |
639 def getDjangoURLPatterns(self, params=None): |
562 def getDjangoURLPatterns(self, params=None): |
640 """Retrieves a list of sidebar entries for this view from self._params. |
563 """Retrieves a list of sidebar entries for this view |
641 |
564 |
642 If self._params['django_patterns'] is None default entries will be |
565 Params usage: |
643 constructed. |
566 The params dictionary is passed to the getDjangoURLPatterns |
644 |
567 function in the soc.views.sitemap.sitemap module, see the |
645 Params usage: |
568 docstring of getDjangoURLPatterns on how it uses it. |
646 The params dictionary is passed to the getKeyFieldsPatterns |
|
647 method, see it's docstring on how it is used. |
|
648 django_patterns: The django_patterns value is returned directly |
|
649 if it is non-False. |
|
650 django_patterns_defaults: The dajngo_patterns_defaults value is |
|
651 used to construct the url patterns. It is expected to be a |
|
652 list of tuples. The tuples should contain an url, a module |
|
653 name, and the name of the url. The name is used as the |
|
654 page_name passed as keyword argument, but also as the name |
|
655 by which the url is known to Django internally. |
|
656 url_name: The url_name argument is passed as argument to each |
|
657 url, together with the link_id pattern, the link_id core |
|
658 pattern, and the key fields for this View. |
|
659 |
569 |
660 Args: |
570 Args: |
661 params: a dict with params for this View |
571 params: a dict with params for this View |
662 """ |
572 """ |
663 |
573 |