@handle_page_crumb
def retrieve_breadcrumbs(path, model_instance, root_name=''):
    """
    Build a semi-hardcoded breadcrumbs
    based of the model's url handled by Zinnia.
    """
    breadcrumbs = []
    zinnia_root_path = reverse('zinnia:entry_archive_index')

    if root_name:
        breadcrumbs.append(Crumb(root_name, zinnia_root_path))

    if model_instance is not None:
        key = model_instance.__class__.__name__
        if key in MODEL_BREADCRUMBS:
            breadcrumbs.extend(MODEL_BREADCRUMBS[key](model_instance))
            return breadcrumbs

    date_match = ARCHIVE_WEEK_REGEXP.match(path)
    if date_match:
        year, week = date_match.groups()
        year_date = datetime(int(year), 1, 1)
        date_breadcrumbs = [year_crumb(year_date),
                            Crumb(_('Week %s') % week)]
        breadcrumbs.extend(date_breadcrumbs)
        return breadcrumbs

    date_match = ARCHIVE_REGEXP.match(path)
    if date_match:
        date_dict = date_match.groupdict()
        path_date = datetime(
            int(date_dict['year']),
            date_dict.get('month') is not None and
            int(date_dict.get('month')) or 1,
            date_dict.get('day') is not None and
            int(date_dict.get('day')) or 1)

        date_breadcrumbs = [year_crumb(path_date)]
        if date_dict['month']:
            date_breadcrumbs.append(month_crumb(path_date))
        if date_dict['day']:
            date_breadcrumbs.append(day_crumb(path_date))
        breadcrumbs.extend(date_breadcrumbs)
        breadcrumbs[-1].url = None
        return breadcrumbs

    url_components = [comp for comp in
                      path.replace(zinnia_root_path, '', 1).split('/')
                      if comp]
    if len(url_components):
        breadcrumbs.append(Crumb(_(url_components[-1].capitalize())))

    return breadcrumbs
dataset/ETHPy150Open Fantomas42/django-blog-zinnia/zinnia/breadcrumbs.py/retrieve_breadcrumbs/original