Esempio n. 1
0
 def utx():
   user = PMMUser.get(recipe.parent_key())
   user.rec_pub -= 1
   if user.rec_pub < 0:
     user.rec_pub = 0
   user.put()
   cache_delete('gfcu', recipe.parent_key().name())
Esempio 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,
  })
Esempio n. 3
0
 def utx():
   user = PMMUser.get(self.request.user.key())
   user.rec_pub -= 1
   if user.rec_pub < 0:
     user.rec_pub = 0
   user.put()
   cache_delete('gfcu', self.request.user.key().name())
Esempio n. 4
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,
    })
Esempio n. 5
0
def atom_feed(request):
  feed = AtomFeed(u"Najnowsze przepisy diety Montignac", feed_url=request.url,
                  url=request.host_url,
                  subtitle=u"Lista 20 najnowszych przepisów publicznych dodanych przez użytkowników witryny.")

  recipes = models.Recipe.all().filter('rec_vis =', VISIBILITY[2]).filter('disabled =', False).order('-created').fetch(20)

  # 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:
      recipe.author = 'Nieznany'

  for post in recipes:
    body = post.recipe_html + u'<p><i>Proporcje składników znajdziesz na witrynie...</i></p>'
    feed.add(post.title, body, content_type='html',
            author=post.author, url=post.get_url(True), category=post.category,
            updated=post.updated, published=post.created)
  return feed.get_response()
Esempio n. 6
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(),
  })
  
Esempio n. 7
0
def disabled_list(request):  
  prev, recipes, next = PagerQuery(models.Recipe) \
    .filter('disabled =', True) \
    .order('-updated') \
    .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/disabled_list.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
    })
  else:
    return render_to_response('przepisy/disabled_list.html', {
      'recipes': recipes,
      'prev': prev,
      'next': next,
    })
Esempio n. 8
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,
    })