Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated administration list for previews

  • Loading branch information...
commit f8d7fec6346d5c908bf57ed77963ebda4a5582b5 1 parent a26ff2f
Zenobius Jiricek authored
View
17 cmsplugin_configurableproduct/admin.py
@@ -1,3 +1,5 @@
+import os
+
from django.contrib import admin
from django import forms
from django.template.defaultfilters import slugify
@@ -17,8 +19,21 @@
from models import (
ProductTypeIcon,
+ STATIC_URL
)
+from pprint import pprint
+
class ProductTypeIconAdmin(admin.ModelAdmin):
- list_display = ('product_type', 'name', 'image', )
+ list_display = ('product_type', 'name', 'image_preview', )
+
+ def image_preview(self, obj):
+ return U"""
+ <span style='display:inline-block;margin:.5em;'>
+ <img src='{url}' />
+ </span>
+ <pre style='display:inline-block;'>{url}</pre>
+ """.format(url = obj.image.url)
+ image_preview.allow_tags=True
+
admin.site.register(ProductTypeIcon, ProductTypeIconAdmin)
View
21 cmsplugin_configurableproduct/models.py
@@ -15,20 +15,28 @@
DynamicChoice,
)
-STATIC_URL = getattr(settings, "STATIC_URL", '/static/')
+STATIC_URL = getattr(settings, "STATIC_URL", '/static')
+STATIC_ROOT = getattr(settings, "STATIC_ROOT", None)
+MEDIA_URL = getattr(settings, "MEDIA_URL", '/media')
+MEDIA_ROOT = getattr(settings, "MEDIA_ROOT", None)
class ApplicationSettings(AppConf):
TEMPLATE_BASE_PATH = __package__
PRODUCT_TYPE_TEMPLATE_PATH = os.path.join(TEMPLATE_BASE_PATH, "product-types")
PRODUCT_LIST_TEMPLATE_PATH = os.path.join(TEMPLATE_BASE_PATH, "product-list")
- DEFAULT_CATEGORY_IMAGE_PATH = '{0}defaults/product-category.png'.format(STATIC_URL)
- CATEGORY_IMAGE_ROOT = os.sep.join((TEMPLATE_BASE_PATH, 'product-categories'))
+ DEFAULT_CATEGORY_IMAGE_URL = '{0}/defaults/img/product-category'.format(STATIC_URL)
+ DEFAULT_CATEGORY_IMAGE_ROOT = '{0}/defaults/img/product-category'.format(STATIC_ROOT)
+ CATEGORY_IMAGE_URL = '{0}/product-category'.format(MEDIA_URL)
+ CATEGORY_IMAGE_ROOT = '{0}/product-category'.format(MEDIA_ROOT)
class ProductTypeIcon(models.Model):
- upload_path = lambda instance, filename: "/".join((
- ApplicationSettings.CATEGORY_IMAGE_ROOT, "{0}-{1}".format(
- slugify(instance.product_type), filename)))
+# upload_path = lambda instance, filename: "/product-category".join((
+# ApplicationSettings.CATEGORY_IMAGE_ROOT, "{0}-{1}".format(
+# slugify(instance.product_type), filename)))
+
+ upload_path = lambda instance, filename: "files/product-category/{0}".format(
+ "{0}-{1}".format(slugify(instance.product_type), filename) )
# fields
name = models.CharField(max_length=128, default="small")
@@ -37,6 +45,7 @@ class ProductTypeIcon(models.Model):
related_name='icons', help_text="""The product type you want this icon
related to...""")
+
class CProductTypesPlugin(CMSPlugin):
""" Stores options for cmsplugin that shows lists of ProductTypes
"""
View
3  ..._configurableproduct/templates/cmsplugin_configurableproduct/product-types/with_icon.html
@@ -3,9 +3,12 @@
<div class="product span8"
id="product-{{ Type.id }}"
data-product-type="{{ Type.name|slugify }}">
+
<img src="{% product_type_icon Type 'small' %}"/>
+
<div class="header">
<a href="#">{{ Type }}</a>
</div>
+
</div>
{% endfor %}
View
9 cmsplugin_configurableproduct/templatetags/cmsplugin_configurableproduct_tags.py
@@ -32,17 +32,10 @@ class ProductTypeIcon(Tag):
)
def render_tag(self, context, product_type, tag):
- default_image_path = os.path.join(settings.STATIC_ROOT,
- ApplicationSettings.DEFAULT_CATEGORY_IMAGE_PATH)
-
try:
icon = product_type.icons.get(name = tag)
except Exception, error:
- icon_file = open(default_image_path, 'r')
- icon = ImageFile(icon_file)
-
- except IOError, error:
icon = None
- return icon
+ return ApplicationSettings.DEFAULT_CATEGORY_IMAGE_URL
Please sign in to comment.
Something went wrong with that request. Please try again.