From 1c2c28270911dbd2e5fbf106edcce6cc5f053101 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 5 Jun 2014 17:01:51 +0000 Subject: fixed some bugs in notes app and added check for twitter submit --- app/notes/models.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'app/notes/models.py') 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 -- cgit v1.2.3-70-g09d2