Exemplo n.º 1
0
 def init(self, key):
   self.recipe = get_or_404(models.Recipe, key)
   if self.recipe.disabled:
     return NotFound()
     
   if not (self.request.user.is_admin or self.request.user.key() == self.recipe.parent_key()):
     return Unauthorized()
   
   self.ingredients = models.RecipeIngr.all().ancestor(self.recipe).order('__key__').fetch(20)
   
   initial = {}
   initial['title'] = self.recipe.title
   initial['recipe'] = self.recipe.recipe
   initial['tags'] = ', '.join(self.recipe.tags)
   initial['category'] = self.recipe.category
   initial['phase'] = self.recipe.phase
   initial['type'] = self.recipe.type
   initial['ig'] = self.recipe.ig
   initial['time'] = self.recipe.time
   initial['rec_vis'] = self.recipe.rec_vis
   initial['ingr'] = [{
     'product': i.product,
     'portion': i.portion,
     'weight': i.weight
     } for i in self.ingredients]
   self.form = RecipeForm(initial, edit=True)
   if self.recipe.rec_vis == VISIBILITY[1]:
     self.form.rec_vis.choices = [VISIBILITY[1], VISIBILITY[2]]
   if self.recipe.rec_vis == VISIBILITY[2]:
     self.form.rec_vis.choices = [VISIBILITY[2]]
Exemplo n.º 2
0
 def update_task(cls, key, data={}):
     task = get_or_404(cls, key)
     for key, val in data.iteritems():
         if hasattr(task, key):
             setattr(task, key, val)
     task.put()
     return task
Exemplo n.º 3
0
def task_detail(request, key):
    if request.method == "DELETE":
        Task.delete_task(key)
        return Response(key)

    if request.method == "PUT":
        model_dict = simplejson.load(request.stream)
        task = Task.update_task(key, model_dict)
    else:
        task = get_or_404(Task, key)
    return render_json_response(task.to_dict())
Exemplo n.º 4
0
def view(request, author, slug):
  recipe = get_or_404(models.Recipe, db.Key.from_path('PMMUser', author, 'Recipe', slug))
  if recipe.disabled:
    return NotFound()

  similar = models.Recipe.search(recipe.title, limit=10, order='-created')
  if recipe.key() in similar:
    similar.remove(recipe.key())
  similar = db.get(similar)

  is_author = False
  if request.user.is_authenticated() and request.user.is_admin:
    is_admin = True
  else:
    is_admin = False
  
  if request.user.is_authenticated() and author == request.user.key().name():
    show = True
    is_author = True
  elif recipe.rec_vis == VISIBILITY[0] and (request.user.is_anonymous() or author != request.user.key().name()):
    show = False  
  elif recipe.rec_vis == VISIBILITY[1] and (request.user.is_anonymous() or not is_my_friend(request.user.key().name(), author)):
    show = False
  else:
    show = True
  
  if show:
    ingredients = models.RecipeIngr.all().ancestor(recipe).order('__key__').fetch(20)
    
    if request.user.is_authenticated():
      is_a_fave = models.Favs.is_a_fave(request.user.key(), recipe.key())
    else:
      is_a_fave = False
      
    return render_to_response('przepisy/view.html', {
      'recipe': recipe,
      'ingredients': ingredients,
      'similar': similar,
      'is_a_fave': is_a_fave,
      'is_author': is_author,
      'is_admin': is_admin,
    })
  else:
    return render_to_response('przepisy/view_private.html', {
      'recipe': recipe,
      'similar': similar,
      'private': recipe.rec_vis == VISIBILITY[0],
      'is_admin': is_admin,
    })
Exemplo n.º 5
0
 def delete_task(cls, key):
     task = get_or_404(cls, key)
     task.delete()
     return task