diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/books/migrations/0003_auto_20161023_2014.py | 20 | ||||
-rw-r--r-- | app/daily/migrations/0010_auto_20161023_2014.py | 19 | ||||
-rw-r--r-- | app/jrnl/models.py | 12 | ||||
-rw-r--r-- | app/jrnl/views.py | 5 | ||||
-rw-r--r-- | app/photos/admin.py | 1 | ||||
-rw-r--r-- | app/photos/forms.py | 2 | ||||
-rw-r--r-- | app/photos/migrations/0011_luximagesize_name.py | 20 | ||||
-rw-r--r-- | app/photos/migrations/0012_luximagesize_is_portrait.py | 20 | ||||
-rw-r--r-- | app/photos/migrations/0013_auto_20161022_1348.py | 20 | ||||
-rw-r--r-- | app/photos/migrations/0014_remove_luximagesize_is_portrait.py | 19 | ||||
-rw-r--r-- | app/photos/migrations/0015_auto_20161022_1411.py | 20 | ||||
-rw-r--r-- | app/photos/migrations/0016_auto_20161022_1411.py | 25 | ||||
-rw-r--r-- | app/photos/models.py | 50 | ||||
-rw-r--r-- | app/syndication/migrations/0003_auto_20161023_2014.py | 19 |
14 files changed, 235 insertions, 17 deletions
diff --git a/app/books/migrations/0003_auto_20161023_2014.py b/app/books/migrations/0003_auto_20161023_2014.py new file mode 100644 index 0000000..809c465 --- /dev/null +++ b/app/books/migrations/0003_auto_20161023_2014.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-23 20:14 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0002_book_is_public'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='image', + field=models.FileField(blank=True, null=True, upload_to='/home/lxf/sites/luxagraf/site/media/images/book-covers/'), + ), + ] diff --git a/app/daily/migrations/0010_auto_20161023_2014.py b/app/daily/migrations/0010_auto_20161023_2014.py new file mode 100644 index 0000000..72a68cf --- /dev/null +++ b/app/daily/migrations/0010_auto_20161023_2014.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-23 20:14 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0009_remove_daily_title'), + ] + + operations = [ + migrations.AlterModelOptions( + name='daily', + options={'get_latest_by': 'date', 'ordering': ('-date',)}, + ), + ] diff --git a/app/jrnl/models.py b/app/jrnl/models.py index ceaefa6..2fc775e 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -37,15 +37,16 @@ def image_url_replace(s): def parse_image(s): soup = BeautifulSoup(s.group(), "lxml") for img in soup.find_all('img'): - print(img) src = img['src'].split("images/")[1] - print(src) i = LuxImage.objects.get(image__icontains=src) cl = img['class'] caption = False exif = False + cluster_class = None if len(cl) > 1: css_class = cl[0] + if css_class == 'cluster': + cluster_class = cl[1] if cl[1] == 'caption': caption = True if cl[1] == 'exif': @@ -59,7 +60,7 @@ def parse_image(s): print('caption'+str(caption)) else: css_class = cl[0] - c = Context({'image': i, 'caption': caption, 'exif': exif}) + c = Context({'image': i, 'caption': caption, 'exif': exif, 'cluster_class': cluster_class}) return render_to_string("lib/img_%s.html" % css_class, c) @@ -72,7 +73,10 @@ def extract_images(s): soup = BeautifulSoup(s, "lxml") imgs = [] for img in soup.find_all('img'): - imgs.append(img['src']) + try: + imgs.append(img['src']) + except: + pass return imgs diff --git a/app/jrnl/views.py b/app/jrnl/views.py index c68625d..6d0e85b 100644 --- a/app/jrnl/views.py +++ b/app/jrnl/views.py @@ -7,6 +7,7 @@ from django.conf import settings from utils.views import PaginatedListView from .models import Entry, HomepageCurrator +from daily.models import CheckIn from locations.models import Country, Region @@ -84,7 +85,8 @@ class HomepageList(ListView): Return a main entry and list of Entries in reverse chronological order """ context_object_name = 'recent' - queryset = Entry.objects.filter(status__exact=1)[:5] + exclude = HomepageCurrator.objects.get(pk=1) + queryset = Entry.objects.filter(status__exact=1).exclude(pk=exclude.featured.pk)[:8] def get_template_names(self): obj = HomepageCurrator.objects.get(pk=1) @@ -94,6 +96,7 @@ class HomepageList(ListView): # Call the base implementation first to get a context context = super(HomepageList, self).get_context_data(**kwargs) context['homepage'] = HomepageCurrator.objects.get(pk=1) + context['location'] = CheckIn.objects.get(pk=1) context['IMAGES_URL'] = settings.IMAGES_URL return context diff --git a/app/photos/admin.py b/app/photos/admin.py index 22de1fd..f0eb1c7 100644 --- a/app/photos/admin.py +++ b/app/photos/admin.py @@ -13,6 +13,7 @@ from .forms import UploadZipForm, GalleryForm class LuxImageSizeAdmin(OSMGeoAdmin): + list_display = ('name', 'width', 'height', 'quality') pass diff --git a/app/photos/forms.py b/app/photos/forms.py index 4e00189..06e829d 100644 --- a/app/photos/forms.py +++ b/app/photos/forms.py @@ -151,7 +151,7 @@ class UploadZipForm(forms.Form): if file_extension != ".mp4": img = Image.open(image.image.path) if img.size[0] > img.size[1]: - image.sizes.add(LuxImageSize.objects.get(width=2280)) + image.sizes.add(LuxImageSize.objects.get(width=2560)) image.sizes.add(LuxImageSize.objects.get(width=1140)) image.sizes.add(LuxImageSize.objects.get(width=720)) if img.size[1] > img.size[0]: diff --git a/app/photos/migrations/0011_luximagesize_name.py b/app/photos/migrations/0011_luximagesize_name.py new file mode 100644 index 0000000..49d046b --- /dev/null +++ b/app/photos/migrations/0011_luximagesize_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-21 08:46 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0010_auto_20160517_0906'), + ] + + operations = [ + migrations.AddField( + model_name='luximagesize', + name='name', + field=models.CharField(blank=True, max_length=30, null=True), + ), + ] diff --git a/app/photos/migrations/0012_luximagesize_is_portrait.py b/app/photos/migrations/0012_luximagesize_is_portrait.py new file mode 100644 index 0000000..a2c2e3a --- /dev/null +++ b/app/photos/migrations/0012_luximagesize_is_portrait.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-22 13:46 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0011_luximagesize_name'), + ] + + operations = [ + migrations.AddField( + model_name='luximagesize', + name='is_portrait', + field=models.BooleanField(default=False), + ), + ] diff --git a/app/photos/migrations/0013_auto_20161022_1348.py b/app/photos/migrations/0013_auto_20161022_1348.py new file mode 100644 index 0000000..8dfbf98 --- /dev/null +++ b/app/photos/migrations/0013_auto_20161022_1348.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-22 13:48 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0012_luximagesize_is_portrait'), + ] + + operations = [ + migrations.RenameField( + model_name='luximagesize', + old_name='width', + new_name='long_edge', + ), + ] diff --git a/app/photos/migrations/0014_remove_luximagesize_is_portrait.py b/app/photos/migrations/0014_remove_luximagesize_is_portrait.py new file mode 100644 index 0000000..b8e0aa8 --- /dev/null +++ b/app/photos/migrations/0014_remove_luximagesize_is_portrait.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-22 14:11 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0013_auto_20161022_1348'), + ] + + operations = [ + migrations.RemoveField( + model_name='luximagesize', + name='is_portrait', + ), + ] diff --git a/app/photos/migrations/0015_auto_20161022_1411.py b/app/photos/migrations/0015_auto_20161022_1411.py new file mode 100644 index 0000000..d380b52 --- /dev/null +++ b/app/photos/migrations/0015_auto_20161022_1411.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-22 14:11 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0014_remove_luximagesize_is_portrait'), + ] + + operations = [ + migrations.RenameField( + model_name='luximagesize', + old_name='long_edge', + new_name='width', + ), + ] diff --git a/app/photos/migrations/0016_auto_20161022_1411.py b/app/photos/migrations/0016_auto_20161022_1411.py new file mode 100644 index 0000000..54b84d7 --- /dev/null +++ b/app/photos/migrations/0016_auto_20161022_1411.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-22 14:11 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0015_auto_20161022_1411'), + ] + + operations = [ + migrations.AddField( + model_name='luximagesize', + name='height', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='luximagesize', + name='width', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/app/photos/models.py b/app/photos/models.py index 6940110..4207ad4 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -1,10 +1,13 @@ import os.path +import io import datetime from PIL import Image +from django.core.exceptions import ValidationError from django.contrib.gis.db import models from django.contrib.sitemaps import Sitemap from django.utils.encoding import force_text +from django.utils.text import slugify from django.conf import settings from taggit.managers import TaggableManager @@ -24,15 +27,20 @@ def get_upload_path(self, filename): class LuxImageSize(models.Model): - width = models.IntegerField() + name = models.CharField(null=True, blank=True, max_length=30) + width = models.IntegerField(null=True, blank=True) + height = models.IntegerField(null=True, blank=True) quality = models.IntegerField() class Meta: verbose_name_plural = 'Image Sizes' def __str__(self): - return str(self.width) - + if self.width: + size = self.width + if self.height: + size = self.height + return "%s - %s" %(self.name, str(size)) class LuxImage(models.Model): image = models.FileField(blank=True, null=True, upload_to=get_upload_path) @@ -75,8 +83,9 @@ class LuxImage(models.Model): def get_admin_image(self): for size in self.sizes.all(): - if size.width <= 800: - return self.get_image_by_size(size) + if size.width and size.width <= 820 or size.height and size.height<=800: + print("Size name" +size.name) + return self.get_image_by_size(size.name) def get_largest_image(self): t = [] @@ -139,12 +148,21 @@ class LuxImage(models.Model): n = self.get_next_by_pub_date() return "/admin/photos/luximage/%s/change/" % n.pk + @property + def is_portait(self): + if int(self.height) > int(self.width): + return True + else: + return False @receiver(post_save, sender=LuxImage) def post_save_events(sender, update_fields, created, instance, **kwargs): if instance.exif_raw == '': filename, file_extension = os.path.splitext(instance.image.path) if file_extension != ".mp4": + img = Image.open(instance.image.path) + instance.height = img.height + instance.width = img.width instance = readexif(instance) post_save.disconnect(post_save_events, sender=LuxImage) instance.save() @@ -159,16 +177,24 @@ def update_photo_sizes(sender, instance, **kwargs): img = Image.open(instance.image.path) resize_image(img, 160, None, 78, base_path, "%s_tn.%s" % (instance.get_image_name(), instance.get_image_ext())) for size in instance.sizes.all(): - if img.size[0] > img.size[1]: + if size.width: + print("Image width is:"+str(img.width)) try: - resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext())) + if size.width <= img.width: + resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), slugify(size.name), instance.get_image_ext())) + else: + raise ValidationError({'items': ["Size is larger than source image"]}) except ImageSizeError: m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through) instance.sizes.remove(size) m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through) - if img.size[1] > img.size[0]: + if size.height: try: - resize_image(img, None, size.width, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext())) + if size.height <= img.height: + resize_image(img, None, size.height, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), slugify(size.name), instance.get_image_ext())) + + else: + pass except ImageSizeError: m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through) instance.sizes.remove(size) @@ -205,10 +231,12 @@ class LuxGallery(models.Model): return "/photos/galleries/private/%s" % (self.slug) def latitude(self): - return self.point.y + if self.point: + return self.point.y def longitude(self): - return self.point.x + if self.point: + return self.point.x def thumbs(self): lst = [x.image.name for x in self.images.all()] diff --git a/app/syndication/migrations/0003_auto_20161023_2014.py b/app/syndication/migrations/0003_auto_20161023_2014.py new file mode 100644 index 0000000..2b311fb --- /dev/null +++ b/app/syndication/migrations/0003_auto_20161023_2014.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-23 20:14 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('syndication', '0002_auto_20160628_2149'), + ] + + operations = [ + migrations.AlterModelOptions( + name='fboauthtoken', + options={'get_latest_by': 'expires', 'ordering': ('-expires',)}, + ), + ] |