Esempio n. 1
0
def store(request, category_slug=None):
    categories = None
    products = None

    if category_slug != None:
        categories = get_object_or_404(Category, slug=category_slug)
        products = Product.objects.filter(category=categories,
                                          is_available=True)
        paginator = Paginator(products, 1)
        page = request.GET.get('page')
        paged_products = paginator.get_page(page)
        product_count = products.count()
    else:

        products = Product.objects.all().filter(
            is_available=True).order_by('id')
        paginator = Paginator(products, 3)
        page = request.GET.get('page')
        paged_products = paginator.get_page(page)
        product_count = products.count()

    context = {
        'products': paged_products,
        'product_count': product_count,
    }
    return render(request, 'store/store.html', context)
Esempio n. 2
0
def category(request, category_slug=None):

    category = None
    categories = Category.objects.all().annotate(posts_count=Count('posts'))
    posts = Post.objects.all()

    latest_post = Post.objects.all()[:3]

    paginator = Paginator(posts, 3)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)

    if category_slug:
        category = get_object_or_404(Category, slug=category_slug)
        posts = posts.filter(category=category)

        paginator = Paginator(posts, 3)
        page_number = request.GET.get('page')
        page_obj = paginator.get_page(page_number)

    context = {
        'posts': posts,
        'latest_post': latest_post,
        'category': category,
        'categories': categories,
        'page_obj': page_obj
    }

    return render(request, 'blog/category.html', context)
Esempio n. 3
0
def Essay_list(request):
    """
    글 목록 출력
    """
    # 입력 파라미터
    page = request.GET.get('page', '1')  # 페이지
    kw = request.GET.get('kw', '')  # 검색어

    # 조회
    # subject__contains=kw 대신 subject__icontains=kw을 사용하면 대소문자를 가리지 않고 찾아 준다.
    essay_list = Essay.objects.order_by('-create_date')
    if kw:
        essay_list = essay_list.filter(
            Q(subject__icontains=kw) |  # 제목검색
            Q(content__icontains=kw) |  # 내용검색
            Q(author__username__icontains=kw) |  # 질문 글쓴이검색
            Q(answer__author__username__icontains=kw)  # 답변 글쓴이검색
        ).distinct()

    # page = request.Get.get('page', '1')
    # essay_list = Essay.objects.order_by('-create_date')
    paginator = Paginator(essay_list, 10)
    page_obj = paginator.get_page(page)

    context = {'essay_list': page_obj, 'page': page, 'kw': kw}
    return render(request, 'pages/board/boardList.html', context)
Esempio n. 4
0
def busca(request):
    termo = request.GET.get('termo')

    if termo is None or not termo:
        messages.add_message(
            request,
            messages.ERROR,
            'Campo termo não pode ficar vazio'
        )
        return redirect('index')

    campos = Concat('nome', Value(' '), 'sobrenome')
    contatos = Contato.objects.annotate(
        nome_completo=campos
    ).filter(
        Q(nome_completo__icontains =termo)| Q(telefone__icontains=termo)
    )

    paginator = Paginator(contatos,20)
    page = request.GET.get('p')
    contatos = paginator.get_page(page)
    return render(request, 'contatos/busca.html',{
        'contatos': contatos

    })
Esempio n. 5
0
def Products(request):
	product = Allproduct.objects.all().order_by('id').reverse() #query data from all products by descending order
	paginator = Paginator(product,3) #1 หน้าโชว์ 3 ชิ้นเท่านั้น
	page = request.GET.get('page') # http://localhost:8000/allproduct/?page=2
	product = paginator.get_page(page)
	context = {'product':product}
	return render(request, 'myapp/allproduct.html', context)
Esempio n. 6
0
def following(request):

    # if user is not authenticated then open index page
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse("index"))

    # get users that the user follows
    users = request.user.following.all()

    # that list will hold all posts that the user follows
    posts = []

    # loop through those users
    for user in users:
        posts += user.posts.all()  # and collect all posts the user follows

    # function that gets date and time from a post (for sorting)
    def datetime(p):
        return p.date_time

    # sort post list by date and time
    posts.sort(reverse=True, key=datetime)

    #pagination
    paginator = Paginator(posts, 10)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, "network/following.html", {"page_obj": page_obj})
