diff options
author | luxagraf <sng@luxagraf.net> | 2015-12-13 08:36:51 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-12-13 08:36:51 -0500 |
commit | 2bc926fe3537363f6f5e6883d927120b8ada41da (patch) | |
tree | 3d0905719be8b571bbea357fa26ceb5e86b5b8fb | |
parent | 12100874dc8e713d1d4400bee285ba381f6f449c (diff) |
added resizing function to photo uploads and changed wording on comments
template
-rw-r--r-- | app/TODO | 11 | ||||
-rw-r--r-- | app/photos/admin.py | 42 | ||||
-rw-r--r-- | app/photos/forms.py | 47 | ||||
-rw-r--r-- | app/photos/models.py | 76 | ||||
-rw-r--r-- | app/photos/urls.py | 5 | ||||
-rw-r--r-- | app/photos/views.py | 12 | ||||
-rw-r--r-- | config/base_urls.py | 4 | ||||
-rw-r--r-- | design/templates/admin/buttons.html | 2 | ||||
-rw-r--r-- | design/templates/comments/form.html | 2 |
9 files changed, 103 insertions, 98 deletions
@@ -44,6 +44,17 @@ Then play with gallery templates and add a template selecter to form. like this full width design: http://www.photobyrichard.com/photobyrichard/page/2/ +Next step is to create private galleries and password protect them on the server at a common url. Flow will be something like: + +galleries = PhotoGallery.object.filter(private=True) +for gal in galleries: + create at url like /photos/private/gallery-list and + /photos/private/gallery-name + +Then just require a password to get to anything under /photos/private/ + +Then change the default PhotoGallery manager to filter out anything marked private. Or make sure to write all those queries with .filter(private=False) + --- # birds app: diff --git a/app/photos/admin.py b/app/photos/admin.py index dbcca64..b247bff 100644 --- a/app/photos/admin.py +++ b/app/photos/admin.py @@ -3,7 +3,7 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.conf.urls import patterns from django.conf.urls import url from django.utils.translation import ungettext, ugettext_lazy as _ -from photos.models import Photo, PhotoGallery, LuxImage, Gallery +from photos.models import Photo, PhotoGallery, LuxImage, LuxGallery from django.shortcuts import render from django.contrib.admin import helpers from django.http import HttpResponseRedirect @@ -20,15 +20,15 @@ class LuxImageAdmin(OSMGeoAdmin): admin.site.register(LuxImage, LuxImageAdmin) -class GalleryAdmin(OSMGeoAdmin): +class LuxGalleryAdmin(OSMGeoAdmin): list_display = ('title', 'location', 'pub_date') list_filter = ('location',) def get_urls(self): - urls = super(GalleryAdmin, self).get_urls() + urls = super(LuxGalleryAdmin, self).get_urls() custom_urls = [ url( - r'^upload_zip/$', + r'upload_zip/$', self.admin_site.admin_view(self.upload_zip), name='upload_zip' ) @@ -57,7 +57,7 @@ class GalleryAdmin(OSMGeoAdmin): {}) return render(request, 'admin/upload_zip.html', context) -admin.site.register(Gallery, GalleryAdmin) +admin.site.register(LuxGallery, LuxGalleryAdmin) class PhotoAdmin(OSMGeoAdmin): @@ -131,37 +131,5 @@ class PhotoGalleryAdmin(OSMGeoAdmin): }), ) - def get_urls(self): - urls = super(PhotoGalleryAdmin, self).get_urls() - custom_urls = [ - url( - r'^upload_zip/$', - self.admin_site.admin_view(self.upload_zip), - name='upload_zip' - ) - ] - return custom_urls + urls - - def upload_zip(self, request): - context = { - 'title': _('Upload a zip archive of photos'), - 'app_label': self.model._meta.app_label, - 'opts': self.model._meta, - 'has_change_permission': self.has_change_permission(request) - } - - # Handle form request - if request.method == 'POST': - form = UploadZipForm(request.POST, request.FILES) - if form.is_valid(): - form.save(request=request) - return HttpResponseRedirect('..') - else: - form = UploadZipForm() - context['form'] = form - context['adminform'] = helpers.AdminForm(form, - list([(None, {'fields': form.base_fields})]), - {}) - return render(request, 'admin/upload_zip.html', context) admin.site.register(PhotoGallery, PhotoGalleryAdmin) diff --git a/app/photos/forms.py b/app/photos/forms.py index eae0e7e..6e299cd 100644 --- a/app/photos/forms.py +++ b/app/photos/forms.py @@ -11,24 +11,23 @@ try: except ImportError: from PIL import Image - from django import forms from django.utils.translation import ugettext_lazy as _ from django.contrib import messages -from django.contrib.sites.models import Site -from django.conf import settings -from django.utils.encoding import force_text -from django.template.defaultfilters import slugify from django.core.files.base import ContentFile from django.contrib.admin import widgets from django.contrib.gis.geos import Point +from django.conf import settings import exiftool -from photos.models import LuxImage, Gallery +from photos.models import LuxImage, LuxGallery from locations.models import Location +from .utils import resize_image + logger = logging.getLogger('photos.forms') + class UploadZipForm(forms.Form): """ Handles the uploading of a gallery of photos packed in a .zip file @@ -60,7 +59,7 @@ class UploadZipForm(forms.Form): def clean_title(self): title = self.cleaned_data['title'] - if title and Gallery.objects.filter(title=title).exists(): + if title and LuxGallery.objects.filter(title=title).exists(): raise forms.ValidationError(_('A gallery with that title already exists.')) return title @@ -78,11 +77,12 @@ class UploadZipForm(forms.Form): if not zip_file: zip_file = self.cleaned_data['zip_file'] - gallery, created = Gallery.objects.get_or_create( - title= self.cleaned_data['title'], - description = self.cleaned_data['desc'], - slug= self.cleaned_data['slug'], - pub_date= self.cleaned_data['date'] + gallery, created = LuxGallery.objects.get_or_create( + title=self.cleaned_data['title'], + description=self.cleaned_data['desc'], + slug=self.cleaned_data['slug'], + pub_date=self.cleaned_data['date'], + is_public=self.cleaned_data['is_public'] ) zipper = zipfile.ZipFile(zip_file) count = 1 @@ -124,8 +124,8 @@ class UploadZipForm(forms.Form): continue image = LuxImage( - pub_date = datetime.datetime.now() - ) + pub_date=datetime.datetime.now() + ) contentfile = ContentFile(data) image.image.save(filename, contentfile) image.save() @@ -136,11 +136,11 @@ class UploadZipForm(forms.Form): et.terminate() image.exif_raw = meta try: - image.title = meta["EXIF:ImageDescription"] + image.title = meta["EXIF:ImageDescription"] except: pass try: - image.caption = meta["EXIF:UserComment"] + image.caption = meta["EXIF:UserComment"] except: pass try: @@ -149,17 +149,17 @@ class UploadZipForm(forms.Form): pass try: image.point = Point(meta["XMP:GPSLongitude"], meta["XMP:GPSLatitude"], srid=4326) - try: + try: image.location = Location.objects.filter(geometry__contains=image.point).get() except Location.DoesNotExist: pass except KeyError: pass image.exif_aperture = meta["EXIF:FNumber"] - image.exif_make = meta["EXIF:Make"] - image.exif_model = meta["EXIF:Model"] + image.exif_make = meta["EXIF:Make"] + image.exif_model = meta["EXIF:Model"] image.exif_exposure = str(Fraction(float(meta["EXIF:ExposureTime"])).limit_denominator()) - image.exif_iso = meta["EXIF:ISO"] + image.exif_iso = meta["EXIF:ISO"] image.exif_focal_length = meta["EXIF:FocalLength"] fmt_date = time.strptime(meta["EXIF:DateTimeOriginal"], "%Y:%m:%d %H:%M:%S") image.exif_date = time.strftime("%Y-%m-%d %H:%M:%S", fmt_date) @@ -167,7 +167,12 @@ class UploadZipForm(forms.Form): image.width = meta["File:ImageWidth"] image.save() count += 1 - + img = Image.open(image.image.path) + base_path = "%s/galleries/" % settings.IMAGES_ROOT + resize_image(img, 2280, None, 65, base_path+'large/', image.get_image_name()) + resize_image(img, 1140, None, 72, base_path+'medium/', image.get_image_name()) + resize_image(img, 720, None, 68, base_path+'small/', image.get_image_name()) + zipper.close() if request: diff --git a/app/photos/models.py b/app/photos/models.py index d3024d9..f0d5540 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -10,12 +10,14 @@ from django.conf import settings from taggit.managers import TaggableManager from locations.models import Location, Region + def get_upload_path(self, filename): - return "images/galleries/originals/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + return "images/galleries/original/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + class LuxImage(models.Model): image = models.FileField(blank=True, null=True, upload_to=get_upload_path) - title = models.CharField(null=True,blank=True, max_length=300) + title = models.CharField(null=True, blank=True, max_length=300) caption = models.TextField(blank=True, null=True) pub_date = models.DateTimeField() exif_raw = models.TextField(blank=True, null=True) @@ -33,8 +35,8 @@ class LuxImage(models.Model): location = models.ForeignKey(Location, null=True, blank=True) is_public = models.BooleanField(default=True) is_video = models.BooleanField(default=False) - flickr_id = models.CharField(null=True,blank=True, max_length=80) - + flickr_id = models.CharField(null=True, blank=True, max_length=80) + class Meta: ordering = ('-pub_date', 'id') verbose_name_plural = 'Images' @@ -43,12 +45,45 @@ class LuxImage(models.Model): def __str__(self): return "%s" % self.pk + def get_image_name(self): + return self.image.url.split("galleries/original/")[1] + + def get_image_size(self, size="original"): + base = self.get_image_name() + return "%sgalleries/%s/%s" % (settings.IMAGES_URL, size, base) + def admin_thumbnail(self): - return force_text('<a href="%s"><img src="%s"></a>' % - (self.image.url, self.image.url)) + return force_text('<a href="%s"><img src="%s"></a>' % (self.image.url, self.image.url)) admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail' + +class LuxGallery(models.Model): + title = models.CharField(blank=True, max_length=300) + description = models.TextField(blank=True, null=True) + slug = models.CharField(blank=True, max_length=300) + thumb = models.CharField(blank=True, max_length=300) + image = models.ManyToManyField(LuxImage) + pub_date = models.DateTimeField(null=True) + point = models.PointField(null=True, blank=True) + location = models.ForeignKey(Location, null=True, blank=True) + is_public = models.BooleanField(default=True) + + class Meta: + ordering = ('-pub_date', 'id') + verbose_name_plural = 'Galleries' + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_main_image(self): + return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) + + def get_absolute_url(self): + return "/photos/galleries/%s/" % (self.slug) + + class Photo(models.Model): description = models.TextField(blank=True, null=True) title = models.CharField(blank=True, max_length=300) @@ -84,8 +119,7 @@ class Photo(models.Model): ordering = ('-pub_date',) def admin_thumbnail(self): - return force_text('<a href="%s"><img src="%s"></a>' % - (self.get_absolute_url(), self.get_small_square_url())) + return force_text('<a href="%s"><img src="%s"></a>' % (self.get_absolute_url(), self.get_small_square_url())) admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail' @@ -120,7 +154,7 @@ class Photo(models.Model): return self.get_pic_url(size="medium") def get_original_url(self): - #return self.get_pic_url(size="original") + # return self.get_pic_url(size="original") return "http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (self.flickr_farm, self.flickr_server, self.flickr_id, self.flickr_originalsecret) def get_retina_slideshow_url(self): @@ -209,30 +243,6 @@ class Photo(models.Model): def save(self, *args, **kwargs): super(Photo, self).save() -class Gallery(models.Model): - title = models.CharField(blank=True, max_length=300) - description = models.TextField(blank=True, null=True) - slug = models.CharField(blank=True, max_length=300) - thumb = models.CharField(blank=True, max_length=300) - image = models.ManyToManyField(LuxImage) - pub_date = models.DateTimeField(null=True) - point = models.PointField(null=True, blank=True) - location = models.ForeignKey(Location, null=True, blank=True) - - class Meta: - ordering = ('-pub_date', 'id') - verbose_name_plural = 'Galleries' - get_latest_by = 'pub_date' - - def __str__(self): - return self.title - - def get_main_image(self): - return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) - - def get_absolute_url(self): - return "/photos/galleries/%s/" % (self.slug) - class PhotoGallery(models.Model): set_id = models.CharField(blank=True, max_length=300) diff --git a/app/photos/urls.py b/app/photos/urls.py index 78acb1c..0c7b752 100644 --- a/app/photos/urls.py +++ b/app/photos/urls.py @@ -11,6 +11,11 @@ urlpatterns = [ views.photo_json ), url( + r'galleries/private/(?P<slug>[-\w]+)$', + views.PrivateGallery.as_view(), + name="private" + ), + url( r'galleries/(?P<slug>[-\w]+)/$', views.gallery, ), diff --git a/app/photos/views.py b/app/photos/views.py index 0def0e3..970bbd9 100644 --- a/app/photos/views.py +++ b/app/photos/views.py @@ -3,9 +3,19 @@ from django.template import RequestContext from django.http import Http404, HttpResponse from django.core import serializers -from photos.models import Photo, PhotoGallery +from photos.models import Photo, PhotoGallery, LuxGallery from locations.models import Country, Region +from utils.views import PaginatedListView +from django.views.generic import ListView +from django.views.generic.detail import DetailView + +class PrivateGallery(DetailView): + model = LuxGallery + slug_field = "slug" + template_name = "details/photo_gallery.html" + + def gallery_list(request, page): request.page_url = '/photos/%d/' request.page = int(page) diff --git a/config/base_urls.py b/config/base_urls.py index b5751f0..26a2081 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -50,10 +50,6 @@ urlpatterns += [ include('notes.urls', namespace='notes') ), url( - r'^photo/', - include('photos.detail_urls', namespace='photos') - ), - url( r'^birds/', include('birds.urls', namespace='birds') ), diff --git a/design/templates/admin/buttons.html b/design/templates/admin/buttons.html index 677fa08..872bf74 100644 --- a/design/templates/admin/buttons.html +++ b/design/templates/admin/buttons.html @@ -52,7 +52,7 @@ <li class="item"><a href="/admin/build/build?id=sitemap">Build Sitemap</a></li> <li class="item"><a href="/admin/build/build?id=src">Build src</a></li> <li class="item"><a href="/admin/build/build?id=scrapeflickr">Scrape Flickr</a></li> - <li class="item"><a href="/admin/photos/gallery/upload_zip">Upload Photos</a></li> + <li class="item"><a href="{% url 'admin:upload_zip'%}">Upload Photos</a></li> </ul> </div> </div> diff --git a/design/templates/comments/form.html b/design/templates/comments/form.html index 35391f0..a2cb063 100644 --- a/design/templates/comments/form.html +++ b/design/templates/comments/form.html @@ -21,5 +21,5 @@ <input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" /> </p> </form> -<p style="font-size: 95%;"><strong>All comments are moderated</strong>, so you won’t see it right away. If we’re on the road sometimes it takes a few days, but we’ll get it up as soon as we can. You can use Markdown or HTML to format your comments. The allowed tags are <code><b>, <i>, <em>, <strong>, <a></code>. To create a new paragraph hit return twice. Remember Kurt Vonnegut's rule: “god damn it, you’ve got to be kind.”</p> +<p style="font-size: 95%;"><strong>All comments are moderated</strong>, so you won’t see it right away. If you see it at all. I only publish comments that add good words to the world. Remember Kurt Vonnegut's rule: “god damn it, you’ve got to be kind.” In other words if you want to shit in a pool, go build your own. You can use Markdown or HTML to format your comments. The allowed tags are <code><b>, <i>, <em>, <strong>, <a></code>. To create a new paragraph hit return twice. </p> </div> |