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, })
def user(request, id): user = get_cached_user(id) if not user: return NotFound() if not user.active: return render_to_response('gfcaccount/private.html', {'active': False}) if (user.pro_vis == VISIBILITY[0] and request.user.key().name() != id) or (user.pro_vis == VISIBILITY[1] and not is_my_friend(request.user.key().name(), id)): return render_to_response('gfcaccount/private.html', {'active': True}) # pobierz przepisy użytkownika prev, recipes, next = PagerQuery(models.Recipe) \ .ancestor(user) \ .filter('disabled =', False) \ .filter('rec_vis =', VISIBILITY[2]) \ .order('-created') \ .fetch(settings.PAGE_SIZE, request.args.get('b', None)) if request.is_xhr: return render_to_response('przepisy/includes/public_list.html', { 'recipes': recipes, 'prev': prev, 'next': next, 'user_id': id, }) else: return render_to_response('gfcaccount/public.html', { 'recipes': recipes, 'prev': prev, 'next': next, 'user_id': id, 'info': { 'name': user.display_name, 'public_recipes': user.rec_pub, 'join_date': format_date(user.created, format='long', locale='pl'), 'thumbnail': user.thumbnail_url, } })