def toEntry(self, video): e = Entry() if video.title != None: e.title = video.title.text.decode('UTF-8') if video.content != None: if video.media.content != None: e.text = '<div class="video">' + self.getFlashPlayerHTML( video.media.content[0].url ) + '</div>' if video.content.text != None: e.text += video.content.text.decode('UTF-8') e.source = self.source_id e.external_id = video.id.text e.created = parse( video.published.text ) e.url = video.link[0].href if video.media.keywords != None: # split the tags e.tags = video.media.keywords.text.decode('UTF-8').replace(' ','').split(',') # save the location data if available if video.geo: e.lat = str(video.geo.latitude()) e.lng = str(video.geo.longitude()) return e
def toEntry(self, post): e = Entry() e.external_id = post['hash'] e.url = post['href'] e.title = post['description'] e.text = post['extended'] e.source = self.source_id e.created = parse( post['time'] ) # this is a bit weird but for some reason, the list of tags from post['tags'] will # report at least one element even if it's empty, so we need to protect against that e.tags = [] if len(post['tags'][0]) == 0 else post['tags'] return e
def post(self): form = EntryForm( self.request.POST ) if form.is_valid(): # validation successful, we can save the data e = Entry() print(form.clean_data) e.title = form.clean_data['title'] e.text = form.clean_data['text'] e.tags = form.clean_data['tags'].split(' ') e.lat = form.clean_data['lat'] e.lng = form.clean_data['lng'] e.source = 'blog' e.put() # redirect to the main page self.redirect( '/' ) else: # form not valid, must show again with the errors self.writeResponse( 'new_blog_post.html', { 'form': form.render() } )
def _addNewEntry(self, form): if form.is_valid(): # validation successful, we can save the data e = Entry() e.title = form.clean_data['title'] e.text = form.clean_data['text'] e.tags = form.clean_data['tags'].split(' ') e.lat = form.clean_data['lat'] if e.lat == "": e.lat = None e.lng = form.clean_data['lng'] if e.lng == "": e.lng = None e.source = 'blog' e.put() e = Entry.get(e.key()) # reset the data cache since there's new content from google.appengine.api import memcache memcache.flush_all() # return successful creation view_data = { 'message': 'New blog entry added successfully. <a href="%s">Link to the entry</a>.' % e.permalink(), 'error': False, 'entry_link': e.permalink(), 'entry': e } self.writeResponse(view_data) else: # form not valid, must show again with the errors data = { 'error': True, 'errors': {}} # (the Form object is actually iterable) for field in form: if field.errors: data['errors'][field.name] = field.errors self.writeResponse(data)
def toEntry(self, status): from app.utils import StringHelper e = Entry(external_id=str(status['id']), source = self.source_id, text = Utils.links_to_anchors(Utils.twitpic_to_img(status['text'])), title = StringHelper().remove_new_lines(status['text']), url='http://twitter.com/' + str(status['user']['screen_name']) + '/statuses/' + str(status['id'])) e.created = parse(status['created_at']) # extract the tags e.tags = StringHelper().extract_twitter_tags(status['text']) # process the location coordinates if they're available if status['coordinates'] != None: e.lat = str(status['coordinates']['coordinates'][1]) e.lng = str(status['coordinates']['coordinates'][0]) # is this entry a reply-to? logging.debug(e.text[0]) e.twitter_reply = (e.text[0] == '@') return(e)