adding two fields for images links in collections and removing piwik from iconolab application in template
authorRiwad Salim
Thu, 05 Jul 2018 11:49:21 +0200
changeset 566 238d1023c776
parent 565 9c51f0bb60f5
child 567 65f01d6a5963
adding two fields for images links in collections and removing piwik from iconolab application in template -- HG: user: Riwad Salim HG: branch 'default' HG: added src/iconolab/migrations/0032_auto_20180704_1131.py HG: changed src/iconolab/models.py *** Adding two fields to collection for image link constitution and removing piwik from iconolab generic application
src/iconolab/migrations/0032_auto_20180704_1131.py
src/iconolab/models.py
src/iconolab/templates/iconolab_base.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/migrations/0032_auto_20180704_1131.py	Thu Jul 05 11:49:21 2018 +0200
@@ -0,0 +1,23 @@
+# Generated by Django 2.0.6 on 2018-07-04 11:31
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('iconolab', '0031_auto_20180627_1320'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='collection',
+            name='link_text',
+            field=models.CharField(blank=True, default='', max_length=1024, null=True),
+        ),
+        migrations.AddField(
+            model_name='collection',
+            name='link_url',
+            field=models.CharField(blank=True, default='', max_length=1024, null=True),
+        ),
+    ]
--- a/src/iconolab/models.py	Sat Jun 30 01:05:14 2018 +0200
+++ b/src/iconolab/models.py	Thu Jul 05 11:49:21 2018 +0200
@@ -49,6 +49,8 @@
     height = models.IntegerField(null=True, blank=True)
     width = models.IntegerField(null=True, blank=True)
     show_image_on_home = models.BooleanField(default=False)
+    link_text = models.CharField(max_length=1024, default="", null=True, blank=True)
+    link_url = models.CharField(max_length=1024, default="", null=True, blank=True)
 
     @cached_property
     def items_count(self):
@@ -67,6 +69,7 @@
     def __str__(self):
         return self.name
 
+
 class Folder(models.Model):
     """
         Some items may belong to a "folder". This is actually a physical folder
@@ -119,6 +122,30 @@
         res.sort(key=lambda img: img.name, reverse=True)
         return res
 
+    @cached_property
+    def get_item_link_text(self):
+        link_text = self.collection.link_text
+        if not link_text:
+            return ''
+        else:
+            try:
+                return link_text.format(**self.metadatas.metadata_obj)
+            except (ValueError, SyntaxError, TypeError, NameError):
+                return''
+                logger.info('the text link constitution is not corresponding.')
+
+    @cached_property
+    def get_item_link_url(self):
+        link_url = self.collection.link_url
+        if not link_url:
+            return ''
+        else:
+            try:
+                return link_url.format(**self.metadatas.metadata_obj)
+            except (ValueError, SyntaxError, TypeError, NameError):
+                return ''
+                logger.info('the url link constitution is not corresponding.')
+
 
 class ItemMetadata(models.Model):
     """
--- a/src/iconolab/templates/iconolab_base.html	Sat Jun 30 01:05:14 2018 +0200
+++ b/src/iconolab/templates/iconolab_base.html	Thu Jul 05 11:49:21 2018 +0200
@@ -37,5 +37,8 @@
       <!-- Webpack devServer script to handle page reload -->
       <script src="http://localhost:8001/webpack-dev-server.js" type="text/javascript"></script>
       {% endif %}
+      {% if not "localhost" in request.get_host %}
+      {% block analytics %} {% endblock %}
+      {% endif %}
 	</body>
 </html>