Beispiel #1
0
def autodiscover(filename='crumbs'):
    """
    Automatic discovering for available crumbs definitions

    Before looking at crumbs files, registry start from
    ``settings.AUTOBREADCRUMBS_TITLES`` items if setted, else an empty Dict.

    Then it try to load possible root crumb file defined in
    ``settings.AUTOBREADCRUMBS_ROOT_CRUMB`` (as a Python path). And finally
    load each crumbs file finded in ``settings.INSTALLED_APPS``.

    Keyword Arguments:
        filename (string): Module filename to search for. Default to
            ``crumbs``, so it will search for a ``crumbs.py`` file at root of
            every enabled module from ``settings.INSTALLED_APPS``.

    Returns:
        list: List of successfully loaded Python paths.
    """
    paths = []

    # Directly fill registry from initial crumbs setting
    breadcrumbs_registry.update(getattr(settings, 'AUTOBREADCRUMBS_TITLES',
                                        {}))

    # Fill paths to discover from project level crumb file
    root_crumbs = getattr(settings, 'AUTOBREADCRUMBS_ROOT_CRUMB', None)
    if root_crumbs:
        paths.append(discover(root_crumbs))

    # Fill paths to discover from installed apps
    apps = list(settings.INSTALLED_APPS)

    paths = paths + [discover(app, filename=filename) for app in apps]

    return filter(None, paths)
Beispiel #2
0
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy


breadcrumbs_registry.update({
    'bar': 'Bar',
    'bar-ometer': "O'meter",
})
Beispiel #3
0
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy


breadcrumbs_registry.update({
    'foo:index': 'Foo',
    'foo:date': 'Year month',
    'foo:pika': 'Pika',
    'foo:pika-chu': ugettext_lazy('Chu'),
    'foo:subfoo:index': ugettext_lazy('Sub'),
    'foo:subfoo:plop': ugettext_lazy('Plop'),
    'foo:slug': ugettext_lazy('Sluggy'),
    'foo:invisible-chu': 'Chu',
    'foo:controlled-true': (ugettext_lazy('Controlled true'), lambda x,y: True),
    'foo:controlled-true-endpoint': 'Control Yep',
    'foo:controlled-false': (ugettext_lazy('Controlled false'), lambda x,y: False),
    'foo:controlled-false-endpoint': 'Control Nope',
})
Beispiel #4
0
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy

breadcrumbs_registry.update({
    'foo:index':
    'Foo',
    'foo:date':
    'Year month',
    'foo:pika':
    'Pika',
    'foo:pika-chu':
    ugettext_lazy('Chu'),
    'foo:subfoo:index':
    ugettext_lazy('Sub'),
    'foo:subfoo:plop':
    ugettext_lazy('Plop'),
    'foo:slug':
    ugettext_lazy('Sluggy'),
    'foo:invisible-chu':
    'Chu',
    'foo:controlled-true':
    (ugettext_lazy('Controlled true'), lambda x, y: True),
    'foo:controlled-true-endpoint':
    'Control Yep',
    'foo:controlled-false':
    (ugettext_lazy('Controlled false'), lambda x, y: False),
    'foo:controlled-false-endpoint':
    'Control Nope',
})
Beispiel #5
0
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy

breadcrumbs_registry.update({
    'bar': 'Bar',
    'bar-ometer': "O'meter",
})
Beispiel #6
0
# -*- coding: utf-8 -*-
"""
Application Crumbs
"""
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy

