def save(self, user, story): if self.cleaned_data['id']: post = StoryLineItem.objects.get(pk=self.cleaned_data['id']) post.text = self.cleaned_data['text'] else: post = StoryLineItem(text=self.cleaned_data['text'], creator=user, story=story) post.save() if self.cleaned_data['lng'] and self.cleaned_data['lat']: location = Point(float(self.cleaned_data['lng']), float(self.cleaned_data['lat'])) pointTag = GeoPointTag(content_object=post, location=location, creator=user) pointTag.save() # add medias if self.cleaned_data["medias"]: media_uids = self.cleaned_data["medias"].split(",") for media_uid in media_uids: media = get_target_object(media_uid.strip()) storylineitem = StoryLineItemMedia(storylineitem=post, content_object=media) storylineitem.save() return post
def save(self, user, story): logging.debug("Adding Post to Experience") if self.cleaned_data['id']: post = StoryLineItem.objects.get(pk=self.cleaned_data['id']) post.text = self.cleaned_data['text'] else: post = StoryLineItem(text=self.cleaned_data['text'], creator=user, story=story) post.save() if self.cleaned_data['lng'] and self.cleaned_data['lat']: location = Point(float(self.cleaned_data['lng']), float(self.cleaned_data['lat'])) pointTag = GeoPointTag(content_object=post, location=location, creator=user) pointTag.save() # add medias if self.cleaned_data["image"]: logging.debug("Adding Post With Image") title = "IPhone - %s"%self.cleaned_data["timestamp"] image = Image(title=title) image.image.save(os.path.basename(story.title+"-"+title), ContentFile(self.cleaned_data["image"].read())) image.save() storylineAttachment = StoryLineItemMedia(storylineitem=post, content_object=image) storylineAttachment.save() logging.debug("Finished Saving Image") return post
def store_user(data): # # User # firstname = data['firstname'] if not firstname: firstname = " " lastname = data['lastname'] if not lastname: lastname = " " user = User(username=data['name'], first_name=firstname, last_name=lastname, email=data['email'], password="******"+data["pass"]) user.save(force_insert=True) print "User: "******" " #profile = Profile(user=user, # first_name=firstname, # last_name=lastname, # city=city, # about=data['description']) #profile.save() #account = Account(user=user) #account.save() # avatar # # stories - do them first, since they are containers that we want to add items to # stories = get_stories(data["user_id"]) for story in stories: print "-Story: "+str(story['story_id']) title = story['title'] if not title: title = " " new_story = Story(title=title, slug=slugify(title), creator=user, description=story['text'], mapmode=convert_mapmode(story['mapmode']), creation_date=convert_time(story['timestamp']), update_date=convert_time(story['timestamp']), privacy=get_privacy_of_old_privacy(story['right_view']), status=get_status_of_old_privacy(story['right_view'])) new_story.slug = make_unique(new_story, lambda x: Story.objects.filter(slug__exact=x.slug).count() == 0) new_story.save() migrated_post = MigratedItem(type="story", old_id=story["story_id"], new_id=new_story.pk) migrated_post.save() store_tags_of_item(new_story, story['story_id']) set_hit_count(new_story, story['view_count']) # lines lines = get_lines(data["user_id"]) if lines: for line in lines: print "-Line: "+str(line['line_id']) linestring = make_linestring_of_string(line["controlpoints"], line["start_marker_id"], line["end_marker_id"]) if linestring: line_post = get_post_of_line(line['line_id']) if not line_post: title = " " description = " " else: if line_post['title']: title = line_post['title'] else: title = " " if line_post['text']: description = line_post['text'] else: description = " " new_line = GeoLineTag(creator=user, title=title, description=description, line=linestring, ) # add to story line_w_story = get_story_of_line(line['line_id']) if line_w_story and line_w_story['story_id']: try: new_story = Story.objects.get(pk=get_new_id("story",line_w_story['story_id'])) print "Adding line %s (%s) to story %s (%s)"%(line['line_id'], new_line.id, line_w_story['story_id'], new_story.id) new_line.content_object = new_story except: print "Could not add Story" new_line.save() migrated_line = MigratedItem(type="line", old_id=line["line_id"], new_id=new_line.pk) migrated_line.save() # video videos = get_videos(data["user_id"]) for video in videos: print "-Video: "+str(video['video_id']) if video['medialocation']: import re video_id = re.findall(r"/v/(.+)", video['medialocation'])[0] import_url = "http://www.youtube.com/watch?v="+video_id comment = video['text'] if not comment: comment = " " new_video = Video(creator=user, title=video['title'], comment=comment, was_uploaded=False, import_url=import_url, thumbnail_url=video['thumb1'], safetylevel=get_privacy_of_old_privacy(video['right_view']), last_modified=convert_time(video['timestamp']), date_added=convert_time(video['timestamp']), ) new_video.save() migrated_video = MigratedItem(type="video", old_id=video["video_id"], new_id=new_video.pk) migrated_video.save() # add to story if video["story_id"]: story = Story.objects.get(pk=get_new_id("story", video["story_id"])) count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(video['timestamp'])).count() print "Adding video %s (%s) to story %s (%s) at position: %s "%(video['video_id'], new_video.id, video["story_id"], story.id, count) text = video['text'] if not text: text = " " story_line_item = StoryLineItem(creator=user, story=story, text=text, timestamp_start=convert_time(video['timestamp']), timestamp_end=convert_time(video['timestamp'])) story_line_item.save() story_line_item_media = StoryLineItemMedia(storylineitem=story_line_item, content_object=new_video) story_line_item_media.save() # geotag if video['mapobject_id']: geotag_item(video["video_id"], story_line_item, user) if video['mapobject_id']: geotag_item(video["video_id"], new_video, user) store_tags_of_item(new_video, video["video_id"]) set_hit_count(new_video, video['view_count']) # posts posts = get_posts(data["user_id"]) for post in posts: print "-Post: "+str(post['post_id']) if post['story_id']: post_text = post['text'] if not post_text: post_text = " " try: post_story = Story.objects.get(pk=get_new_id("story", post['story_id'])) count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(post['timestamp'])).count() print "Adding post %s to story %s (%s) at position: %s "%(post['post_id'], post["story_id"], post_story.id, count) new_post = StoryLineItem(creator=user, story=post_story, text=post_text, timestamp_start=convert_time(post['timestamp']), timestamp_end=convert_time(post['timestamp'])) new_post.save() migrated_post = MigratedItem(type="post", old_id=post["post_id"], new_id=new_post.pk) migrated_post.save() if post['mapobject_id']: geotag_item(post["post_id"], new_post, user) store_tags_of_item(new_post, post["post_id"]) set_hit_count(new_post, post['view_count']) except: print "Could not add to Story" # images images = get_images(data["user_id"]) if images: for image in images: print "-Image: "+str(image['image_id']) caption = image['text'] if not caption: caption = " " title = image['title'] if not title: title = " " new_image = Image(member=user, title=title, caption=caption, date_added=convert_time(image['timestamp']), ) try: new_image.image.save(os.path.basename(image["filename"]+".jpg"), ContentFile(open(path_to_images+image["filename"]+".jpg", "r").read())) migrated_image = MigratedItem(type="image", old_id=image["image_id"], new_id=new_image.pk) new_image.save() migrated_image.save() if image["story_id"]: story = Story.objects.get(pk=get_new_id("story", image["story_id"])) count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(image['timestamp'])).count() print "Adding image %s (%s) to story %s (%s) at position: %s "%(image['image_id'], new_image.id, image["story_id"], story.id, count) story_line_item = StoryLineItem(creator=user, story=story, text=caption, position=count, timestamp_start=convert_time(image['timestamp']), timestamp_end=convert_time(image['timestamp'])) story_line_item.save() story_line_item_media = StoryLineItemMedia(storylineitem=story_line_item, content_object=new_image) story_line_item_media.save() if image['mapobject_id']: geotag_item(image['image_id'], story_line_item, user) if image['mapobject_id']: geotag_item(image['image_id'], new_image, user) store_tags_of_item(new_image, image["image_id"]) set_hit_count(new_image, image['view_count']) except: print "Could not store image: %s filename: %s"%(image['image_id'], image['filename']) # story image # store user migrated_user = MigratedItem(type="user", old_id=data["user_id"], new_id=user.pk) migrated_user.save() make_avatar(data) # flickr images # TODO: