def new_exam(request): # 获取文章 posts = ServerPosts.objects.filter(cateid_id=2).filter( is_status=1).order_by('-id') # 获取热门文章 hot_posts = ServerPosts.objects.filter(is_status=1).order_by('-views')[:10] # 获取热门院校 hot_schools = Schools.objects.filter(is_status=1).order_by('-count')[:12] # 获取热门专业 hot_majors = Majors.objects.filter(is_status=1).order_by('-count')[:5] # 分页展示 data = posts page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 15) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'posts': posts, 'hot_posts': hot_posts, 'hot_schools': hot_schools, 'hot_majors': hot_majors } return render(request, 'service/services-new_exam-posts.html', context=context)
def CollegeauthoSearch(request): scool_code = request.GET.get('school_code') school_name = request.GET.get('school_name') centers = Centers.objects.filter(school_id=int(scool_code)) pro_code = request.GET.get('province_code', '') # 查询省份 provinces = Provinces.objects.filter(id__in=centers.values('provinces')) if pro_code: centers = centers.filter(provinces_id=int(pro_code)) # 学习中心数量 center_num = centers.count() # 分页展示 data = centers page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 20) # 当前页数据条数 data_num = len(pages['data'].object_list) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'school_code': scool_code, 'school_name': school_name, 'centers': centers, 'center_num': center_num, 'provinces': provinces, 'province_code': pro_code, 'data_num': data_num } return render(request, 'service/services-collegeautho-search.html', context=context)
def post(self, request): name = request.POST.get('name') phone = request.POST.get('phone') id_card = request.POST.get('card') # 查询相关信息 order = Orders.objects.filter(Q(real_name=name), Q(phone=phone), Q(idcard=id_card)) # 分页展示 data = order page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 10) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'order': order, 'name': name, 'phone': phone, 'id_card': id_card } return render(request, 'service/services-feecard-search.html', context=context)
def searchCenter(request): keyWord = request.GET.get('search', '') school_info, major_info, center_info, posts_info, all_count, recommends = '', '', '', '', '', '' if keyWord: school_info = Schools.objects.filter(name__contains=keyWord) major_info = Majors.objects.filter(school__name__contains=keyWord) center_info = Centers.objects.filter(name__contains=keyWord) posts_info = Posts.objects.filter(post_title__contains=keyWord) recommends = Majors.objects.filter(is_recommend=1) all_count = school_info.count() + major_info.count( ) + center_info.count() + posts_info.count() # 分页展示 data = center_info page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 15) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'keyword': keyWord, 'school_info': school_info, 'major_info': major_info, 'center_info': center_info, 'posts_info': posts_info, 'all_count': all_count, 'recommends': recommends } return render(request, 'search_info/center_info.html', context=context)
def news(request): posts = Posts.objects.order_by('-id').filter(is_status=1) # 热门文章 hot_posts = Posts.objects.order_by('-views').filter(is_status=1)[:10] # 分页展示 data = posts page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 20) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'posts': posts, 'hot_posts': hot_posts, } return render(request, 'news/posts.html', context=context)
def get(self, request): name = request.GET.get('name') # 查询学习中中心, 使用contains 进行模糊查询 centers = Centers.objects.filter(name__contains=name) # 分页展示 data = centers page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 3) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'name': name, 'centers': centers } return render(request, 'service/services-centerauth-search.html', context=context)
def school(request): # 获取学校 schools = Schools.objects.filter(is_status=1) # 获取热门院校 hot_school = schools.order_by('-count')[:12] # 获取报考指南 hot_posts = ServerPosts.objects.filter(cateid_id=1).order_by('-views')[:5] # 获取学校类型 school_types = SchoolType.objects.filter(is_status=1) # 获取院校特征 school_features = SchoolFeatures.objects.filter(is_status=1) # 推荐专业 recommends = Majors.objects.filter(is_recommend=1) # 获取省份 sch_pro = Schools.objects.values('sch_pro').distinct() sch_pro = [int(x['sch_pro']) for x in sch_pro] # 获取所有省 pro = Provinces.objects.all() # 获取省份id pro_id = request.GET.get('p','') if pro_id: schools = schools.filter(sch_pro_id=int(pro_id)) # 获取类型 type_id = request.GET.get('t', '') if type_id: schools = schools.filter(school_type__id=int(type_id)) # 获取特征 feature_id = request.GET.get('f', '') if feature_id: schools = schools.filter(scholl_feature__id = int(feature_id)) # 获取排序 sort = request.GET.get('sort', '') if sort: if sort == 'normal': schools = schools elif sort == 'count': schools = schools.order_by('-count') # 分页展示 data = schools page = request.GET.get('page', 1) pages = Page.get_page(request, page, data, 20) context = { 'data': pages['data'], 'paginator': pages['paginator'], 'currentPage': pages['currentPage'], 'page_range': pages['page_range'], 'schools':schools, 'hot_school':hot_school, 'hot_posts':hot_posts, 'sch_pro':sch_pro, 'recommends':recommends, 'pros':pro, 'school_types':school_types, 'school_features':school_features, 'pro_id':pro_id, 'type_id':type_id, 'feature_id':feature_id, 'sort':sort, } return render(request,'choose_school/school.html',context=context)