diff options
author | luxagraf <sng@luxagraf.net> | 2014-06-05 17:01:51 +0000 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2014-06-05 17:01:51 +0000 |
commit | 1c2c28270911dbd2e5fbf106edcce6cc5f053101 (patch) | |
tree | 7ef81eb54d58fd1df89aeab3c0393b64e9a8407b | |
parent | e7e75fb45f3ac068872f04eaf91dbf0ced11959a (diff) |
fixed some bugs in notes app and added check for twitter submit
-rw-r--r-- | app/notes/admin.py | 4 | ||||
-rw-r--r-- | app/notes/models.py | 25 |
2 files changed, 21 insertions, 8 deletions
diff --git a/app/notes/admin.py b/app/notes/admin.py index 8797a92..03b8b37 100644 --- a/app/notes/admin.py +++ b/app/notes/admin.py @@ -13,13 +13,13 @@ class NoteModelForm(forms.ModelForm): class NoteAdmin(OSMGeoAdmin): form = NoteModelForm - list_display = ('slug', 'date_created', 'location') + list_display = ('slug', 'date_created', 'location', 'twitter_id') list_filter = ('location',) fieldsets = ( ('Note', { 'fields': ( 'body_markdown', - 'slug', + ('twitter_send', 'slug'), 'point' ), 'classes': ( diff --git a/app/notes/models.py b/app/notes/models.py index 6ce912d..35680af 100644 --- a/app/notes/models.py +++ b/app/notes/models.py @@ -11,6 +11,11 @@ from twython import Twython # http://freewisdom.org/projects/python-markdown/ import markdown +def twitter_truncate(txt): + try: + return txt.split("|")[0] + except: + return txt class Note(models.Model): slug = models.SlugField(unique_for_date='date_created', blank=True) @@ -21,6 +26,8 @@ class Note(models.Model): body_html = models.TextField(blank=True) body_markdown = models.CharField('Note', max_length=450) twitter_id = models.CharField('twitter_id', max_length=450) + twitter_send = models.BooleanField("send to twitter?", default=False) + twitter_sent = models.BooleanField(default=False, blank=True) def __str__(self): return self.slug @@ -66,9 +73,15 @@ class Note(models.Model): @receiver(post_save, sender=Note) def post_save_events(sender, instance, **kwargs): - t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) - geo = t.reverse_geocode(lat=instance.latitude, lon=instance.longitude, accuracy=1500, granularity="city") - geo_id = geo['result']['places'][0]['id'] - status = t.update_status(status='Look, Twitter', place_id=geo_id) - instance.twitter_id = status['id'] - print(instance.twitter_id) + if instance.twitter_send and not instance.twitter_sent: + t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) + geo = t.reverse_geocode(lat=instance.latitude, lon=instance.longitude, accuracy=1500, granularity="city") + geo_id = geo['result']['places'][0]['id'] + status = t.update_status(status=instance.body_markdown, place_id=geo_id) + instance.twitter_id = status['id'] + instance.twitter_sent = True + instance.save() + +def write_note(sender, instance, **kwargs): + if created: + pass |