Ejemplo n.º 1
0
def my_list(request, ordering='popularne'):
  if ordering not in ORDERINGS.keys():
    return NotFound()
  
  prev, recipes, next = PagerQuery(models.Recipe) \
    .ancestor(request.user) \
    .filter('disabled =', False) \
    .order(ORDERINGS[ordering]) \
    .fetch(settings.PAGE_SIZE, request.args.get('b', None))
  
  if request.is_xhr:
    return render_to_response('przepisy/includes/my_list.html', {
      'recipes': recipes,
      'prev': prev,
      'ordering': ordering,
      'next': next,
    })
  else:
    return render_to_response('przepisy/my_list.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
      'ordering': ordering,
      'fav_recipes': models.Favs.get_list(request.user.key()),
    })
Ejemplo n.º 2
0
def list(request, ordering='popularne'):
  if ordering not in ORDERINGS.keys():
    return NotFound()
  
  prev, recipes, next = PagerQuery(models.Recipe) \
    .filter('rec_vis =', VISIBILITY[2]) \
    .filter('disabled =', False) \
    .order(ORDERINGS[ordering]) \
    .fetch(settings.PAGE_SIZE, request.args.get('b', None))
  
  # Get authors, TODO: OPTIMIZE
  authors = PMMUser.get([recipe.parent_key() for recipe in recipes])
  for i, recipe in enumerate(recipes):
    if recipe and authors[i]:
      recipe.author = authors[i]
  
  if request.is_xhr:
    template = 'przepisy/includes/list.html'
  else:
    template = 'przepisy/list.html'
  
  return render_to_response(template, {
    'recipes': recipes,
    'prev': prev,
    'ordering': ordering,
    'next': next,
  })
Ejemplo n.º 3
0
def category(request, slug, ordering='popularne'):
  if slug in models.CATEGORIES_SV.keys():
    category = get_by_key_name_or_404(models.Category, models.CATEGORIES_SV[slug])
  else:
    return NotFound()
  
  if ordering not in ORDERINGS.keys():
    return NotFound()
  
  if category.counter == 0:
    prev, recipes, next = None, [], None
  else:
    prev, recipes, next = PagerQuery(models.Recipe) \
      .filter('rec_vis =', VISIBILITY[2]) \
      .filter('disabled =', False) \
      .filter('category =', slug) \
      .order(ORDERINGS[ordering]) \
      .fetch(settings.PAGE_SIZE, request.args.get('b', None))
  
    # Get authors, TODO: OPTIMIZE
    authors = PMMUser.get([recipe.parent_key() for recipe in recipes])
    for i, recipe in enumerate(recipes):
      if recipe and authors[i]:
        recipe.author = authors[i]
  
  if request.is_xhr:
    return render_to_response('przepisy/includes/category_list.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
      'ordering': ordering,
      'category_slug': slug
    })
  else:
    categories = [c for c in models.Category.get_for_lists() if c['name'] != category.key().name()]
    return render_to_response('przepisy/category.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
      'ordering': ordering,
      'category_slug': slug,
      'category': category.key().name(),
      'categories': categories,
    })
Ejemplo n.º 4
0
def friend_list(request, ordering='popularne'):
  if ordering not in ORDERINGS.keys():
    return NotFound()
  
  friends = get_cached_friends(request.user.key().name())
  
  if friends:
    prev, recipes, next = PagerQuery(models.RecipeFriends) \
      .filter('friends =', request.user.key().name()) \
      .order(ORDERINGS[ordering]) \
      .fetch(settings.PAGE_SIZE, request.args.get('b', None))
    
    recipes = models.Recipe.get([recipe.parent_key() for recipe in recipes])
  
    # Get authors, TODO: OPTIMIZE
    authors = PMMUser.get([recipe.parent_key() for recipe in recipes])
    for i, recipe in enumerate(recipes):
      if recipe and authors[i]:
        recipe.author = authors[i]
  else:
    prev, recipes, next = None, [], None
      
  
  if request.is_xhr:
    template = 'przepisy/includes/friend_list.html'
  else:
    template = 'przepisy/friend_list.html'
  
  return render_to_response(template, {
    'recipes': recipes,
    'prev': prev,
    'ordering': ordering,
    'next': next,
    'friends': friends.values(),
  })
  
Ejemplo n.º 5
0
def search(request, ordering='popularne'):
  query = request.args.get('q', '').strip()
  page = request.args.get('p', 1, type=int)
  if page < 1:
    page = 1
  order = request.args.get('o', '')
  if order != '' and order not in ORDERINGS.keys():
    order = ''
  exact = request.args.get('e', '1')
  if exact not in ('0', '1'):
    exact = '1'
  advanced = request.args.get('a', '0')
  if advanced not in ('0', '1'):
    advanced = '0'

  recipes = models.Recipe.search(query, 201, order=ORDERINGS[order] if order else None, exact=True if exact == '1' else False)
  is_more = len(recipes) > 200
  if is_more:
    recipes = recipes[:200]
  
  # Przygotuj urle
  if page != 1:
    prev = url_for('przepisy/search', q=query, p=page-1, o=order, e=exact, a=advanced)
  else:
    prev = None
  
  pages = int(math.ceil(len(recipes)/float(settings.PAGE_SIZE)))
  if pages != page and pages > 1:
    next = url_for('przepisy/search', q=query, p=page+1, o=order, e=exact, a=advanced)
  else:
    next = None
  
  # Końcowa lista przepisów, po przycięciu
  if pages > 1:
    recipes = recipes[settings.PAGE_SIZE*(page-1):settings.PAGE_SIZE*page]
  recipes = models.Recipe.get(recipes)
  recipes = [recipe for recipe in recipes if recipe is not None]
  
  # Get authors, TODO: OPTIMIZE
  authors = PMMUser.get([recipe.parent_key() for recipe in recipes])
  for i, recipe in enumerate(recipes):
    if recipe and authors[i]:
      recipe.author = authors[i]
  
  if request.is_xhr:
    return render_to_response('przepisy/includes/search_list.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
    })
  else:
    pop_recipes = models.Recipe.all() \
      .filter('rec_vis =', VISIBILITY[2]) \
      .filter('disabled =', False) \
      .order('-views') \
      .fetch(20)
    
    return render_to_response('przepisy/search.html', {
      'recipes': recipes,
      'prev': prev,
      'order': order,
      'page': page,
      'exact': exact,
      'advanced': advanced,
      'query': query,
      'squery': query,
      'next': next,
      'is_more': is_more,
      'pop_recipes': pop_recipes,
    })