g214/page/views.py

48 lines
1.5 KiB
Python
Raw Normal View History

2018-08-20 08:21:25 +00:00
#coding:utf-8
from django.shortcuts import render
from django.http import HttpResponse
from page.models import Page, Member, Introduction
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
# Create your views here.
def page(request):
name = request.GET.get('name')
return render(request, 'page/about.html', {'name': name})
def unit(request):
category = request.GET.get('category')
pages = []
member = []
if category == '11' or category == '21' or category == '31':
try:
pages = Page.objects.filter(name=category).order_by('-created')
except Page.DoesNotExist:
pages = []
paginator = Paginator(pages, 12)
p = int(request.GET.get('page', 1))
try:
page_paginator = paginator.page(p)
except PageNotAnInteger:
page_paginator = paginator.page(1)
except EmptyPage:
page_paginator = paginator.page(paginator.num_pages)
if category == '1':
pages = Introduction.objects.all()
if category == '41':
member = Member.objects.all().order_by('number')
return render(request, 'page/detail.html', {"category": category,
"pages": pages, "page_paginator": page_paginator,
"p": p, "member": member})
def list_detail(request):
id = request.GET.get('id')
if id:
page = Page.objects.get(id=id)
category = request.GET.get('category')
return render(request, 'page/list_detail.html', {"page": page, "category": category})