]> git.parisson.com Git - mezzo.git/commitdiff
Add Product lists to pages, fix admin fields order against translations
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 26 Sep 2016 11:18:12 +0000 (13:18 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 26 Sep 2016 11:18:12 +0000 (13:18 +0200)
12 files changed:
app/local_settings.py
app/organization/core/admin.py
app/organization/network/admin.py
app/organization/pages/admin.py
app/organization/shop/admin.py
app/organization/shop/migrations/0004_auto_20160926_1144.py [new file with mode: 0644]
app/organization/shop/migrations/0005_auto_20160926_1230.py [new file with mode: 0644]
app/organization/shop/models.py
app/organization/shop/translation.py
app/templates/pages/custompage.html
app/templates/pages/page.html
app/templates/shop/includes/product_list_square_style.html [new file with mode: 0644]

index 8b702ed6c1fb7c60b20adf6ba6a3e31bedb0d749..ef1e640188b327f6f0473d2ade960db1e801ec58 100644 (file)
@@ -108,6 +108,12 @@ ADMIN_MENU_ORDER = (
                     'organization-projects.ProjectTopic',
                     'organization-projects.ProjectProgramType',
                     )),
+    (_('Shop'), ('shop.Product',
+                    'organization-shop.ProductList',
+                    'shop.Order',
+                    'shop.DiscountCode',
+                    'shop.Sale',
+                    )),
     (_('Jobs'), ('organization-job.JobOffer',)),
     (_('Festival'), ('organization-festival.Artist',)),
     (_('Users'), ('auth.User', 'auth.Group',)),
index 4438e24c9d1eab1840f16140240d4d547c17351b..abdeaffa073744ec6ad6dff6aa1d1633fdb9f438 100644 (file)
@@ -12,6 +12,18 @@ class KeywordAdmin(BaseTranslationModelAdmin):
     model = Keyword
 
 
+class BaseTranslationOrderedModelAdmin(BaseTranslationModelAdmin):
+
+    def get_fieldsets(self, request, obj = None):
+        res = super(BaseTranslationOrderedModelAdmin, self).get_fieldsets(request, obj)
+        for field in reversed(self.first_fields):
+            for trans_field in res[0][1]['fields']:
+                if field in trans_field:
+                    index = res[0][1]['fields'].index(trans_field)
+                    res[0][1]['fields'].insert(0, res[0][1]['fields'].pop(index))
+        return res
+
+
 admin.site.register(LinkType)
 admin.site.unregister(BlogPost)
 admin.site.unregister(ThreadedComment)
index 63fe49913331817075ab4e8c7ea5bcc126561b99..b2527e859668bca66bb81c7760c9ae59e326a104 100644 (file)
@@ -103,20 +103,13 @@ class PersonBlockInline(StackedDynamicInlineAdmin):
     model = PersonBlock
 
 
-class PersonAdmin(BaseTranslationModelAdmin):
+class PersonAdmin(BaseTranslationOrderedModelAdmin):
 
     model = Person
     inlines = [PersonActivityInline, PersonAudioInline, PersonImageInline, PersonVideoInline, PersonBlockInline, PersonLinkInline ]
     first_fields = ['last_name', 'first_name', 'title', 'gender', 'user']
     search_fields = ['last_name', 'first_name']
 
-    def get_fieldsets(self, request, obj = None):
-        res = super(PersonAdmin, self).get_fieldsets(request, obj)
-        for field in reversed(self.first_fields):
-            index = res[0][1]['fields'].index(field)
-            res[0][1]['fields'].insert(0, res[0][1]['fields'].pop(index))
-        return res
-
 
 class PersonListBlockInlineAdmin(TabularDynamicInlineAdmin):
 
index c73ef8c3c496008ebdbc91cfb3aee881d63adf70..fde7064f14d63d516bd17e2ac5694e4b255add74 100644 (file)
@@ -59,9 +59,9 @@ class PersonListBlockAutocompleteInlineAdmin(TabularDynamicInlineAdmin):
     form = PageCustomPersonListForm
 
 
-class PageProductBlockInline(TabularDynamicInlineAdmin):
+class PageProductListInline(TabularDynamicInlineAdmin):
 
-    model = PageProductBlock
+    model = PageProductList
 
 
 class CustomPageAdmin(PageAdmin):
