Exemple #1
0
def get_box(context, appname, slug, template_name=None):
    """
    {% load box_tags %}
    {% get_box 'polls' 'box_slug' %}
    """
    model = get_app_model(appname, "Box")
    try:
        box = model.objects.get(site=settings.SITE_ID,
                                slug=slug,
                                date_available__lte=timezone.now(),
                                published=True)
    except model.DoesNotExist:
        box = None

    if template_name:
        t = template.loader.get_template(template_name)
    else:
        t = template.loader.get_template('{0}/{1}_detail.html'.format(
            appname, model.__name__.lower()))
    return t.render(
        template.Context({
            '{0}'.format(model.__name__.lower()): box,
            'slug': slug,
            'context': context
        }))
Exemple #2
0
def get_config(appname, key, **kwargs):
    """
    {% load config %}
    {% get_config 'polls' 'key_slug' %}
    {% get_config 'infographics' 'key_slug' %}
    {% get_config 'promos' 'key_slug' %}

    Also works
    {% get_config 'opps.polls' 'key_slug' %}
    """

    model = get_app_model(appname, "Config")
    return model and model.get_value(key, **kwargs)
Exemple #3
0
def get_all_box(appname, channel_slug, template_name=None):
    """
    {% load box_tags %}
    {% get_all_box 'polls' 'channel_slug' %}
    """
    model = get_app_model(appname, "Box")
    boxes = model.objects.filter(site=settings.SITE_ID,
                                 date_available__lte=timezone.now(),
                                 published=True,
                                 channel__slug=channel_slug)

    if template_name:
        t = template.loader.get_template(template_name)
    else:
        t = template.loader.get_template('{0}/{1}_list.html'.format(
            appname, model.__name__.lower()))

    return t.render(
        template.Context({'{0}boxes'.format(model.__name__.lower()): boxes}))
Exemple #4
0
def get_all_box(context, appname, channel_long_slug, template_name=None):
    """
    {% load box_tags %}
    {% get_all_box 'polls' 'channel_slug' %}
    """
    model = get_app_model(appname, "Box")
    boxes = model.objects.filter(site=settings.SITE_ID,
                                 date_available__lte=timezone.now(),
                                 published=True,
                                 channel_long_slug=channel_long_slug)

    if template_name:
        t = template.loader.get_template(template_name)
    else:
        t = template.loader.get_template(
            '{0}/{1}_list.html'.format(appname, model.__name__.lower())
        )

    return t.render(template.Context({'{0}boxes'.format(
        model.__name__.lower()): boxes, 'context': context}))
Exemple #5
0
def get_box(context, appname, slug, template_name=None):
    """
    {% load box_tags %}
    {% get_box 'polls' 'box_slug' %}
    """
    model = get_app_model(appname, "Box")
    try:
        box = model.objects.get(site=settings.SITE_ID, slug=slug,
                                date_available__lte=timezone.now(),
                                published=True)
    except model.DoesNotExist:
        box = None

    if template_name:
        t = template.loader.get_template(template_name)
    else:
        t = template.loader.get_template(
            '{0}/{1}_detail.html'.format(appname, model.__name__.lower())
        )
    return t.render(template.Context({'{0}'.format(
        model.__name__.lower()): box, 'slug': slug, 'context': context}))