from django import template

from base.models import BannerSnippet

register = template.Library()


@register.simple_tag
def get_banners(key=None, first=False):
    banners = BannerSnippet.objects.filter(is_active=True, image__isnull=False)
    if key:
        banners = banners.filter(key=key)
    if first:
        return banners.first()
    return banners
