diff options
author | luxagraf <sng@luxagraf.net> | 2011-03-27 20:07:29 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2011-03-27 20:07:29 -0500 |
commit | d0e4499b968834592bd211c0bfecd00aaa042e9a (patch) | |
tree | 0280fb65fc98e94c282e928b0a0f95e4c2009795 | |
parent | cbad6ab096e23aea74c913fd37921652eca9728a (diff) |
removed remain references to django tagging and replaced with taggit (faster, fewer db queries)
-rw-r--r-- | apps/links/admin.py | 2 | ||||
-rw-r--r-- | apps/links/models.py | 15 | ||||
-rw-r--r-- | apps/links/retriever.py | 120 | ||||
-rw-r--r-- | apps/photos/models.py | 7 | ||||
-rw-r--r-- | apps/photos/retriever.py | 11 | ||||
-rw-r--r-- | apps/photos/views.py | 6 | ||||
-rw-r--r-- | cron/sync_links.py | 6 | ||||
-rw-r--r-- | cron/sync_photo_sets.py | 2 | ||||
-rw-r--r-- | cron/sync_photos.py | 2 | ||||
-rw-r--r-- | settings.py | 3 | ||||
-rw-r--r-- | templates/details/about.html | 2 |
11 files changed, 58 insertions, 118 deletions
diff --git a/apps/links/admin.py b/apps/links/admin.py index acd22df..2c73c76 100644 --- a/apps/links/admin.py +++ b/apps/links/admin.py @@ -8,7 +8,7 @@ class LinkAdmin(admin.ModelAdmin): list_filter = ['rating', 'status'] fieldsets = ( (None, {'fields': ('title','url','description','rating')}), - ('Details', {'fields': ('screen_url', 'pub_date', 'magnolia_id', 'tags', 'status'), 'classes': 'collapse'}), + ('Details', {'fields': ('screen_url', 'pub_date', 'link_id', 'tags', 'status'), 'classes': 'collapse'}), ) admin.site.register(Link, LinkAdmin)
\ No newline at end of file diff --git a/apps/links/models.py b/apps/links/models.py index e8fee43..09acc1c 100644 --- a/apps/links/models.py +++ b/apps/links/models.py @@ -4,9 +4,7 @@ from django.db import models from django.contrib.syndication.feeds import Feed from django.contrib.sitemaps import Sitemap -from tagging.fields import TagField -from tagging.models import Tag - +from taggit.managers import TaggableManager RATINGS = ( ('1', "1 Star"), @@ -19,20 +17,19 @@ RATINGS = ( DEBUG = 1 class Link(models.Model): + link_id = models.CharField(max_length=60, blank=True, null=True) title = models.CharField(max_length=400) - magnolia_id = models.CharField(max_length=60, blank=True, null=True) url = models.CharField(max_length=400) description = models.TextField(blank=True, null=True) - screen_url = models.CharField(max_length=400, blank=True) - rating = models.CharField(max_length=1, choices=RATINGS) + screen_url = models.CharField(max_length=400, blank=True, null=True) + rating = models.CharField(max_length=1, choices=RATINGS, null=True) pub_date = models.DateTimeField() - enable_comments = models.NullBooleanField(default=False) PUB_STATUS = ( (0, 'Private'), (1, 'Public'), ) status = models.IntegerField(choices=PUB_STATUS, default=0) - tags = TagField() + tags = TaggableManager(blank=True) class Meta: ordering = ['-pub_date'] @@ -52,8 +49,6 @@ class Link(models.Model): def get_next_published(self): return self.get_next_by_pub_date(status__exact=1) - def get_tags(self): - return Tag.objects.get_for_object(self) def get_thumbnail_url(self): return "http://images.luxagraf.net/magnolia_thumbs/%s" %(self.screen_url) diff --git a/apps/links/retriever.py b/apps/links/retriever.py index 35bd41a..f876405 100644 --- a/apps/links/retriever.py +++ b/apps/links/retriever.py @@ -1,75 +1,46 @@ -import time, datetime, urllib +import datetime from django.core.exceptions import ObjectDoesNotExist -from django.template.defaultfilters import slugify,striptags +from django.template.defaultfilters import striptags from django.core.mail import EmailMessage -from django.utils.encoding import smart_unicode from django.conf import settings from utils.strutils import safestr,unquotehtml -from utils.APIClients import MagnoliaClient -from utils import pydelicious as delicious -from utils import markdown2 as markdown - from links.models import Link +from utils import pinboard -def flickr_datetime_to_datetime(fdt): - from datetime import datetime - from time import strptime - date_parts = strptime(fdt, '%Y-%m-%dT%H:%M:%S%Z') - return datetime(*date_parts[0:6]) - -def sync_magnolia_links(*args, **kwargs): - #Number of links to retrieve at one time - get_num = 15 - BASE_PATH = 'http://ma.gnolia.com/api/rest/1/' - client = MagnoliaClient(BASE_PATH, settings.MAGNOLIA_API_KEY) - data = client.bookmarks_find(person="luxagraf",limit=get_num) +def sync_pinboard_links(): + """ + sync bookmarks from my pinboard account + + dependancies: python-pinboard https://github.com/mgan59/python-pinboard/ + """ + p = pinboard.open(settings.PIN_USER, settings.PIN_PASS) dupe = False - for post in data.findall('bookmarks/bookmark'): - taglist = [] - info = dict((k, smart_unicode(post.get(k))) for k in post.keys()) + links = p.posts(count=30) + for link in links: try: - row = Link.objects.get(magnolia_id=safestr(info['id'])) - # If the row exists already, set the dupe flag - dupe = True + #check to see if link exists + row = Link.objects.get(link_id=safestr(link['hash'])) except ObjectDoesNotExist: - f = copy_file(safestr(post.findtext('screenshot')), safestr(info['id'])) - local_image_url = "%s/%s.jpg" %(safestr(datetime.datetime.today().strftime("%b").lower()), safestr(info['id'])) - - for t in post.findall('tags/tag'): - tag = dict((k, smart_unicode(t.get(k))) for k in t.keys()) - taglist.append(tag['name']) - print tag['name'] - for tag in taglist: - if tag == '2lux': - status = 1 - break - else: - status = 0 - descr = markdown.markdown(unquotehtml(safestr(post.findtext('description'))), safe_mode = False) l, created = Link.objects.get_or_create( - title = post.findtext('title'), - magnolia_id = safestr(info['id']), - url = safestr(post.findtext('url')), - description = descr, - screen_url = local_image_url, - rating = safestr(info['rating']), - pub_date = datetime.datetime(*(time.strptime(str(info['created'][:-6]), '%Y-%m-%dT%H:%M:%S')[0:6])), - status = status, - enable_comments = True, - tags = ", ".join(t for t in taglist if t != "2lux") + title = link['description'], + link_id = safestr(link['hash']), + url = safestr(link['href']), + description = safestr(link['extended']), + rating = "3", + pub_date = datetime.datetime.strptime(link['time'], "%Y-%m-%dT%H:%M:%SZ"), + status = 0 ) - + print l.title + if created: + print l.title + for t in link['tags']: + l.tags.add(t) email_link(l) - send_to_delicious(l) - if l.status == 1: - post_to_tumblr(l) - send_to_deliciousfb(l) - if(dupe): - break - + +''' def sync_delicious_links(*args, **kwargs): b = delicious.get_all(settings.DELICIOUS_USER, settings.DELICIOUS_PASS) dupe = False @@ -116,8 +87,7 @@ def sync_delicious_links(*args, **kwargs): break - - +''' def email_link(link): """ @@ -125,9 +95,12 @@ def email_link(link): """ subject = link.title body = "%s\n\n%s\n\n\nvisit site:%s\n" %(link.title, link.description, link.url) - msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf@gmail.com']) + msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf+links@gmail.com']) msg.send() - + msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng+links@luxagraf.net']) + msg.send() + +''' def send_to_delicious(link): del_tags = '' tags = link.tags.split(',') @@ -135,27 +108,4 @@ def send_to_delicious(link): del_tags += tag.strip().replace(' ','_')+' ' delicious.add(settings.DELICIOUS_USER, settings.DELICIOUS_PASS, link.url, link.title, tags = del_tags, extended = striptags(link.description), dt =safestr(link.pub_date), replace="no") -def copy_file(url, id): - filename="/home/luxagraf/webapps/static/images/magnolia_thumbs/%s/%s.jpg" %(datetime.datetime.today().strftime("%b").lower(), id) - urllib.urlretrieve(url, filename) - return id - -def post_to_tumblr(link): - from links import tumblr - blog = settings.TUMBLR_URL - user= settings.TUMBLR_USER - password = settings.TUMBLR_PASSWORD - api = tumblr.Api(blog,user,password) - post = api.write_link(link.url,name=link.title,description=link.description,date=safestr(link.pub_date)) - -def send_to_deliciousfb(link): - """Wanted my links to go to Facebook and since the Facebook API is needlessly complex - I just created a second delicious account and added the feed via facebook""" - del_tags = '' - tags = link.tags.split(',') - for tag in tags: - del_tags += tag.strip().replace(' ','_')+' ' - desc = link.description.replace('<blockquote>','\n“') - desc = desc.replace('</blockquote>','”\n') - desc = striptags(desc) - delicious.add(settings.DELTOFACEUSER, settings.DELTOFACEPASS, link.url, link.title, tags = del_tags, extended = desc, dt =safestr(link.pub_date), replace="no") +'''
\ No newline at end of file diff --git a/apps/photos/models.py b/apps/photos/models.py index 5766e19..f13b17a 100644 --- a/apps/photos/models.py +++ b/apps/photos/models.py @@ -7,8 +7,7 @@ from django.utils.encoding import force_unicode from django.conf import settings -from tagging.fields import TagField -from tagging.models import Tag +from taggit.managers import TaggableManager from locations.models import Location,Region @@ -16,7 +15,7 @@ class Photo(models.Model): description = models.TextField(blank=True, null=True) title = models.CharField(blank=True, max_length=300) pub_date = models.DateTimeField() - tags = TagField() + tags = TaggableManager(blank=True) exif_aperture = models.CharField(max_length=50, blank=True, null=True) exif_make = models.CharField(max_length=50, blank=True, null=True) exif_model = models.CharField(max_length=50, blank=True, null=True) @@ -144,8 +143,6 @@ class Photo(models.Model): def get_tumble_image(self): return "%s/crops/%s/%s.jpg" %(settings.IMAGES_URL, self.pub_date.strftime("%Y/%b").lower(), self.id) - def get_tags(self): - return Tag.objects.get_for_object(self) def get_previous_published(self): return self.get_previous_by_pub_date() diff --git a/apps/photos/retriever.py b/apps/photos/retriever.py index 64889ba..8d7b07c 100644 --- a/apps/photos/retriever.py +++ b/apps/photos/retriever.py @@ -64,7 +64,7 @@ def sync_flickr_photos(*args, **kwargs): taglist.append(tag['raw']) exif = exif_handler(client.flickr_photos_getExif(user_id=API_KEY, photo_id=safestr(info['id']))) - photo = Photo.objects.create( + photo, created = Photo.objects.get_or_create( title = info['title'], flickr_id = info['id'], flickr_owner = info['owner'], @@ -86,8 +86,10 @@ def sync_flickr_photos(*args, **kwargs): lon = float(info['longitude']), region = region, location = location, - tags = ", ".join(t for t in taglist) ) + if created: + for t in taglist: + photo.tags.add(t) #print info['title'], region, location photo.save() make_local_copies(photo) @@ -130,7 +132,10 @@ def get_geo(lat,lon): location = Location.objects.get(geometry__contains=pnt_wkt) except Location.DoesNotExist: location = None - region = Region.objects.get(geometry__contains=pnt_wkt) + try: + region = Region.objects.get(geometry__contains=pnt_wkt) + except Region.DoesNotExist: + region = None return location, region diff --git a/apps/photos/views.py b/apps/photos/views.py index a1e3459..5b993b4 100644 --- a/apps/photos/views.py +++ b/apps/photos/views.py @@ -5,14 +5,8 @@ from django.http import Http404,HttpResponse from django.core import serializers -from tagging.models import Tag,TaggedItem from photos.models import Photo,PhotoGallery from locations.models import Country, Region - -def potd_list(request): - potd_obj = Tag.objects.filter(name__exact='potd') - qs = TaggedItem.objects.get_by_model(Photo, potd_obj) - return render_to_response('photos/photo-of-the-day.html', {'object_list': qs,}) diff --git a/cron/sync_links.py b/cron/sync_links.py index d622bbb..51422ce 100644 --- a/cron/sync_links.py +++ b/cron/sync_links.py @@ -3,13 +3,11 @@ from os.path import dirname, abspath PROJECT_ROOT = abspath(dirname(dirname(__file__))) - sys.path.append(PROJECT_ROOT) sys.path.append(PROJECT_ROOT+'/apps') sys.path.append(PROJECT_ROOT+'/lib') sys.path.append(PROJECT_ROOT+'/lib/utils') -sys.path.append('/home/luxagraf/webapps/django/lib/python2.6/') +sys.path.append('/home/luxagraf/webapps/django1_3/lib/python2.7/') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' - from links import retriever -retriever.sync_delicious_links()
\ No newline at end of file +retriever.sync_pinboard_links()
\ No newline at end of file diff --git a/cron/sync_photo_sets.py b/cron/sync_photo_sets.py index 9d3f754..8ce8bb5 100644 --- a/cron/sync_photo_sets.py +++ b/cron/sync_photo_sets.py @@ -7,7 +7,7 @@ sys.path.append(PROJECT_ROOT) sys.path.append(PROJECT_ROOT+'/apps') sys.path.append(PROJECT_ROOT+'/lib') sys.path.append(PROJECT_ROOT+'/lib/utils') -sys.path.append('/home/luxagraf/webapps/django/lib/python2.6/') +sys.path.append('/home/luxagraf/webapps/django1_3/lib/python2.7/') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from photos import retriever diff --git a/cron/sync_photos.py b/cron/sync_photos.py index 492a986..916057f 100644 --- a/cron/sync_photos.py +++ b/cron/sync_photos.py @@ -7,7 +7,7 @@ sys.path.append(PROJECT_ROOT) sys.path.append(PROJECT_ROOT+'/apps') sys.path.append(PROJECT_ROOT+'/lib') sys.path.append(PROJECT_ROOT+'/lib/utils') -sys.path.append('/home/luxagraf/webapps/django/lib/python2.6/') +sys.path.append('/home/luxagraf/webapps/django1_3/lib/python2.7/') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from photos import retriever diff --git a/settings.py b/settings.py index fd74df0..d076768 100644 --- a/settings.py +++ b/settings.py @@ -145,7 +145,8 @@ INSTALLED_APPS = ( 'locations', 'blog', 'photos', - 'tagging', + #'tagging', + 'taggit', 'chunks', 'links', 'pagination', diff --git a/templates/details/about.html b/templates/details/about.html index e2090d8..e5561c9 100644 --- a/templates/details/about.html +++ b/templates/details/about.html @@ -34,7 +34,7 @@ <section> <h2>Colophon</h2> <img src="{{IMAGES_URL}}colo.jpg" alt="me" /> - <div class="content">{%for object in object_list %}{%if forloop.counter = 1 %} + <div class="content">{%for object in object_list %}{%if forloop.counter = 2 %} {{object.content|smartypants|safe}}{%endif%} {% endfor %} </div> </section> |