"location_name": "{{self.location_name}}" }""") return t.render(c) def save(self, *args, **kwargs): super(Video, self).save(*args, **kwargs) if not VideoImage.objects.filter(video=self).all(): import urllib import os from django.core.files.base import ContentFile story_image = VideoImage(video=self) story_image.image.save(os.path.basename("video_thumb_"+str(self.id)), ContentFile(urllib.urlopen(self.thumbnail_url).read())) story_image.save() import geo geo.register(Video) def check_vimeo_status(sender, instance, **kwargs): from video.rest.vimeoPy import VimeoClient if not instance.is_viewable: vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) rsp = vimeoClient.call("vimeo.videos.checkUploadStatus", {"ticket_id": instance.ticket_id} ) if(rsp.attributes['stat'].value=="ok"): data = rsp.getElementsByTagName("ticket")[0] if data.attributes['is_uploading'].nodeValue=="0": if data.attributes['is_uploading'].nodeValue=="0": rsp = vimeoClient.call("vimeo.videos.getThumbnailUrl", {"video_id": instance.external_id, "size":"160x120"} ) thumbnail_url = rsp.getElementsByTagName("thumbnail")[0].childNodes[0].nodeValue instance.thumbnail_url = thumbnail_url instance.is_viewable = True instance.save()
"self": self, "position": self.position}) t = Template("""{"type": "{{type}}",\ "id": {{self.id}},\ "storyId": {{story.id}},\ "text": "{{self.text|linebreaksbr}}",\ "marker_image": "{{self.get_image.0.content_object.get_50x50_url}}",\ {% if self.has_location %}\ "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\ {% endif %}\ "position": {{position}} }""") return t.render(c) import geo geo.register(StoryLineItem) class StoryLineItemMedia(models.Model): storylineitem = models.ForeignKey(StoryLineItem, related_name='attachments', db_index=True) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() position = PositionField(collection='storylineitem') class Meta: # Enforce unique associations per object unique_together = (('content_type', 'object_id', 'storylineitem'),) ordering = ('position',) def __unicode__(self): return str(self.storylineitem)+" > "+str(self.content_object)+" > " + str(self.position)
"self": self}) t = Template("""{"type": "{{type}}",\ "id": "{{self.id}}",\ "title": "{{self.title}}",\ "caption": "{{self.caption}}",\ "date_added": "{{self.date_added|date}} ",\ "marker_image": "{{self.get_50x50_url}}",\ {% if self.has_location %}\ "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\ {% endif %}\ "location_name": "{{self.location_name}}" }""") return t.render(c) get_absolute_url = models.permalink(get_absolute_url) geo.register(Image) class Pool(models.Model): """ model for a photo to be applied to an object """ photo = models.ForeignKey(Image) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() created_at = models.DateTimeField(_('created_at'), default=datetime.now) class Meta: # Enforce unique associations per object
def get_geojson(self): c = Context({"type": get_model_name(self), "self": self, "STATIC_URL": settings.STATIC_URL}) t = Template("""{"type": "{{type}}",\ "id": "{{self.id}}",\ "title": "{{self.title}}",\ "body": "{{self.body}}",\ "publish": "{{self.publish|date}} ",\ "marker_image": "{{STATIC_URL}}/images/post-75-75.gif",\ "slug": "{{self.slug}}",\ {% if self.has_location %}\ "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\ {% endif %}\ "location_name": "{{self.location.location_name}}" }""") return t.render(c) import geo geo.register(Post) # handle notification of new comments from threadedcomments.models import ThreadedComment def new_comment(sender, instance, **kwargs): if isinstance(instance.content_object, Post): post = instance.content_object if notification: notification.send([post.author], "blog_post_comment", {"user": instance.user, "post": post, "comment": instance}) signals.post_save.connect(new_comment, sender=ThreadedComment)