From: Thomas Fillon Date: Mon, 7 Sep 2015 17:19:55 +0000 (+0200) Subject: Update template and add records template tags X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=fdfe66bb017723c33bab993410519d0271a43bad;p=diggersdigest.git Update template and add records template tags --- diff --git a/diggersdigest/records/management/commands/populate_db.py b/diggersdigest/records/management/commands/populate_db.py index 613b619..77830ef 100644 --- a/diggersdigest/records/management/commands/populate_db.py +++ b/diggersdigest/records/management/commands/populate_db.py @@ -221,6 +221,7 @@ class Command(BaseCommand): def populate_category(self): # shop_cat, created = Category.objects.get_or_create(title="Shop") + theme_list = [theme for theme in rec_models.Theme.objects.all() if theme.published==1] count = 0 diff --git a/diggersdigest/records/templatetags/__init__.py b/diggersdigest/records/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/diggersdigest/records/templatetags/records_tags.py b/diggersdigest/records/templatetags/records_tags.py new file mode 100644 index 0000000..34480d5 --- /dev/null +++ b/diggersdigest/records/templatetags/records_tags.py @@ -0,0 +1,28 @@ +from mezzanine import template +from cartridge.shop.models import Product, Category + +register = template.Library() + + +@register.as_tag +def shop_recent_products(limit=5, category=None): + """ + Put a list of recently published products into the template + context. A tag title or slug, category title or slug or author's + username can also be specified to filter the recent posts returned. + Usage:: + {% blog_recent_posts 5 as recent_posts %} + {% blog_recent_posts limit=5 tag="django" as recent_posts %} + {% blog_recent_posts limit=5 category="python" as recent_posts %} + """ + products = Product.objects.published() + title_or_slug = lambda s: Q(title=s) | Q(slug=s) + + if category is not None: + try: + category = Category.objects.get(title_or_slug(category)) + products = products.filter(categories=category) + except Category.DoesNotExist: + return [] + + return list(products[:limit]) diff --git a/diggersdigest/templates/index.html b/diggersdigest/templates/index.html index 338b9ad..461baf1 100644 --- a/diggersdigest/templates/index.html +++ b/diggersdigest/templates/index.html @@ -25,12 +25,31 @@
  • Deploying to a production server
  • {% endblocktrans %} -
    +{% load blog_tags records_tags keyword_tags i18n mezzanine_tags %} +
    +

    {% trans "Showcase" %}

    -
    +
    +{% shop_recent_products 9 as recent_products %} +{% if recent_products %} +

    {% trans "Latest Releases" %}

    +{% for product in recent_products %} + +{% endfor %} +{% endif %}
    -{% load blog_tags keyword_tags i18n mezzanine_tags %} {% blog_recent_posts 5 as recent_posts %} {% if recent_posts %}

    {% trans "Recent Posts" %}

    @@ -54,7 +73,7 @@ {% if recent_post.categories %} {{ recent_post.categories. }} {% endif %} - +
    {% endfor %} {% endif %}