Esempio n. 7
0
def profile(request):

    # if user is not authenticated then open index page
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse("index"))

    # get user posts from DB
    user_posts = []
    if Post.objects.filter(author=request.user).exists():
        user_posts = Post.objects.filter(
            author=request.user).order_by("-date_time")

    # pagination
    paginator = Paginator(user_posts, 10)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)

    # get other users
    other_users = User.objects.exclude(id=request.user.id).values()

    context = {
        "page_obj": page_obj,  # user posts
        "following_count": request.user.following.count(),
        "followers_count":
        request.user.followers.count(),  # get number of followers of user
        "other_users": other_users,
        "following_users":
        request.user.following.all()  # get a list of all users being followed
    }
    return render(request, "network/profile.html", context)
Esempio n. 8
0
def AllOrderListPage(request):
	
	context = {}
	order = OrderPending.objects.all()


	for od in order:
		orderid = od.orderid
		odlist = OrderList.objects.filter(orderid=orderid)
		total = sum([ c.total for c in odlist])
		od.total = total

		count = sum([ c.quantity for c in odlist])

		if od.shipping == 'ems':
			shipcost = sum([ 50 if i == 0 else 10 for i in range(count)])
			# shipcost = รวมค่าทั้งหมด (หากเป็นชิ้นแรกค่าส่งจะคิด 50 บาท ชิ้นถัดไปชิ้นละ 10 บาท)
		else:
			shipcost = sum([ 35 if i == 0 else 10 for i in range(count)])

		if od.payment == 'cod':
			shipcost += 20 # shipcost = shipcost + 20
		od.shipcost = shipcost

	paginator = Paginator(order,5)
	page = request.GET.get('page') # http://localhost:8000/allorderlist/?page=
	order = paginator.get_page(page)
	context['allorder'] = order
	
	return render(request, 'myapp/allorderlist.html',context)
Esempio n. 9
0
def job_list(request):
    job_list = Job.objects.all()
    paginator = Paginator(job_list, 1)  # Show 25 contacts per page.
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    context = {'jobs': page_obj, 'jobs2': job_list}
    return render(request, "job/job_list.html", context)
Esempio n. 10
0
def detail(request, question_id):
    # 내용 출력
    # 존재하지 않는 페이지 접속시 404 출력, 기본키를 이용해 객체 반환
    question = get_object_or_404(Question, pk=question_id)

    page = request.GET.get('page', '1')
    so = request.GET.get('so', 'recent')

    if so == 'recommend':
        answer_list = question.answer_set.annotate(
            num_voter=Count('voter')).order_by('-num_voter', 'create_date')
    elif so == 'popular':
        answer_list = question.answer_set.annotate(
            num_comment=Count('comment')).order_by('-num_comment',
                                                   'create_date')
    else:  # recent
        answer_list = question.answer_set.order_by(
            'create_date')  # 먼저 작성된 시간순서 순으로 정렬

    paginator = Paginator(answer_list, 10)
    page_obj = paginator.get_page(page)
    last_page = paginator.num_pages
    answer_count = page_obj.count
    context = {
        'answer_list': page_obj,
        'question': question,
        'page': page,
        'so': so,
        'answer_count': answer_count,
        'last_page': last_page
    }
    return render(request, 'pybo/question_detail.html', context)
Esempio n. 11
0
def by_rubric(request, pk):
    rubric = get_object_or_404(SubRubric, pk=pk)
    articles = Article.objects.filter(is_active=True, rubric=pk)

    if 'keyword' in request.GET:
        keyword = request.GET['keyword']
        q = Q(title__icontains=keyword) | Q(content__icontains=keyword)
        articles = articles.filter(q)
    else:
        keyword = ''

    form = SearchForm(initial={'keyword': keyword})

    paginator = Paginator(articles, 2)  # по 2 на страницу
    if 'page' in request.GET:
        page_num = request.GET['page']
    else:
        page_num = 1

    page = paginator.get_page(page_num)
    context = {
        'rubric': rubric,
        'page': page,
        'articles': articles,
        'form': form,
    }
    return render(request, 'main/by_rubric.html', context)
Esempio n. 12
0
def ProductsCategory(request,code):
	select = Category.objects.get(id=code)
	product = Allproduct.objects.filter(catname=select).order_by('id').reverse() #query data from all products by descending order
	paginator = Paginator(product,3) #1 หน้าโชว์ 3 ชิ้นเท่านั้น
	page = request.GET.get('page') # http://localhost:8000/allproduct/?page=2
	product = paginator.get_page(page)
	context = {'product':product,'catname':select.catname}
	return render(request, 'myapp/allproductcat.html', context)