@@ -72,7 +72,7 @@ class CustomPageAdmin(PageAdmin):
             PageVideoInline,
             PageLinkInline,
             PersonListBlockAutocompleteInlineAdmin,
-            PageProductBlockInline
+            PageProductListInline
             ]
 
 
index 27502fb0f6ad9ef7d2b6aec3a15d7b9430545b51..cc66060dd18c4584f1f25363200026cb5b012d19 100644 (file)
@@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _
 
 from mezzanine.core.admin import *
 
+from organization.core.admin import *
 from organization.projects.models import *
 from organization.pages.models import *
 from organization.media.models import Video, Audio
@@ -13,14 +14,15 @@ from organization.shop.models import *
 from cartridge.shop.admin import *
 
 
-class ProductBlockProductInline(TabularDynamicInlineAdmin):
+class ProductListProductInline(TabularDynamicInlineAdmin):
 
-    model = ProductBlockProduct
+    model = ProductListProduct
 
 
-class ProductBlockAdmin(BaseTranslationModelAdmin):
+class ProductListAdmin(BaseTranslationOrderedModelAdmin):
 
-    inlines = [ProductBlockProductInline, ]
+    inlines = [ProductListProductInline, ]
+    first_fields = ['title', 'description',]
 
 
 class ProductLinkInline(TabularDynamicInlineAdmin):
@@ -33,6 +35,6 @@ class CustomProductAdmin(ProductAdmin):
     inlines = [ProductImageAdmin, ProductVariationAdmin, ProductLinkInline]
 
 
-admin.site.register(ProductBlock, ProductBlockAdmin)
+admin.site.register(ProductList, ProductListAdmin)
 admin.site.unregister(Product)
 admin.site.register(Product, CustomProductAdmin)
diff --git a/app/organization/shop/migrations/0004_auto_20160926_1144.py b/app/organization/shop/migrations/0004_auto_20160926_1144.py
new file mode 100644 (file)
index 0000000..7b7b78e
--- /dev/null
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-26 09:44
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-shop', '0003_productlink'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='productblock',
+            name='content',
+            field=mezzanine.core.fields.RichTextField(default='', verbose_name='Content'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='productblock',
+            name='content_en',
+            field=mezzanine.core.fields.RichTextField(null=True, verbose_name='Content'),
+        ),
+        migrations.AddField(
+            model_name='productblock',
+            name='content_fr',
+            field=mezzanine.core.fields.RichTextField(null=True, verbose_name='Content'),
+        ),
+        migrations.AddField(
+            model_name='productblock',
+            name='description_en',
+            field=models.TextField(blank=True, null=True, verbose_name='description'),
+        ),
+        migrations.AddField(
+            model_name='productblock',
+            name='description_fr',
+            field=models.TextField(blank=True, null=True, verbose_name='description'),
+        ),
+    ]
diff --git a/app/organization/shop/migrations/0005_auto_20160926_1230.py b/app/organization/shop/migrations/0005_auto_20160926_1230.py
new file mode 100644 (file)
index 0000000..91c5872
--- /dev/null
@@ -0,0 +1,91 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-26 10:30
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('shop', '0008_auto_20160907_1726'),
+        ('pages', '0005_auto_20160923_1219'),
+        ('organization-shop', '0004_auto_20160926_1144'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='PageProductList',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+            ],
+            options={
+                'verbose_name': 'product list',
+                'verbose_name_plural': 'product lists',
+            },
+        ),
+        migrations.CreateModel(
+            name='ProductListProduct',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('_order', mezzanine.core.fields.OrderField(null=True, verbose_name='Order')),
+            ],
+            options={
+                'verbose_name': 'product',
+                'verbose_name_plural': 'products',
+                'ordering': ('_order',),
+            },
+        ),
+        migrations.RenameModel(
+            old_name='ProductBlock',
+            new_name='ProductList',
+        ),
+        migrations.RemoveField(
+            model_name='pageproductblock',
+            name='page',
+        ),
+        migrations.RemoveField(
+            model_name='pageproductblock',
+            name='product_block',
+        ),
+        migrations.RemoveField(
+            model_name='productblockproduct',
+            name='product',
+        ),
+        migrations.RemoveField(
+            model_name='productblockproduct',
+            name='product_block',
+        ),
+        migrations.AlterModelOptions(
+            name='productlist',
+            options={'verbose_name': 'product list', 'verbose_name_plural': 'product lists'},
+        ),
+        migrations.DeleteModel(
+            name='PageProductBlock',
+        ),
+        migrations.DeleteModel(
+            name='ProductBlockProduct',
+        ),
+        migrations.AddField(
+            model_name='productlistproduct',
+            name='list',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='products', to='organization-shop.ProductList', verbose_name='product list'),
+        ),
+        migrations.AddField(
+            model_name='productlistproduct',
+            name='product',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='lists', to='shop.Product', verbose_name='product'),
+        ),
+        migrations.AddField(
+            model_name='pageproductlist',
+            name='list',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pages', to='organization-shop.ProductList', verbose_name='product list'),
+        ),
+        migrations.AddField(
+            model_name='pageproductlist',
+            name='page',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='product_lists', to='pages.Page', verbose_name='page'),
+        ),
+    ]
index cf1588a9abce5cddff8b615c2e6aea3e3568cdd6..30db82e57fabf199f6084ef22be834f1a3c872ce 100644 (file)
@@ -15,22 +15,22 @@ PRODUCT_LIST_STYLE_CHOICES = [
 ]
 
 
