Пример #1
0
def report_date_hierarchy(cl):
    if cl.date_hierarchy:
        model, field_name = get_date_model_field(cl.model, cl.date_hierarchy)
        rel_query_set = model.objects.all()

        year_field = "%s__year" % cl.date_hierarchy
        month_field = "%s__month" % cl.date_hierarchy
        day_field = "%s__day" % cl.date_hierarchy
        field_generic = "%s__" % cl.date_hierarchy
        year_lookup = cl.params.get(year_field)
        month_lookup = cl.params.get(month_field)
        day_lookup = cl.params.get(day_field)
        year_month_format, month_day_format = get_partial_date_formats()

        link = lambda d: mark_safe(cl.get_query_string(d, [field_generic]))

        if year_lookup and month_lookup and day_lookup:
            day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
            return {
                "show": True,
                "back": {
                    "link": link({year_field: year_lookup, month_field: month_lookup}),
                    "title": dateformat.format(day, year_month_format),
                },
                "choices": [{"title": dateformat.format(day, month_day_format)}],
            }
        elif year_lookup and month_lookup:
            days = rel_query_set.filter(
                **{"%s__year" % field_name: year_lookup, "%s__month" % field_name: month_lookup}
            ).dates(field_name, "day")
            return {
                "show": True,
                "back": {"link": link({year_field: year_lookup}), "title": year_lookup},
                "choices": [
                    {
                        "link": link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
                        "title": dateformat.format(day, month_day_format),
                    }
                    for day in days
                ],
            }
        elif year_lookup:
            months = rel_query_set.filter(**{"%s__year" % field_name: year_lookup}).dates(field_name, "month")
            return {
                "show": True,
                "back": {"link": link({}), "title": _("All dates")},
                "choices": [
                    {
                        "link": link({year_field: year_lookup, month_field: month.month}),
                        "title": dateformat.format(month, year_month_format),
                    }
                    for month in months
                ],
            }
        else:
            years = rel_query_set.dates(field_name, "year")
            return {
                "show": True,
                "choices": [{"link": link({year_field: year.year}), "title": year.year} for year in years],
            }
Пример #2
0
def date_hierarchy(cl):
    if cl.lookup_opts.admin.date_hierarchy:
        field_name = cl.lookup_opts.admin.date_hierarchy
        year_field = '%s__year' % field_name
        month_field = '%s__month' % field_name
        day_field = '%s__day' % field_name
        field_generic = '%s__' % field_name
        year_lookup = cl.params.get(year_field)
        month_lookup = cl.params.get(month_field)
        day_lookup = cl.params.get(day_field)
        year_month_format, month_day_format = get_partial_date_formats()

        link = lambda d: cl.get_query_string(d, [field_generic])

        if year_lookup and month_lookup and day_lookup:
            day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
            return {
                'show': True,
                'back': {
                    'link': link({year_field: year_lookup, month_field: month_lookup}),
                    'title': dateformat.format(day, year_month_format)
                },
                'choices': [{'title': dateformat.format(day, month_day_format)}]
            }
        elif year_lookup and month_lookup:
            days = cl.query_set.filter(**{year_field: year_lookup, month_field: month_lookup}).dates(field_name, 'day')
            return {
                'show': True,
                'back': {
                    'link': link({year_field: year_lookup}),
                    'title': year_lookup
                },
                'choices': [{
                    'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
                    'title': dateformat.format(day, month_day_format)
                } for day in days]
            }
        elif year_lookup:
            months = cl.query_set.filter(**{year_field: year_lookup}).dates(field_name, 'month')
            return {
                'show' : True,
                'back': {
                    'link' : link({}),
                    'title': _('All dates')
                },
                'choices': [{
                    'link': link({year_field: year_lookup, month_field: month.month}),
                    'title': dateformat.format(month, year_month_format)
                } for month in months]
            }
        else:
            years = cl.query_set.dates(field_name, 'year')
            return {
                'show': True,
                'choices': [{
                    'link': link({year_field: year.year}),
                    'title': year.year
                } for year in years]
            }
def date_hierarchy(cl):
    if cl.lookup_opts.admin.date_hierarchy:
        field_name = cl.lookup_opts.admin.date_hierarchy
        year_field = '%s__year' % field_name
        month_field = '%s__month' % field_name
        day_field = '%s__day' % field_name
        field_generic = '%s__' % field_name
        year_lookup = cl.params.get(year_field)
        month_lookup = cl.params.get(month_field)
        day_lookup = cl.params.get(day_field)
        year_month_format, month_day_format = get_partial_date_formats()

        link = lambda d: cl.get_query_string(d, [field_generic])

        if year_lookup and month_lookup and day_lookup:
            day = datetime.date(int(year_lookup), int(month_lookup),
                                int(day_lookup))
            return {
                'show': True,
                'back': {
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month_lookup
                    }),
                    'title':
                    dateformat.format(day, year_month_format)
                },
                'choices': [{
                    'title': dateformat.format(day, month_day_format)
                }]
            }
        elif year_lookup and month_lookup:
            days = cl.query_set.filter(**{
                year_field: year_lookup,
                month_field: month_lookup
            }).dates(field_name, 'day')
            return {
                'show':
                True,
                'back': {
                    'link': link({year_field: year_lookup}),
                    'title': year_lookup
                },
                'choices': [{
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month_lookup,
                        day_field: day.day
                    }),
                    'title':
                    dateformat.format(day, month_day_format)
                } for day in days]
            }
        elif year_lookup:
            months = cl.query_set.filter(**{
                year_field: year_lookup
            }).dates(field_name, 'month')
            return {
                'show':
                True,
                'back': {
                    'link': link({}),
                    'title': _('All dates')
                },
                'choices': [{
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month.month
                    }),
                    'title':
                    dateformat.format(month, year_month_format)
                } for month in months]
            }
        else:
            years = cl.query_set.dates(field_name, 'year')
            return {
                'show':
                True,
                'choices': [{
                    'link': link({year_field: year.year}),
                    'title': year.year
                } for year in years]
            }
