Repository: kartoza/prj.app

Issue:
We need to support variable sized icons based on sponsorship level
CC

@jef-n
@andreasneumann



Discussion:

Resolving patch:
diff --git a/django_project/changes/migrations/0005_auto_20160229_2050.py b/django_project/changes/migrations/0005_auto_20160229_2050.py
new file mode 100644
--- /dev/null
+++ b/django_project/changes/migrations/0005_auto_20160229_2050.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('changes', '0004_auto_20160221_2103'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='sponsorshiplevel',
+            name='logo_height',
+            field=models.IntegerField(default=100, help_text=b'Enter the height of the icon that should be used on the changelog'),
+        ),
+        migrations.AddField(
+            model_name='sponsorshiplevel',
+            name='logo_width',
+            field=models.IntegerField(default=100, help_text=b'Enter the width of the icon that should be used on the changelog'),
+        ),
+    ]
diff --git a/django_project/changes/models/sponsorship_level.py b/django_project/changes/models/sponsorship_level.py
--- a/django_project/changes/models/sponsorship_level.py
+++ b/django_project/changes/models/sponsorship_level.py
@@ -9,7 +9,6 @@
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.auth.models import User
 
-
 __author__ = 'rischan'
 
 
@@ -66,6 +65,24 @@ class SponsorshipLevel(models.Model):
         upload_to=os.path.join(MEDIA_ROOT, 'images/projects'),
         blank=False)
 
+    logo_width = models.IntegerField(
+        help_text=(
+            'Enter the width of the icon that should be used on the changelog'
+        ),
+        blank=False,
+        null=False,
+        default=100
+    )
+
+    logo_height = models.IntegerField(
+        help_text=(
+            'Enter the height of the icon that should be used on the changelog'
+        ),
+        blank=False,
+        null=False,
+        default=100
+    )
+
     approved = models.BooleanField(
         help_text=_(
             'Whether this sponsorship level has been approved for use by '
diff --git a/django_project/changes/models/sponsorship_period.py b/django_project/changes/models/sponsorship_period.py
--- a/django_project/changes/models/sponsorship_period.py
+++ b/django_project/changes/models/sponsorship_period.py
@@ -11,6 +11,7 @@
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.auth.models import User
+from easy_thumbnails.files import get_thumbnailer
 
 __author__ = 'rischan'
 
@@ -116,3 +117,22 @@ def current_sponsor(self):
             return False
         else:
             return True
+
+    def logo_url(self):
+        """Get the logo url sampled according to the size of sponsorship.
+
+        The idea here is that large sponsors get large logos and small
+        sponsors get small ones. You can specify the width and height in the
+        logo_height and logo_width properties.
+
+        This method is intended mainly for use from within your html templates.
+
+        :returns: A url to the resampled logo
+        :rtype: str
+        """
+        options = {'size': (
+            self.sponsorship_level.logo_width,
+            self.sponsorship_level.logo_height), 'crop': False}
+        thumb_url = get_thumbnailer(
+                self.sponsor.logo).get_thumbnail(options).url
+        return thumb_url


Test patch:
diff --git a/django_project/changes/tests/test_models.py b/django_project/changes/tests/test_models.py
--- a/django_project/changes/tests/test_models.py
+++ b/django_project/changes/tests/test_models.py
@@ -367,6 +367,8 @@ def test_SponsorshipLevel_update(self):
             'currency': u'IDR',
             'approved': False,
             'private': True,
+            'logo_width': 100,
+            'logo_height': 100
         }
         model.__dict__.update(new_model_data)
         model.save()