summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/notes/models.py49
1 files changed, 33 insertions, 16 deletions
diff --git a/app/notes/models.py b/app/notes/models.py
index 464ea6c..dc158d2 100644
--- a/app/notes/models.py
+++ b/app/notes/models.py
@@ -42,6 +42,7 @@ class Note(models.Model):
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)
+ in_reply_to = models.CharField('in reply to url', max_length=450)
def __str__(self):
return self.slug
@@ -92,7 +93,7 @@ class Note(models.Model):
if not self.date_created:
self.date_created = datetime.datetime.now()
if not self.slug:
- self.slug = slugify(self.body_markdown)[:20]
+ self.slug = slugify(self.title)[:30]
if not self.twitter_text:
self.twitter_text = twitter_truncate(self.body_markdown)
super(Note, self).save()
@@ -100,21 +101,24 @@ class Note(models.Model):
@receiver(post_save, sender=Note)
def post_save_events(sender, instance, **kwargs):
- #if kwargs["created"]:
- try:
- l = Location.objects.filter(geometry__contains=instance.point).get()
- instance.location = l
- instance.city_name = l.name
- instance.state_name = l.state.name
- instance.country_name = l.state.country.name
- except Location.DoesNotExist:
- r_str = 'http://nominatim.openstreetmap.org/reverse?format=json&lat=%s&lon=%s&zoom=18' % (instance.latitude, instance.longitude)
- response = requests.get(r_str)
- data = json.loads(response.text)
- adr = data.get('address', {})
- instance.city_name = adr.get('hamlet') or adr.get('village') or adr.get('town') or adr.get('city')
- instance.state_name = adr.get('state')
- instance.country_name = adr.get('country')
+ if kwargs["created"]:
+ try:
+ l = Location.objects.filter(geometry__contains=instance.point).get()
+ instance.location = l
+ instance.city_name = l.name
+ instance.state_name = l.state.name
+ instance.country_name = l.state.country.name
+ except Location.DoesNotExist:
+ r_str = 'http://nominatim.openstreetmap.org/reverse?format=json&lat=%s&lon=%s&zoom=18' % (instance.latitude, instance.longitude)
+ response = requests.get(r_str)
+ data = json.loads(response.text)
+ adr = data.get('address', {})
+ instance.city_name = adr.get('hamlet') or adr.get('village') or adr.get('town') or adr.get('city')
+ instance.state_name = adr.get('state')
+ instance.country_name = adr.get('country')
+ if instance.in_reply_to:
+ #crawl url, extract text, store it locally with a reference to instance
+ pass
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")
@@ -132,3 +136,16 @@ def post_save_events(sender, instance, **kwargs):
def write_note(sender, instance, **kwargs):
if kwargs["created"]:
pass
+
+
+class OriginNoteForReplies(models.Model):
+ #created_at
+ date_created = models.DateTimeField()
+ #profile_image_url_https
+ profile_image = models.CharField(max_length=450, null=True, blank=True)
+ #screen_name
+ screen_name = models.CharField(max_length=75, null=True, blank=True)
+ #text
+ body_html = models.TextField(blank=True)
+ #url
+ remote_url = models.CharField(max_length=450, null=True, blank=True)