Beispiel #1
0
def tagged(request, tags_slug):
    categories = Category.objects.all()
    tag_category = Tag.objects.all()
    instance = Article.objects.all()

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    if tags_slug:
        tags = get_object_or_404(Tag, slug=tags_slug)
        instance_list = instance.filter(tags=tags)
        paginator = Paginator(instance_list, 10)
        page = request.GET.get('page')
        instance = paginator.get_page(page)

    context = {
        'categories': categories,
        'instance': instance,
        'tag': tags,
        'tag_category': tag_category,
        'sub': sub,
    }
    return render(request, 'blog/tag_list_view.html', context)
Beispiel #2
0
def detail(request, article_slug):
    instance = get_object_or_404(Article, slug=article_slug)
    categories = Category.objects.all()

    similar_posts = instance.tags.similar_objects()[:5]

    app_url = request.path

    initial_data = {
        'content_type': instance.get_content_type,
        'object_id': instance.id
    }
    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    form = CommentForm(request.POST or None, initial=initial_data)
    if form.is_valid():
        c_type = form.cleaned_data.get('content_type')
        content_type = ContentType.objects.get(model=c_type)
        obj_id = form.cleaned_data.get('object_id')
        content_data = form.cleaned_data.get('content')
        user_data = form.cleaned_data.get('user')
        email_data = form.cleaned_data.get('email')

        parent_obj = None
        try:
            parent_id = request.POST.get('parent_id')
        except:
            parent_id = None

        if parent_id:
            parent_qs = Comment.objects.filter(id=parent_id)
            if parent_qs.exists():
                parent_obj = parent_qs.first()

        new_comment, created = Comment.objects.get_or_create(
            user=user_data,
            email=email_data,
            content_type=content_type,
            object_id=obj_id,
            content=content_data,
        )
        messages.success(request, 'Comment added successfully!!')

    comments = instance.comments
    context = {
        'title': instance.title,
        'instance': instance,
        'comments': comments,
        'comment_form': form,
        'app_url': app_url,
        'similar_posts': similar_posts,
        'categories': categories,
        'sub': sub,
    }
    return render(request, 'blog/detail_view.html', context)
Beispiel #3
0
def list_of_articles_by_category(request, category_slug):

    instance = Article.objects.all()
    categories = Category.objects.all()

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    if category_slug:
        category = get_object_or_404(Category, slug=category_slug)
        instance_list = instance.filter(category=category)
        paginator = Paginator(instance_list, 10)
        page = request.GET.get('page')
        instance = paginator.get_page(page)

    context = {
        'categories': categories,
        'instance': instance,
        'category': category,
        'sub': sub,
    }
    return render(request, 'blog/category_list.html', context)
Beispiel #4
0
def listing_search(request):
    qs = Listing.objects.order_by('company_name')
    categories = Category.objects.all()
    listing_categories = Category.objects.all()

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    Keywords = request.GET['Keywords']

    if 'Keywords' in request.GET:
        keywords = request.GET['Keywords']
        if keywords:
            qs = qs.filter(description__icontains=keywords)

    if 'country' in request.GET:
        country = request.GET['country']
        if country:
            qs = qs.filter(country__iexact=country)

    content = {
        'instance': qs,
        'country_choice': country_choice,
        'Keywords': Keywords,
        'categories': categories,
        'listing_categories': listing_categories,
        'sub': sub,
    }
    return render(request, 'listing/listing_search.html', content)
Beispiel #5
0
def listing_detail(request, listing_slug):
    instance = get_object_or_404(Listing, slug=listing_slug)
    categories = Category.objects.all()
    listing_categories = Category.objects.all()

    initial_data = {
        'content_type': instance.get_content_type,
        'object_id': instance.id
    }
    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')
    form = CommentForm(request.POST or None, initial=initial_data)
    if form.is_valid():
        c_type = form.cleaned_data.get('content_type')
        content_type = ContentType.objects.get(model=c_type)
        obj_id = form.cleaned_data.get('object_id')
        content_data = form.cleaned_data.get('content')
        user_data = form.cleaned_data.get('user')
        email_data = form.cleaned_data.get('email')

        parent_obj = None
        try:
            parent_id = request.POST.get('parent_id')
        except:
            parent_id = None

        if parent_id:
            parent_qs = Comment.objects.filter(id=parent_id)
            if parent_qs.exists():
                parent_obj = parent_qs.first()

        new_comment, created = Comment.objects.get_or_create(
            user=user_data,
            email=email_data,
            content_type=content_type,
            object_id=obj_id,
            content=content_data,
        )
        messages.success(request, 'Review added successfully!!')

    comments = instance.comments
    context = {
        'instance': instance,
        'comments': comments,
        'comment_form': form,
        'categories': categories,
        'sub': sub,
        'listing_categories': listing_categories,
    }
    return render(request, 'listing/business_detail.html', context)
Beispiel #6
0
def events(request):

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    content = {
        'sub': sub,
    }
    return render(request, 'blog/events.html', content)
Beispiel #7
0
def list_home(request):
    instance = Listing.objects.all()
    categories = Category.objects.all()

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    content = {
        'instance': instance,
        'country_choice': country_choice,
        'categories': categories,
        'sub': sub,
    }
    return render(request, 'listing/listing_home.html', content)
Beispiel #8
0
def search(request):
    categories = Category.objects.all()
    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')
    if request.GET:
        search_term = request.GET['search_term']
        search_result = Article.objects.filter(Q(title__icontains=search_term))
        content = {
            'search_term': search_term,
            'instance': search_result,
            'categories': categories,
            'sub': sub,
        }
        return render(request, 'blog/search.html', content)
    else:
        return redirect('home')
Beispiel #9
0
def Articles_list(request):
    instance_list = Article.objects.all()
    categories = Category.objects.all()

    paginator = Paginator(instance_list, 10)
    page = request.GET.get('page')
    instance = paginator.get_page(page)

    sub = SubscribeForm(request.POST)
    if sub.is_valid():
        email_data = sub.cleaned_data.get('S_email')
        new_comment, created = Subscribe.objects.get_or_create(
            S_email=email_data, )
        messages.success(request, 'You have subscribed successfully!!')

    content = {
        'instance': instance,
        'categories': categories,
        'sub': sub,
    }
    return render(request, 'blog/article_list.html', content)
Beispiel #10
0
def add_subscriber(request):

    if request.method == 'POST':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            subscribe = form.save()
            subscribe.save()
            return redirect('houses:home')
    else:
        form = SubscribeForm()
        return render(request, 'houses/faqs.html', {'form': form})