]> git.parisson.com Git - diggersdigest.git/commitdiff
Update template and add records template tags
authorThomas Fillon <thomas@parisson.com>
Mon, 7 Sep 2015 17:19:55 +0000 (19:19 +0200)
committerThomas Fillon <thomas@parisson.com>
Mon, 7 Sep 2015 17:19:55 +0000 (19:19 +0200)
diggersdigest/records/management/commands/populate_db.py
diggersdigest/records/templatetags/__init__.py [new file with mode: 0644]
diggersdigest/records/templatetags/records_tags.py [new file with mode: 0644]
diggersdigest/templates/index.html

index 613b619ea5806c4002d280f2e7dab550d2347139..77830efd30076c438997a77d4d8e186f82e96887 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/diggersdigest/records/templatetags/records_tags.py b/diggersdigest/records/templatetags/records_tags.py
new file mode 100644 (file)
index 0000000..34480d5
--- /dev/null
@@ -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])
index 338b9addb7204931ca2bcb73aecf06a5b391eff9..461baf19e00d7f7835978badcedd80d3792fa329 100644 (file)
     <li><a href="http://mezzanine.jupo.org/docs/deployment.html">Deploying to a production server</a></li>
 </ul>
 {% endblocktrans %}
-<div><!-- Showcase-->
+{% load blog_tags records_tags keyword_tags i18n mezzanine_tags %}
+<div class="col-xs-12 col-md-8"><!-- Showcase-->
+<h2>{% trans "Showcase" %}</h2>
 </div><!-- /Showcase -->
-<div><!-- Latest Releases -->
+<div class="col-xs-6 col-md-4"><!-- Latest Releases -->
+{% shop_recent_products 9 as recent_products %}
+{% if recent_products %}
+<h2>{% trans "Latest Releases" %}</h2>
+{% for product in recent_products %}
+    <div class="col-xs-2 col-md-4 product-thumb">
+    <a href="{{ product.get_absolute_url }}" class="thumbnail">
+        {% if product.image %}
+          <img src="{{ MEDIA_URL }}{% thumbnail product.image 148 148 %}">
+        {% else %}
+          <div class="placeholder"></div>
+        {% endif %}
+        <div class="caption">
+        <h6>{{ product }}</h6>
+        </div>
+    </a>
+    </div>
+{% endfor %}
+{% endif %}
 </div><!-- /Latest Releases -->
 <div><!-- Recent Posts -->
-{% load blog_tags keyword_tags i18n mezzanine_tags %}
 {% blog_recent_posts 5 as recent_posts %}
 {% if recent_posts %}
 <h2>{% trans "Recent Posts" %}</h2>
@@ -54,7 +73,7 @@
     {% if recent_post.categories %}
     {{ recent_post.categories. }}
     {% endif %}
-    
+
 </div><!-- /recent-summary -->
 {% endfor %}
 {% endif %}