-class ProductBlock(Titled):
+class ProductList(Titled, RichText):
 
     style = models.CharField(_('style'), max_length=16, choices=PRODUCT_LIST_STYLE_CHOICES)
 
     class Meta:
-        verbose_name = _("product block")
-        verbose_name_plural = _("product blocks")
+        verbose_name = _("product list")
+        verbose_name_plural = _("product lists")
 
     def __str__(self):
         return self.title
 
 
-class ProductBlockProduct(Orderable):
+class ProductListProduct(Orderable):
 
-    product_block = models.ForeignKey(ProductBlock, verbose_name=_('product block'), related_name='products', blank=True, null=True, on_delete=models.SET_NULL)
-    product = models.ForeignKey(Product, verbose_name=_('product'), related_name='blocks', blank=True, null=True, on_delete=models.SET_NULL)
+    list = models.ForeignKey(ProductList, verbose_name=_('product list'), related_name='products', blank=True, null=True, on_delete=models.SET_NULL)
+    product = models.ForeignKey(Product, verbose_name=_('product'), related_name='lists', blank=True, null=True, on_delete=models.SET_NULL)
 
     class Meta:
         verbose_name = _("product")
@@ -38,14 +38,14 @@ class ProductBlockProduct(Orderable):
 
 
 
-class PageProductBlock(models.Model):
+class PageProductList(models.Model):
 
-    page = models.ForeignKey('pages.Page', verbose_name=_('page'), related_name='product_blocks', blank=True, null=True, on_delete=models.SET_NULL)
-    product_block = models.ForeignKey('organization-shop.ProductBlock', verbose_name=_('product block'), related_name='pages', blank=True, null=True, on_delete=models.SET_NULL)
+    page = models.ForeignKey('pages.Page', verbose_name=_('page'), related_name='product_lists', blank=True, null=True, on_delete=models.SET_NULL)
+    list = models.ForeignKey('organization-shop.ProductList', verbose_name=_('product list'), related_name='pages', blank=True, null=True, on_delete=models.SET_NULL)
 
     class Meta:
-        verbose_name = _("product block")
-        verbose_name_plural = _("product blocks")
+        verbose_name = _("product list")
+        verbose_name_plural = _("product lists")
 
 
 class ProductLink(Link):
index 57d5a2667465de48664972e428daf603301e2c2d..9f3c1acca03fbfd6a5d39aef2bfa886b05836961 100644 (file)
@@ -4,20 +4,20 @@ from organization.shop.models import *
 
 
 
-@register(ProductBlock)
-class ProductBlockTranslationOptions(TranslationOptions):
+@register(ProductList)
+class ProductListTranslationOptions(TranslationOptions):
 
-    fields = ['title',]
+    fields = ['title', 'description', 'content']
 
 
-@register(ProductBlockProduct)
-class ProductBlockProductTranslationOptions(TranslationOptions):
+@register(ProductListProduct)
+class ProductListProductTranslationOptions(TranslationOptions):
 
     pass
 
 
