Beispiel #1
0
def index(request, tag_name=None, title_recipes="Latest recipes"):
    """Main entry point for the recipes. Show all recipe using pagination

    Keyword arguments:
    tag_name  --  If tag_name is not None then showing recipe by tag

    """
    title = ".:: BSNUX - Arturo Fernandez  ::."
    # To calculate max. links for pagination
    PAGES_LINK_COUNT = 5
    # Number of items per page
    ITEMS_PER_PAGE = 4
    # Activating tab
    blo_active = True
    # Template
    template = 'recipes/index.html'

    latest_recipe_list_all = None
    # If tag was sended then getting all recipes by tag
    if tag_name:
        latest_recipe_list_all = Tag.objects.get(name=tag_name).recipe_set.all().order_by('-created_at')
    else:
        latest_recipe_list_all = Recipe.objects.all().order_by('-created_at')

    arr_pages, latest_recipe_list = _get_paginated_list(latest_recipe_list_all, ITEMS_PER_PAGE, PAGES_LINK_COUNT, request.GET.get('p', '1'))

    tag = Tag()

    # Getting latest tweets
    tweets = None
    try:
        page = urllib.urlopen('https://api.twitter.com/1/statuses/user_timeline.json?screen_name=bsnux&count={0}'.format(settings.N_TWEETS)).read()
        #page = urllib.urlopen("http://twitter.com/status/user_timeline/bsnux.json?count=%d" % settings.N_TWEETS).read()
        tweets = simplejson.loads(page)
    except:
        tweets = None

    # Variables for the template and rendering
    dict_vars = { 'latest_recipe_list': latest_recipe_list,
                  'arr_pages': arr_pages,
                  'tag_cloud': tag.get_tag_cloud(),
                  'title': title,
                  'blo_active': blo_active,
                  'title_head': title_recipes,
                  'tweets': tweets,
                }
    return render_to_response(template, dict_vars,
                              context_instance=RequestContext(request))
Beispiel #2
0
def search(request):
    """Searching recipes"""
    title = ".:: BSNUX - Arturo Fernandez - Searching Recipes ::. "
    template = 'recipes/search_result.html'
    blo_active = True

    tag = Tag()

    qs = request.GET.get("q", "")
    res = Recipe.search.query(qs)

    dict_vars = { 'res': res,
                  'title': title,
                  'qs': qs,
                  'tag_cloud': tag.get_tag_cloud(),
                }
    return render_to_response(template, dict_vars,
                              context_instance=RequestContext(request))
Beispiel #3
0
def recipe(request, slug):
    """Showing a specific recipe

       Keyword arguments:
       recipe_id   -- ID for this recipe
       permalink -- permalink for this recipe

    """
    title = ".:: BSNUX - Arturo Fernandez - Recipes. "
    template = 'recipes/recipe.html'
    blo_active = True

    recipe = Recipe.objects.get(slug=slug)
    title += recipe.title + '::.'
    tag = Tag()

    dict_vars = { 'recipe': recipe,
                  'title': title,
                  'blo_active': blo_active,
                  'tag_cloud': tag.get_tag_cloud(),
                }
    return render_to_response(template, dict_vars,
                              context_instance=RequestContext(request))