Esempio n. 13
0
def blog_list(request):
    posts = Post.objects.all()
    paginator = Paginator(posts, 1)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)

    context = {'posts': posts, 'page_obj': page_obj}
    return render(request, 'blog/index.html', context)
Esempio n. 14
0
def group_posts(request, slug):
    group = get_object_or_404(Group, slug=slug)
    posts = group.posts.all()[:12]
    paginator = Paginator(posts, 10)
    page_number = request.GET.get('page')
    page = paginator.get_page(page_number)

    return render(request, "group.html", {"group": group, 'page': page})
Esempio n. 15
0
def index(request):
    post_list = Post.objects.all()
    paginator = Paginator(post_list, 10)
    page_number = request.GET.get('page')
    page = paginator.get_page(page_number)

    return render(request, "index.html", {
        'page': page,
    })
Esempio n. 16
0
def filtered_by_category(request, category_code):
    posts = Post.objects.all().filter(category_id=category_code)
    paginator = Paginator(posts, 3)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)

    return render(request, 'feed.html', {
        "posts": page_obj
    })
Esempio n. 17
0
def listings(request):

    listings = Listing.objects.order_by('-list_date').filter(is_published=True)
    paginator = Paginator(listings, 3)
    page = request.GET.get('page')
    paged_listings = paginator.get_page(page)
    context = {'listings': listings}

    return render(request, 'listings.html', context)
Esempio n. 18
0
def index(request):
    page = request.GET.get('page', 1)
    board_list = Board.objects.order_by('-create_date')
    paginator = Paginator(board_list, 5)
    page_obj = paginator.get_page(page)

    context = {'board_list': page_obj}    
    #return HttpResponse("bbsnote에 오신 것을 환영합니다!");
    return render(request, 'bbsnote/board_list.html', context)
Esempio n. 19
0
def followed_posts(request):
    filtered, created = Follower.objects.get_or_create(owner=request.user)

    posts = Post.objects.filter(
        author__in=[fol for fol in filtered.followers.all()]).order_by(
            "-creation_date").all()
    paginator = Paginator(posts, 10)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, 'network/followed.html', {'page_obj': page_obj})
Esempio n. 20
0
def article_list(request):
    articles = Article.objects.order_by('created_at').reverse()
    paginator = Paginator(articles, 5)
    page = request.GET.get('page')
    articles = paginator.get_page(page)
    
    total_page = paginator.num_pages

    serializer= ArticleSerializer(articles, many=True)
    return Response(serializer.data)
Esempio n. 21
0
def index(request):

    # contatos = Contato.objects.all()
    contatos = Contato.objects.order_by('-id').filter(mostrar=True)
    paginator = Paginator(contatos, 8)

    page = request.GET.get('p')
    contatos = paginator.get_page(page)

    return render(request, 'contatos/index.html', {'contatos': contatos})
Esempio n. 22
0
def gamemain(request):
    gmain = Cookierun.objects
    g_list = Cookierun.objects.all()
    paginator = Paginator(g_list, 2)
    g_page = request.GET.get('g_page')
    g_posts = paginator.get_page(g_page)
    return render(request, 'gamemain.html', {
        'gmain': gmain,
        'g_posts': g_posts
    })
Esempio n. 23
0
def home(request):
    home_list = Dado.objects.all().order_by('-data')

    paginator = Paginator(home_list, 50)

    page = request.GET.get('page')

    home = paginator.get_page(page)

    return render(request, 'home.html', {'home': home})
Esempio n. 24
0
    def get(self, request, *args, **kwargs):
        posts = Post.objects.all()
        paginator = Paginator(posts, 6)

        page_number = request.GET.get('page')
        page_obj = paginator.get_page(page_number)

        return render(request,
                      'myblog/home.html',
                      context={'page_obj': page_obj})