-@register(PageProductBlock)
-class PageProductBlockTranslationOptions(TranslationOptions):
+@register(PageProductList)
+class PageProductListTranslationOptions(TranslationOptions):
 
     pass
 
index a6eca743e93b806be9c2d6184924702532588398..e4cbab50597ac19e6eeefe5a5a6e625c5e01139a 100644 (file)
 {% endblock %}
 
 {% block page_person_list %}
-    {% for page_custom_person_list_block_inline in page.custompage.page_custom_person_list_block_inlines.all  %}
-      {% with page_custom_person_list_block_inline.person_list_block as person_list_block %}
-        {% with "network/inc/person/list_"|add:person_list_block.style|add:"_style.html" as template %}
-          {% include template %}
-        {% endwith %}
-      {% endwith %}
-    {% endfor %}
+  {% for inline in page.custompage.page_custom_person_list_block_inlines.all  %}
+    {% with "network/inc/person/list_"|add:inline.person_list_block.style|add:"_style.html" as template %}
+      {% include template %}
+    {% endwith %}
+  {% endfor %}
 {% endblock %}
 
 {% block page_sub_content %}
   {% endwith %}
 {% endblock %}
 
+{% block products %}
+    {% for page_product_list in page.custompage.product_lists.all %}
+      {% with page_product_list.list as list %}
+        {% with "shop/includes/product_list_"|add:list.style|add:"_style.html" as template %}
+          {% include template %}
+        {% endwith %}
+      {% endwith %}
+    {% endfor %}
+{% endblock %}
+
 {% block logo %}
     {% with page.custompage.images.all|get_type:'logo' as images %}
         {% if images %}
index 6cea623929148a3f73eac784da667fa236dd833c..b2690f510556a85f6749ed196cc4c7a5af4f1c88 100644 (file)
@@ -70,6 +70,8 @@
         {% endblock %}
         {% block page_person_list %}
         {% endblock %}
+        {% block products %}
+        {% endblock %}
         {% block page_sub_content %}
         {% endblock %}
         {% block page_related_content %}
diff --git a/app/templates/shop/includes/product_list_square_style.html b/app/templates/shop/includes/product_list_square_style.html
new file mode 100644 (file)
index 0000000..d0e75d6
--- /dev/null
@@ -0,0 +1,46 @@
+{% load organization_tags mezzanine_tags %}
+{% if list %}
+    <div class="white-bg pb2">
+        <hr class="mt0" />
+        <div class="container">
+            <div class="row">
+                <div class="col-sm-9 col-sm-push-3 col-lg-8 col-lg-push-2" data-summary-content>
+                    <h2 class="dotted">{{ list.title }}</h2>
+                    {% if list.description %}
+                        <p>{{ list.description }}</p>
+                    {% endif %}
+                </div>
+            </div>
+        </div>
+
+        <div class="container-fluid">
+            <div class="row tac">
+                {% for product_inline in list.products.all %}
+                  {% with product_inline.product as product %}
+                    <div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
+                        <div class="article-box article-box--person" >
+                            {% if product.images.all %}
+                                <div class="article-box__header">
+                                    <a href="{{ product.get_absolute_url }}" title="{{ product.title }}">
+                                        <figure class="article-box__image">
+                                            <img class="lazyload" src="{{ MEDIA_URL }}{% thumbnail product.images.all.0 427 500 top=0.5 %}" alt="product"/>
+                                        </figure>
+                                    </a>
+                                </div>
+                            {% endif %}
+                            <div class="article-box__content tal">
+                                <a href="{{ product.get_absolute_url }}" title="{{ product.title }}"><h3 class="article-box__title">{{ product.title }}</h3></a>
+                                {% if product.description %}
+                                    <div class="article-box__desc">{{ product.description|richtext_filters|safe|truncatechars_html:255 }}</div>
+                                {% elif product.content %}
+                                    <div class="article-box__desc">{{ product.content|richtext_filters|safe|truncatechars_html:255 }}</div>
+                                {% endif %}
+                            </div>
+                        </div>
+                    </div>
+                  {% endwith %}
+                {% endfor %}
+            </div>
+        </div>
+    </div>
+{% endif %}