summaryrefslogtreecommitdiff
path: root/app/notes/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-06-05 17:01:51 +0000
committerluxagraf <sng@luxagraf.net>2014-06-05 17:01:51 +0000
commit1c2c28270911dbd2e5fbf106edcce6cc5f053101 (patch)
tree7ef81eb54d58fd1df89aeab3c0393b64e9a8407b /app/notes/models.py
parente7e75fb45f3ac068872f04eaf91dbf0ced11959a (diff)
fixed some bugs in notes app and added check for twitter submit
Diffstat (limited to 'app/notes/models.py')
-rw-r--r--app/notes/models.py25
1 files changed, 19 insertions, 6 deletions
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