示例#1
0
	def toEntry(self, pictures):
		# and now create the entry
		c = Config()
		e = Entry(source = self.source_id,
			url = "http://picasaweb.google.com/" + c.getKey('picasa_user'))
		
		# define whether we show a matrix with pictures (in case we've got more than one) or just a bigger thumbnail)
		if(len(pictures) > 1):
			html = "<div class=\"picasa-entry\">"
			html += "<ul class=\"picasa-entry-ul\">"
			#for pic in pictures:
			#	html += self.pictureHTML(pic, True)
			html += "".join(map(lambda e: self.pictureHTML(e, True), pictures))				
			html += "</ul></div>"

			e.text = html			
			e.title = "%s new photos (%s)" % (str(len(pictures)), self._getTodayDate())
		else:
			pic = pictures.pop()
			# only one picture, we can show a bigger version of the picture
			# the markup uses different CSS classes so that we can control the styling separately
			e.title = "New photo upload (%s)" % (self._getTodayDate())
			e.text = "<div class=\"picasa-single-entry\">" + self.pictureHTML(pic, False) + "</div>"
					
		return e
示例#2
0
	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
示例#3
0
	def toEntry(self, item):
		e = Entry()
		e.title = item.title
		e.url = item.link
		e.created = parse(item.published)
		e.source = self.source_id
		e.external_id = item.id
		# if there's an annotation, let's use it as the body for the post
		if 'content' in item:
			if len(item.content) > 1:
				e.text = item.content[1].value
		
		return e
示例#4
0
 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
示例#5
0
 def toEntry(self, item):
     e = Entry()
     e.external_id = item.id 
     e.created = item.created_time
     e.source = self.source_id
     e.url = item.link
     e.title = item.caption.text
     e.text = self.makeInstagramText(item)
     
     # save the location data in case it's got any
     if 'location' in dir(item):
         e.lat = "%.15f" % item.location.point.latitude
         e.lng = "%.15f" % item.location.point.longitude
         e.location_name = item.location.name
     
     return e
示例#6
0
	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() } )
示例#7
0
	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)