Пример #4
0
def report_date_hierarchy(cl):
    if cl.date_hierarchy:
        model, field_name = get_date_model_field(cl.model, cl.date_hierarchy)
        rel_query_set = model.objects.all()

        year_field = '%s__year' % cl.date_hierarchy
        month_field = '%s__month' % cl.date_hierarchy
        day_field = '%s__day' % cl.date_hierarchy
        field_generic = '%s__' % cl.date_hierarchy
        year_lookup = cl.params.get(year_field)
        month_lookup = cl.params.get(month_field)
        day_lookup = cl.params.get(day_field)
        year_month_format, month_day_format = get_partial_date_formats()

        link = lambda d: mark_safe(cl.get_query_string(d, [field_generic]))

        if year_lookup and month_lookup and day_lookup:
            day = datetime.date(int(year_lookup), int(month_lookup),
                                int(day_lookup))
            return {
                'show': True,
                'back': {
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month_lookup
                    }),
                    'title':
                    dateformat.format(day, year_month_format)
                },
                'choices': [{
                    'title': dateformat.format(day, month_day_format)
                }]
            }
        elif year_lookup and month_lookup:
            days = rel_query_set.filter(
                **{
                    '%s__year' % field_name: year_lookup,
                    '%s__month' % field_name: month_lookup
                }).dates(field_name, 'day')
            return {
                'show':
                True,
                'back': {
                    'link': link({year_field: year_lookup}),
                    'title': year_lookup
                },
                'choices': [{
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month_lookup,
                        day_field: day.day
                    }),
                    'title':
                    dateformat.format(day, month_day_format)
                } for day in days]
            }
        elif year_lookup:
            months = rel_query_set.filter(**{
                '%s__year' % field_name: year_lookup
            }).dates(field_name, 'month')
            return {
                'show':
                True,
                'back': {
                    'link': link({}),
                    'title': _('All dates')
                },
                'choices': [{
                    'link':
                    link({
                        year_field: year_lookup,
                        month_field: month.month
                    }),
                    'title':
                    dateformat.format(month, year_month_format)
                } for month in months]
            }
        else:
            years = rel_query_set.dates(field_name, 'year')
            return {
                'show':
                True,
                'choices': [{
                    'link': link({year_field: year.year}),
                    'title': year.year
                } for year in years]
            }
Пример #5
0
def report_date_hierarchy(cl):
    if cl.date_hierarchy:
        model, field_name = get_date_model_field(cl.model, cl.date_hierarchy)
        rel_query_set = model.objects.all()
         
        year_field = '%s__year' % cl.date_hierarchy
        month_field = '%s__month' % cl.date_hierarchy
        day_field = '%s__day' % cl.date_hierarchy
        field_generic = '%s__' % cl.date_hierarchy
        year_lookup = cl.params.get(year_field)
        month_lookup = cl.params.get(month_field)
        day_lookup = cl.params.get(day_field)
        year_month_format, month_day_format = get_partial_date_formats()

        link = lambda d: mark_safe(cl.get_query_string(d, [field_generic]))

        if year_lookup and month_lookup and day_lookup:
            day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
            return {
                'show': True,
                'back': {
                    'link': link({year_field: year_lookup, month_field: month_lookup}),
                    'title': dateformat.format(day, year_month_format)
                },
                'choices': [{'title': dateformat.format(day, month_day_format)}]
            }
        elif year_lookup and month_lookup:
            days = rel_query_set.filter(**{'%s__year' % field_name: year_lookup, '%s__month' % field_name: month_lookup}).dates(field_name, 'day')
            return {
                'show': True,
                'back': {
                    'link': link({year_field: year_lookup}),
                    'title': year_lookup
                },
                'choices': [{
                    'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
                    'title': dateformat.format(day, month_day_format)
                } for day in days]
            }
        elif year_lookup:
            months = rel_query_set.filter(**{'%s__year' % field_name: year_lookup}).dates(field_name, 'month')
            return {
                'show' : True,
                'back': {
                    'link' : link({}),
                    'title': _('All dates')
                },
                'choices': [{
                    'link': link({year_field: year_lookup, month_field: month.month}),
                    'title': dateformat.format(month, year_month_format)
                } for month in months]
            }
        else:
            years = rel_query_set.dates(field_name, 'year')
            return {
                'show': True,
                'choices': [{
                    'link': link({year_field: year.year}),
                    'title': year.year
                } for year in years]
            }