Esempio n. 25
0
def other(request):
    if request.is_ajax and request.method == 'POST':
        print(request.POST)
        if request.POST['action'] == 'add':
            servis_setting.add_edit_other(request.POST)
            return redirect('/other')
        elif request.POST['action'] == 'delete':
            response = servis_setting.delete_other(request.POST)
            return JsonResponse(response, status=200, safe=False)
    if request.method == 'GET':
        if 'add' in request.GET:
            subject = Subjects.objects.all()
            lesson_pattern = Patterns.objects.all()
            context = {
                'subject': subject,
                'lesson_pattern': lesson_pattern,
            }
            return render(request, 'add_other.html', context)
        elif 'id' in request.GET:
            subject = Subjects.objects.all()
            lesson_pattern = Patterns.objects.all()
            context = {
                'subject': subject,
                'lesson_pattern': lesson_pattern,
                'others': servis_setting.get_other(request.GET['id'])
            }
            return render(request, 'edit_other.html', context=context)
        else:
            ctx = {}
            url_parameter = request.GET.get("q")

            if url_parameter:
                other = Other.objects.filter(
                    subject_name__name__icontains=url_parameter)
            else:
                other = Other.objects.all()
            paginator = Paginator(other, 5)
            page_number = request.GET.get('page')
            page_obj = paginator.get_page(page_number)

            ctx = {
                'other': other,
                'page_obj': page_obj,
            }
            if request.is_ajax():

                html = render_to_string(
                    template_name="settings/search/other-results.html",
                    context={
                        'other': other,
                        'page_obj': page_obj,
                    })
                data_dict = {"html_from_view": html}
                return JsonResponse(data=data_dict, safe=False)
            return render(request, 'other.html', context=ctx)
Esempio n. 26
0
def index(request):
    products = Product.objects.all()
    item_name = request.GET.get('item_name')
    if item_name != '' and item_name is not None:
        products = products.filter(title__icontains = item_name)

    paginator = Paginator(products, 4)
    page = request.GET.get('page')
    products = paginator.get_page(page)
    
    return render(request, 'shop/index.html', {'products':products})
Esempio n. 27
0
def index(request):
    #messages.add_message(request, messages.ERROR, 'Ocorreu um erro.')
    contatos = Contato.objects.order_by('nome')
    paginator = Paginator(contatos, 20)  # Show 20 contacts per page

    page = request.GET.get('p')
    contatos = paginator.get_page(page)
    return render(request, 'contatos/index.html',{
        'contatos': contatos

    })
Esempio n. 28
0
def room(request):
    if request.is_ajax and request.method == 'POST':
        print(request.POST)
        if request.POST['action'] == 'add':
            servis_setting.add_edit_room(request.POST)
            return redirect('/room')
        elif request.POST['action'] == 'delete':
            response = servis_setting.delete_room(request.POST)
            return JsonResponse(response, status=200, safe=False)
    if request.method == 'GET':
        if 'add' in request.GET:
            building_name = Building.objects.all()
            room_type = RoomType.objects.all()
            context = {
                'building_name': building_name,
                'room_type': room_type,
            }
            return render(request, 'add_room.html', context)
        elif 'id' in request.GET:
            building_name = Building.objects.all()
            room_type = RoomType.objects.all()
            context = {
                'building_name': building_name,
                'room_type': room_type,
                'rooms': servis_setting.get_room(request.GET['id']),
            }
            return render(request, 'edit_room.html', context=context)
        else:
            ctx = {}
            url_parameter = request.GET.get("q")

            if url_parameter:
                room = Room.objects.filter(
                    building_name__name__icontains=url_parameter)
            else:
                room = Room.objects.all()
            paginator = Paginator(room, 5)
            page_number = request.GET.get('page')
            page_obj = paginator.get_page(page_number)
            ctx = {
                'room': room,
                'page_obj': page_obj,
            }
            if request.is_ajax():

                html = render_to_string(
                    template_name="settings/search/room-results.html",
                    context={
                        'room': room,
                        'page_obj': page_obj,
                    })
                data_dict = {"html_from_view": html}
                return JsonResponse(data=data_dict, safe=False)
            return render(request, 'room.html', context=ctx)
Esempio n. 29
0
def home(request):
    blogs = Blog.objects.all()
    #블로그 모든 글들을 대상으로
    blog_list = Blog.objects.all()
    #블로그 객체 세 개를 한 페이지로 자르기
    paginator = Paginator(blog_list, 3)
    #request된 페이지가 뭔지를 알아내고 (request페이지를 변수에 담아내고)
    page = request.GET.get('page')
    #request된 페이지를 얻어온 뒤 return 해 준다
    posts = paginator.get_page(page)
    return render(request, 'home.html', {'blogs': blogs, 'posts': posts})
Esempio n. 30
0
def CategoryViewList(request):
    cat = Category.objects.order_by('-id')
    paginator = Paginator(cat, 5)
    page = request.GET.get('page')
    categories = paginator.get_page(page)

    context = {
        'categories' : categories
    }

    return render(request, 'blog/category.html', context)