Ejemplo n.º 1
0
	def get(self, id=None, page=0, json=None):
		offset = 0
		p = 0
		if page:
			offset = 10*int(page)
			p = page
		template_values = {}
		if not id:
			competition = Competition.all().order("-dateCreated").get()
		else:
			competition = Competition.get_by_id(int(id))
		photo = competition.photoKey # get photo instance
		showPagination = False
		captions = Caption.all().filter('competitionKey =',competition).filter('approved =',True).fetch(limit=100)
		if len(captions) == 11:
			showPagination = True
			p = p+1
			captions.pop(10)
	
		if json == 'json':
			caps = []
			for c in captions:
				caps.append({'text' : "%s" % c.text,
				"author" : "%s" % c.author,
				"comp" : "%s" % c.competitionKey,
				"caption" : "%s" % c.key().id(),
				"dateCreated" : "%s" % c.dateCreated})
			self.response.headers['Content-Type'] = "application/json"
			self.response.out.write(simplejson.dumps([caps, showPagination, p]))
		else:
			caps = []
			for c in captions:
				caps.append({'text' : c.text,
				"author" : c.author,
				"comp" : c.competitionKey,
				"caption" : c.key().id(),
				"dateCreated" : c.dateCreated})
			template_values['img'] = "/photo/%s" % photo.key().id() # get id from photo instance, to pass later in URL
			template_values['title'] = photo.title
			template_values['description'] = photo.description
			template_values['competitionId'] = competition.key().id()
			template_values['complete'] = competition.complete
			template_values['captions'] = caps
			template_values['showPagination'] = showPagination
			template_values['page'] = p
			template_values['divWidth'] = len(captions) * 437
			path = os.path.join(os.path.dirname(__file__), 'templates/competition.html')
			self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
	def get(self, id=None):
		template_values = {}
		if id:
			captions = Caption.get_by_id(int(id))
			template_values['caption'] = captions
			template_values['comp'] = captions.competitionKey.photoKey
			template_values['photoId'] = captions.competitionKey.photoKey.key().id()
			template_values['id'] = id
			template_values['author'] = captions.author	
			path = os.path.join(os.path.dirname(__file__), 'templates/caption.html')
			self.response.out.write(template.render(path, template_values))
		else:
			captions = Caption.all().order("-dateCreated").fetch(limit=100)
			caps = []
			for c in captions:
				caps.append({'text' : c.text,
				'author' : c.author,
				'comp' : c.competitionKey,
				'caption' : c.key().id(),
				'dateCreated' : c.dateCreated})
			template_values['captions'] = caps
			path = os.path.join(os.path.dirname(__file__), 'templates/captions.html')
			self.response.out.write(template.render(path, template_values))