diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/blog/admin.py | 7 | ||||
-rw-r--r-- | apps/blog/models.py | 22 | ||||
-rw-r--r-- | apps/blog/views.py | 13 | ||||
-rw-r--r-- | apps/links/utils.py | 2 | ||||
-rw-r--r-- | apps/photos/models.py | 9 | ||||
-rw-r--r-- | apps/photos/urls.py | 2 | ||||
-rw-r--r-- | apps/photos/utils.py | 110 | ||||
-rw-r--r-- | apps/photos/views.py | 5 |
8 files changed, 146 insertions, 24 deletions
diff --git a/apps/blog/admin.py b/apps/blog/admin.py index 78ad458..c5c5c5d 100644 --- a/apps/blog/admin.py +++ b/apps/blog/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin from django import forms -from blog.models import Entry, PostImage +from blog.models import Entry, PostImage, Topic from blog.widgets import AdminImageWidget from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.gis.maps.google import GoogleMap @@ -23,7 +23,7 @@ class EntryAdmin(OSMGeoAdmin): list_filter = ('pub_date', 'enable_comments', 'status','region','location') fieldsets = ( ('Entry', {'fields': ('title','body_markdown', ('location','region'), 'pub_date', ('status','enable_comments'), 'tags', 'slug','photo_gallery'), 'classes': ('show','extrapretty','wide')}), - ('Pub Location', {'fields': ('point',('thumbnail',),'dek', 'title_keywords'), 'classes': ('collapse', 'wide')}), + ('Pub Location', {'fields': ('point',('thumbnail',),'dek', 'topics', 'title_keywords'), 'classes': ('collapse', 'wide')}), ) class Media: @@ -71,6 +71,9 @@ class EntryAdmin(OSMGeoAdmin): class PostImageAdmin(admin.ModelAdmin): list_display = ('title', 'output_tags') +class TopicAdmin(admin.ModelAdmin): + list_display = ('name', 'slug') +admin.site.register(Topic, TopicAdmin) admin.site.register(PostImage, PostImageAdmin) admin.site.register(Entry, EntryAdmin) diff --git a/apps/blog/models.py b/apps/blog/models.py index 5ff6624..bdbcd82 100644 --- a/apps/blog/models.py +++ b/apps/blog/models.py @@ -35,6 +35,17 @@ class PostImage(models.Model): return force_unicode('<img src="%s%s" alt="%s" class="postpic"/>' % \ (settings.IMAGES_URL, self.image.url.split('images')[1].split('/',1)[1], self.title)) + +class Topic(models.Model): + name = models.CharField(max_length=100) + slug = models.SlugField() + + def __unicode__(self): + return self.name + + def get_absolute_url(self): + return "/topics/%s/" % (self.slug) + class Entry(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') @@ -56,6 +67,17 @@ class Entry(models.Model): photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') thumbnail = models.FileField(upload_to=get_upload_path, null=True,blank=True) title_keywords = models.CharField(max_length=200, null=True, blank=True) + topics = models.ManyToManyField(Topic, blank=True) + + @property + def longitude(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def latitude(self): + '''Get the site's latitude.''' + return self.point.y class Meta: ordering = ('-pub_date',) diff --git a/apps/blog/views.py b/apps/blog/views.py index 6ccdc28..ef933eb 100644 --- a/apps/blog/views.py +++ b/apps/blog/views.py @@ -5,7 +5,7 @@ from django.views.generic.list_detail import object_list from django.http import Http404 -from blog.models import Entry +from blog.models import Entry, Topic from locations.models import Region, Country def home(request): @@ -36,6 +36,17 @@ def entry_list(request,page): """ +List of all writing +""" +def topic_list(request,slug,page): + request.page_url = '/topics/'+slug+'/%d/' + request.page = int(page) + topic = Topic.objects.get(slug=slug) + qs = Entry.objects.filter(status__exact=1,topics=topic).order_by('-pub_date').select_related() + return object_list(request, queryset=qs, template_name='archives/topics.html',) + + +""" Grabs entries by region or country """ def entry_list_by_area(request,slug,page): diff --git a/apps/links/utils.py b/apps/links/utils.py index b94f196..9acbd52 100644 --- a/apps/links/utils.py +++ b/apps/links/utils.py @@ -109,7 +109,7 @@ def sync_delicious_links(*args, **kwargs): email_link(l) if l.status == 1: pass - post_to_tumblr(l) + #post_to_tumblr(l) #send_to_deliciousfb(l) if(dupe): break diff --git a/apps/photos/models.py b/apps/photos/models.py index 9b6d331..73098b3 100644 --- a/apps/photos/models.py +++ b/apps/photos/models.py @@ -47,7 +47,14 @@ class Photo(models.Model): admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail' + def get_local_medium_url(self): + return '%sflickr/med/%s/%s.jpg' %(settings.IMAGES_URL,self.pub_date.strftime("%Y"),self.flickr_id) + def get_local_orig_url(self): + return '%sflickr/full/%s/%s.jpg' %(settings.IMAGES_URL,self.pub_date.strftime("%Y"),self.flickr_id) + + def get_local_slideshow_url(self): + return '%sslideshow/%s/%s.jpg' %(settings.IMAGES_URL,self.pub_date.strftime("%Y"),self.flickr_id) def __unicode__(self): return self.title @@ -139,7 +146,7 @@ class PhotoGallery(models.Model): return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) def get_absolute_url(self): - return "/photos/album/%s/" % (self.id) + return "/photos/galleries/%s/" % (self.set_slug) class PhotoSitemap(Sitemap): diff --git a/apps/photos/urls.py b/apps/photos/urls.py index 44b4869..b53b343 100644 --- a/apps/photos/urls.py +++ b/apps/photos/urls.py @@ -5,7 +5,7 @@ from django.views.generic.simple import redirect_to urlpatterns = patterns('', - (r'(?P<slug>[-\w]+)/(?P<page>\d+)/$', 'photos.views.gallery_list_by_area'), + (r'galleries/(?P<slug>[-\w]+)/$', 'photos.views.gallery'), (r'(?P<page>\d+)/$', 'photos.views.gallery_list'), (r'(?P<slug>[-\w]+)/$', redirect_to, {'url': '/photos/%(slug)s/1/'}), (r'', redirect_to, {'url': '/photos/1/'}), diff --git a/apps/photos/utils.py b/apps/photos/utils.py index de0884d..57a4cdb 100644 --- a/apps/photos/utils.py +++ b/apps/photos/utils.py @@ -55,7 +55,7 @@ def sync_flickr_photos(*args, **kwargs): print 'already have '+info['id']+' moving on' except ObjectDoesNotExist: taglist = [] - place = place_handler(force_unicode(info['latitude'])+","+force_unicode(info['longitude'])) + location, region = get_geo(float(info['latitude']),float(info['longitude'])) details = client.flickr_photos_getInfo(user_id=settings.FLICKR_USER_ID, photo_id=force_unicode(info['id'])) for t in details.findall('photo/tags/tag'): tag = dict((k, smart_unicode(t.get(k))) for k in t.keys()) @@ -78,12 +78,15 @@ def sync_flickr_photos(*args, **kwargs): exif_iso = exif['ISO Speed'], exif_lens = exif['Focal Length'], exif_date = flickr_datetime_to_datetime(exif["Date and Time (Original)"].replace(':', '-', 2)), - gps = force_unicode(info['latitude'])+","+force_unicode(info['longitude']), - place = place, + lat = float(info['latitude']), + lon = float(info['longitude']), + region = region, + location = location, tags = ", ".join(t for t in taglist) ) + #print info['title'], region, location photo.save() - make_local_size(photo) + #make_local_size(photo) def exif_handler(data): converted = {} @@ -109,20 +112,92 @@ def flickr_datetime_to_datetime(fdt): date_parts = strptime(fdt, '%Y-%m-%d %H:%M:%S') return datetime(*date_parts[0:6]) -def place_handler(gps): - place = Place.objects.all() - count = Place.objects.count() - num = 1 - for p in place: - if p.within_bounds(gps) is True: - return p - elif p.within_bounds(gps) is False and count == num: - return Place.objects.filter(name='Default').get() - num += 1 +def get_geo(lat,lon): + from locations.models import Location, Region + from django.contrib.gis.geos import Point + pnt_wkt = Point(lon, lat) + try: + location = Location.objects.get(geometry__contains=pnt_wkt) + except Location.DoesNotExist: + location = None + region = Region.objects.get(geometry__contains=pnt_wkt) + return location, region + ImageFile.MAXBLOCK = 1000000 -def make_local_size(photo,set): +def slideshow_image(photo): + slide_dir = settings.IMAGES_ROOT + '/slideshow/'+ photo.pub_date.strftime("%Y") + if not os.path.isdir(slide_dir): + os.makedirs(slide_dir) + med = photo.get_original_url() + fname = urllib.urlopen(med) + im = cStringIO.StringIO(fname.read()) # constructs a StringIO holding the image + img = Image.open(im) + cur_width, cur_height = img.size + #if image landscape + if cur_width > cur_height: + new_width = 800 + #check to make sure we aren't upsizing + if cur_width > new_width: + ratio = float(new_width)/cur_width + x = (cur_width * ratio) + y = (cur_height * ratio) + resized = img.resize((int(x), int(y)), Image.ANTIALIAS) + resized_filename = '%s/%s.jpg' %(slide_dir, photo.flickr_id) + resized.save(resized_filename, 'JPEG', quality=95, optimize=True) + else: + filename = '%s/%s.jpg' %(slide_dir, photo.flickr_id) + img.save(filename) + else: + #image portrait + new_height = 600 + #check to make sure we aren't upsizing + if cur_height > new_height: + ratio = float(new_height)/cur_height + x = (cur_width * ratio) + y = (cur_height * ratio) + resized = img.resize((int(x), int(y)), Image.ANTIALIAS) + resized_filename = '%s/%s.jpg' %(slide_dir, photo.flickr_id) + resized.save(resized_filename, 'JPEG', quality=95, optimize=True) + else: + filename = '%s/%s.jpg' %(slide_dir, photo.flickr_id) + img.save(filename) + +def make_local_copies(photo): + orig_dir = settings.IMAGES_ROOT + '/flickr/full/'+ photo.pub_date.strftime("%Y") + if not os.path.isdir(orig_dir): + os.makedirs(orig_dir) + full = photo.get_original_url() + fname = urllib.urlopen(full) + im = cStringIO.StringIO(fname.read()) # constructs a StringIO holding the image + img = Image.open(im) + local_full = '%s/%s.jpg' %(orig_dir, photo.flickr_id) + img.save(local_full) + #save large size + large_dir = settings.IMAGES_ROOT + '/flickr/large/'+ photo.pub_date.strftime("%Y") + if not os.path.isdir(large_dir): + os.makedirs(large_dir) + large = photo.get_large_url() + fname = urllib.urlopen(large) + im = cStringIO.StringIO(fname.read()) # constructs a StringIO holding the image + img = Image.open(im) + local_large = '%s/%s.jpg' %(large_dir, photo.flickr_id) + if img.format == 'JPEG': + img.save(local_large) + #save medium size + med_dir = settings.IMAGES_ROOT + '/flickr/med/'+ photo.pub_date.strftime("%Y") + if not os.path.isdir(med_dir): + os.makedirs(med_dir) + med = photo.get_medium_url() + fname = urllib.urlopen(med) + im = cStringIO.StringIO(fname.read()) # constructs a StringIO holding the image + img = Image.open(im) + local_med = '%s/%s.jpg' %(med_dir, photo.flickr_id) + img.save(local_med) + + +def make_gallery_thumb(photo,set): crop_dir = settings.IMAGES_ROOT + '/gallery_thumbs/' if not os.path.isdir(crop_dir): os.makedirs(crop_dir) @@ -392,8 +467,6 @@ for p in photos.photos.photo: make_local_size(photo) #if (dupe): #break - -""" from locations.models import Location from photos.models import Photo @@ -408,4 +481,5 @@ def find_loc(photos): print photo.id photo.save() except Location.DoesNotExist: - print "photo %s does not fall within any exisiting location" %(photo.id)
\ No newline at end of file + print "photo %s does not fall within any exisiting location" %(photo.id) +"""
\ No newline at end of file diff --git a/apps/photos/views.py b/apps/photos/views.py index 43591ca..5967333 100644 --- a/apps/photos/views.py +++ b/apps/photos/views.py @@ -3,6 +3,7 @@ from django.template import RequestContext from django.views.generic.list_detail import object_list from django.http import Http404 +from view_wrapper import luxagraf_render from tagging.models import Tag,TaggedItem from photos.models import Photo,PhotoGallery from locations.models import Country, Region @@ -20,6 +21,10 @@ def gallery_list(request,page): qs = PhotoGallery.objects.all().order_by('-id') return object_list(request, queryset=qs, template_name='archives/photos.html') +def gallery(request,slug): + g = PhotoGallery.objects.get(set_slug=slug) + return luxagraf_render(request,'details/photo_galleries.html', {'object': g,}) + """ Grabs entries by region or country |