Exemple #1
0
	def get(self, tag):
		user = User.is_logged(self)
		tag = helpers.sluglify(tag)
		tag = tag.replace('-', ' ')
		page = self.request.get_range('page', min_value=0, max_value=1000, default=0)
		title = "Explore %s" %(tag)
		subhead = "You can find hidden treasures."
		current = "explore"
  		tmp_kochs, next_page, prev_page = helpers.paginate( Koch.all().filter('tags =', tag).order('-created'), page ) 
		kochs = helpers.get_kochs_data(tmp_kochs)
		last_from_all = Koch.get_random()
		self.response.out.write(template.render('templates/list_kochs.html', locals()))
Exemple #2
0
	def post(self):
		user = User.is_logged(self)
		if not user:
			self.redirect('/')

		key 		= self.request.get('edit')
		tags        = [a.lower() for a in self.request.get_all('tags[]')]
		user        = user
		ingredients = self.request.get_all('ingredients[]')
		directions  = self.request.get_all('directions[]')
		tags        = tags
		name        = self.request.get('name')
		notes       = self.request.get('notes')
		prep        = self.request.get('prep_time')
		cook        = self.request.get('cook_time')
		level       = self.request.get('level')
		private     = True if self.request.get('private') == "1" else False
		slug        = helpers.sluglify( name )
		thumb       = None
		tinythumb   = None

		slug_exists = Koch.all().filter('slug =', slug).fetch(1)

		if len ( slug_exists ) == 1:
			#alreadyexists
			slug = "%s-%s" % (slug, helpers.random_string())

		if self.request.get('photo'):
			try:
				img_data = self.request.POST.get('photo').file.read()

				img = images.Image(img_data)
				img.im_feeling_lucky()
				png_data = img.execute_transforms(images.JPEG)
				img.resize(620,420)
				thumb = img.execute_transforms(images.JPEG)

				thmb = images.Image(img_data)
				thmb.im_feeling_lucky()
				png_data = thmb.execute_transforms(images.JPEG)
				thmb.resize(0, 80)
				tinythumb = thmb.execute_transforms(images.JPEG)				

			except images.BadImageError:
				pass
			except images.NotImageError:
				pass
			except images.LargeImageError:
				pass

		if key:
			koch       = Koch.get( key )
			koch.title = name 
		else:
			koch = Koch(slug=slug, title=name, author=user)
		
		koch.notes       = notes
		koch.prep_time   = prep
		koch.cook_time   = cook
		koch.level       = level
		koch.private     = private
		koch.tags        = tags
		koch.ingredients = ingredients
		koch.directions  = directions
					
		
		if thumb is not None:
			koch.photo = thumb
			koch.thumb = tinythumb
		
		for tag in tags:
			Tag.up(tag)

		if key:
			user.recipes += 1
			user.put() 
		
		koch.put()
		self.redirect('/cook/%s' % (user.nickname))