breadcrumbs_registry.update({
    'datebook:index': ugettext_lazy('Datebooks'),
    'datebook:create': ugettext_lazy('Create a datebook'),
    'datebook:author-detail': '{{ author.username }}',
    'datebook:year-detail': '{{ year }}',
    'datebook:month-detail': '{{ target_date|date:"F Y" }}',
    'datebook:month-notes': ugettext_lazy('Notes for {{ target_date|date:"F Y" }}'),
    'datebook:day-add': ugettext_lazy('Add {{ target_date|date:"l d F Y" }}'),
    'datebook:day-edit': ugettext_lazy('Edit {{ target_date|date:"l d F Y" }}'),
    'datebook:day-remove': ugettext_lazy('Remove {{ target_date|date:"l d F Y" }}'),
    'datebook:day-models': ugettext_lazy('Day models'),
    'datebook:day-model-edit': ugettext_lazy('Edit "{{ daymodel.title }}"'),
    'datebook:dayentry-to-daymodel': ugettext_lazy('Make a model from {{ target_date|date:"l d F Y" }}'),
})
Beispiel #7
0
def repository_patterns(app_name,
                        fedora_prefix='',
                        custom_patterns=None,
                        custom_extended_search_params=None,
                        breadcrumbs_app_name=None,
                        via_indexer=True):
    """
    Returns a generic set of url patterns for a repository collection

    :param app_name:        if not None, install the url patterns into the application namespace
    :param fedora_prefix:   prefix inside the fedora repository in case only a part of repository is handled by the patterns
    :param custom_patterns: array of url patterns that should be included at the end of the patterns
    :param custom_extended_search_params: a dictionary that can have the following keys:

    dict(
        facets=(),
        orderings=(
                 ('title@lang', _('Sort by title (asc)')),
                 ('-title@lang', _('Sort by title (desc)')),
        ),
        title='Documents'
    )

    :param breadcrumbs_app_name: in case the patterns are embedded into an existing application, do not set app_name
                                 but set this argument to application's appname to get correct breadcrumbs
    :param via_indexer:          can be either a boolean or a callable accepting a request. If true, use indexer
                                 (elasticsearch) to access the object. If false, use fedora to get the object.
    :return:                     an array of patterns to be included to url patterns
    """
    extended_search_params = dict(facets=(),
                                  orderings=(
                                      ('title@lang', _('Sort by title (asc)')),
                                      ('-title@lang',
                                       _('Sort by title (desc)')),
                                  ),
                                  title='Documents',
                                  create_button_title='Create a New Document',
                                  fedora_prefix=fedora_prefix)

    if custom_extended_search_params:
        for k, v in custom_extended_search_params.items():
            extended_search_params[k] = v

    urlpatterns = [
        url('^$',
            fedoralink_ui.views.GenericDetailView.as_view(
                fedora_prefix=fedora_prefix, always_use_indexer=via_indexer),
            name="index"),
        url(r'^((?P<collection_id>.*)/)?search(?P<parameters>.*)$',
            fedoralink_ui.views.GenericSearchView.as_view(
                **extended_search_params),
            name='extended_search'),
        url('^(?P<id>.*)/addSubcollection$',
            (fedoralink_ui.views.GenericSubcollectionCreateView.as_view(
                fedora_prefix=fedora_prefix,
                success_url="oarepo:detail",
                parent_collection=lambda x: FedoraObject.objects.get(
                    pk=fedora_prefix),
                success_url_param_names=('id', ))),
            name='addSubcollection'),
        url('^(?P<id>.*)/add$', (fedoralink_ui.views.GenericCreateView.as_view(
            fedora_prefix=fedora_prefix,
            success_url="oarepo:detail",
            parent_collection=lambda x: FedoraObject.objects.get(
                pk=fedora_prefix),
            success_url_param_names=('id', ))),
            name='add'),
        url('^(?P<id>.*)/edit$', (fedoralink_ui.views.GenericEditView.as_view(
            success_url="oarepo:detail", fedora_prefix=fedora_prefix)),
            name="edit"),
        url('^(?P<id>.*)$',
            fedoralink_ui.views.GenericDetailView.as_view(
                fedora_prefix=fedora_prefix, always_use_indexer=via_indexer),
            name="detail"),
    ]

    if custom_patterns:
        urlpatterns.append(custom_patterns)

    if getattr(settings, 'USE_BREADCRUMBS'):
        from autobreadcrumbs.registry import breadcrumbs_registry
        from fedoralink_ui.templatetags.fedoralink_tags import rdf2lang
        import django.utils.translation
        from django.core.cache import cache

        def breadcrumb_detail(request, crumb):
            # print(request, crumb.path, crumb.name, crumb.title, crumb.view_args, crumb.view_kwargs)
            id = crumb.view_kwargs['id']
            lang = django.utils.translation.get_language()
            return get_title(id, lang)

        def get_title(id, lang):
            if id.endswith('/'):
                id = id[:-1]

            def _get_title():
                try:
                    idd = id
                    if fedora_prefix:
                        idd = fedora_prefix + '/' + idd
                    return rdf2lang(FedoraObject.objects.get(pk=idd).title,
                                    lang=lang)
                except:
                    import traceback
                    traceback.print_exc()
                    return None

            return cache.get_or_set(
                'title__%s__%s' % (fedora_prefix + '/' + id, lang), _get_title,
                3600)

        breadcrumbs_registry.update({
            '%s:detail' % (breadcrumbs_app_name if breadcrumbs_app_name else app_name):
            breadcrumb_detail,
        })

    if app_name:
        return [
            url(r'^',
                include(urlpatterns, namespace=app_name, app_name=app_name))
        ]
    else:
        return urlpatterns
Beispiel #8
0
"""
This file contain a syntax error for some test purpose.

Don't correct it.
"""
from autobreadcrumbs.registry import breadcrumbs_registry
from django.utils.translation import ugettext_lazy

breadcrumbs_registry.update({