def detail_post(request, post_slug):
    post = get_object_or_404(blog_models.Post, slug=post_slug)
    comments = blog_models.Comment.objects.filter(post=post.id, status=1, parent_id__isnull=True).order_by("created_date")
    images = general_models.Image.objects.filter(album=post.album)
    blog_filter_form = blog_forms.PostFilter()
    num_comments = len(blog_models.Comment.objects.filter(post=post.id, status=1))
    #related_posts = related_posts(post.title, post.category, post.tags, post.author)

    shoppingcart = shop_views.getShoppingCart(request.session)

    comment_form = getCommentForm(request)

    return render(request, "post_detail.html", {
        # 'comment_parent_id': 1,
        "post": post,
        "related_posts": related_posts(post_slug),
        "images": images,
        #"categories": getBlogCategories(),
        "comments":comments,
        "num_comments": num_comments,
        "comment_form": comment_form,
        #"answer_form": getCommentForm(request),
        'blog_filter_form': blog_filter_form,
        #'shoppingcart_form': getShoppingCart(),
        "search_form": general_views.getSearchForm(),
        'subscribe_form': general_views.getSubscribeForm(),
        'shoppingcart': shoppingcart,
    })
def nutrition(request):
    """
    View for nutrition section
    Search nutritional information
    """
    food_information = None

    nutrition_filter_form = getNutritionFilterForm(request)

    if nutrition_filter_form.is_valid():
        food_name = nutrition_filter_form.cleaned_data['name']
        print(food_name)
    else:
        food_name = None

    if food_name is not None:
        food_information = getNutritionixApiInformation(food_name)
        #food_information = json.loads(food_information)
        print(food_information)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'nutrition.html', {
            "search_form": general_views.getSearchForm(),
            'subscribe_form': general_views.getSubscribeForm(),
            'search_food_form': getNutritionFilterForm(request),
            'food_information': food_information,
            'shoppingcart': shoppingcart,
        })
def health(request):

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'health.html', {
            "search_form": general_views.getSearchForm(),
            'subscribe_form': general_views.getSubscribeForm(),
            'shoppingcart': shoppingcart,
        })
def category_posts(request, category):
    category = blog_models.Category.objects.get(slug=category)
    posts = blog_models.Post.objects.filter(status=1, category=category.id)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(request, 'post_list.html', {
        "posts":posts,
        "categories": getBlogCategories(),
        "search_form": general_views.getSearchForm(),
        'subscribe_form': general_views.getSubscribeForm(),
        'shoppingcart': shoppingcart,
    })
def author_posts(request, username):
    author = User.objects.get(username=username)
    posts = blog_models.Post.objects.filter(status=1, author=author.id)
    categories = blog_models.Category.objects.order_by("name")

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(request, 'post_list.html', {
        "posts":posts,
        "categories": getBlogCategories(),
        "search_form": general_views.getSearchForm(),
        'subscribe_form': general_views.getSubscribeForm(),
        'shoppingcart': shoppingcart,
    })
def tag_posts(request, tag_slug):
    print(tag_slug)
    tag = blog_models.Tag.objects.filter(slug=tag_slug)
    print(tag)
    posts = blog_models.Post.objects.filter(status=1, tags=tag)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(request, 'post_list.html', {
        "posts":posts,
        "categories": getBlogCategories(),
        "search_form": general_views.getSearchForm(),
        'subscribe_form': general_views.getSubscribeForm(),
        'shoppingcart': shoppingcart,
    })
Beispiel #7
0
def award_detail(request, award_slug):
    """
    View for award details
    """
    award = award_models.Award.objects.filter(slug=award_slug)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'award_detail.html', {
            'award': award,
            'awards_filter_form': getAwardsFilterForm(request),
            'subscribe_form': general_views.getSubscribeForm(),
            "search_form": general_views.getSearchForm(),
            'shoppingcart': shoppingcart,
        })
Beispiel #8
0
def awards(request):
    """
    """
    awards_filter_form = getAwardsFilterForm(request)
    awards = None

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'awards.html', {
            "search_form": general_views.getSearchForm(),
            'subscribe_form': general_views.getSubscribeForm(),
            'awards_filter_form': getAwardsFilterForm(request),
            'awards': awards,
            'shoppingcart': shoppingcart,
        })
def sport(request):
    """
    """
    sport_information = None
    sport_filter_form = getSportFilterForm(request)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'sport.html', {
            "search_form": general_views.getSearchForm(),
            'subscribe_form': general_views.getSubscribeForm(),
            'sport_filter_form': getSportFilterForm(request),
            'sport_information': sport_information,
            'shoppingcart': shoppingcart,
        })
Beispiel #10
0
def awards_profile(request, username):
    """
    View that returns the awards that a user has obtained
    """
    user = User.objects.filter(username=username)
    awards = award_models.Award.objects.filter(users=user)
    print("secion de premios del perfil")
    print(awards)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(
        request, 'awards_profile.html', {
            'awards': awards,
            "search_form": general_views.getSearchForm(),
            'subscribe_form': general_views.getSubscribeForm(),
            'shoppingcart': shoppingcart,
        })
def list_posts(request, blog_category_slug=None):

    category = None
    posts = blog_models.Post.objects.filter(status=1)
    # blog_filter_form = None

    if blog_category_slug:
        category = get_object_or_404(blog_models.Category, slug=blog_category_slug)
        post = posts.filter(category=category)

    if request.method == 'POST':
        blog_filter_form = blog_forms.PostFilter(request.POST)
        if blog_filter_form.is_valid():
            data = blog_filter_form.cleaned_data
            if data['title'] is not None:
                print(data['title'])
                posts = posts.filter(
                    Q(title__icontains=data["title"]) |
                    Q(description__icontains=data["title"]) |
                    Q(tags__name__icontains=data["title"]))
            if data['category'] is not None:
                print("categoria introducido")
                posts = posts.filter(category_id=data['category'].id)
            """
            if data['minimum_date'] is not None:
                print("fecha minima introducido")
                posts = posts.filter(created_date__gte=data['minimum_date'])
            if data['maximum_date'] is not None:
                print("fecha maxima introducido")
                posts = posts.filter(created_date__lte=data['maximum_date'])
            """
            if data['order_by'] == 1:
                print("ordenacion introducido")
                posts = posts.all().order_by('created_date')
                #posts = posts.all().order_by('-created_date')
        else:
            print(blog_filter_form.errors)

    else:
        blog_filter_form = blog_forms.PostFilter()

    posts = posts.all().order_by('-created_date')
    #print(posts)

    paginator = Paginator(posts, 12)
    page = request.GET.get('page')

    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)

    shoppingcart = shop_views.getShoppingCart(request.session)

    return render(request, "post_list.html", {
        'category': category,
        "posts": posts,
        #"categories": getBlogCategories(),
        'blog_filter_form': blog_filter_form,
        #'shoppingcart_form': getShoppingCart(),
        "search_form": general_views.getSearchForm(),
        'subscribe_form': general_views.getSubscribeForm(),
        'shoppingcart': shoppingcart,
    })