def get(self, request: Request): """@sadeceCikmayanlar çıkış tarihi eklenmemiş kayıtları gösterir @subeFiltre""" sadeceCikmayanlar = False subeFiltre = -1 if request.query_params.get("sadece-cikmayanlar") == "1": sadeceCikmayanlar = True subeId: str = request.query_params.get("sube-id") if (subeId != "" and subeId is not None and re.match("^([0-9].*)$", subeId) is not None): subeFiltre = int(subeId) customersQ = MusteriGirisi.objects if sadeceCikmayanlar: customersQ = customersQ.filter(cikis_tarih__isnull=True) relations = iliskiliSubeler(request.user) # admin control if request.user.is_superuser: customerEntries = None if subeFiltre == -1: customerEntries = MusteriGirisi.objects.order_by("-id").all() else: customerEntries = MusteriGirisi.objects.filter( secili_sube__id=subeFiltre).order_by("-id") paginated = pagination(customerEntries, request.query_params.get("page"), request.query_params.get("size")) return Response(makeArraySerializationsQuery(paginated)) # if not admin but staff elif request.user.is_staff: if subeFiltre > -1: iliskiliSube = iliskiVarMi(request.user, subeFiltre, relations) if iliskiliSube is not None: customerEntries = customersQ.filter( secili_sube=iliskiliSube).order_by("-id") paginated = pagination(customerEntries, request.query_params.get("page"), request.query_params.get("size")) return Response(makeArraySerializationsQuery(paginated)) else: return createErrorResponse( 403, { "message": "You aren't related with ŞUBE(Branch)" + str(subeFiltre) }, ) else: customerEntries = customersQ.filter( secili_sube__in=relations).order_by("-id") return Response( makeArraySerializationsQuery(customerEntries.all()))
def index_view(request, page=1): pictures = Picture.objects.order_by('-add_time').all() pages, page_range = pagination(page=page, queryset=pictures, per_page=16) context = template_context(tag='gallery', pages=pages, page_range=page_range) return render(request, 'gallery.html', context)
def index_view(request, page=1, category_name=''): categories = Category.objects.filter( post__category__isnull=False).distinct().all() keyword = request.GET.get('s', '') if category_name == '' and keyword == '': posts = Post.objects.order_by("-add_time").all() elif category_name == '' and keyword != '': posts = Post.objects.filter( title__icontains=keyword).order_by("-add_time").all() elif category_name != '' and keyword == '': posts = Post.objects.filter( category__sub_name=category_name).order_by("-add_time").all() else: posts = Post.objects.filter( category__sub_name=category_name, title__contains=keyword).order_by("-add_time").all() pages, page_range = pagination(page=page, queryset=posts, per_page=5) context = template_context(tag='blog', pages=pages, page_range=page_range, categories=categories, category_name=category_name) return render(request, 'blog.html', context)
def customs_declaration(cls, declarations, trade_type, page, filter_id, sort_id, asc_id, **kwargs): declaration_statuses = Declaration_Status.query.all() search = request.args.get('search') if search: declarations = Search_Class.search_content(search, declarations, **kwargs) else: if filter_id != 0: declarations = declarations.filter_by(status_id=filter_id) d = Declaration_Class(declarations, trade_type, sort_id, asc_id) declarations = d.query_declaration() total_page, start, end, page_li, pre_page, next_page = pagination( page, len(declarations), SINGLE_PAGE_NUM, SHOW_PAGE) context = dict(declarations=declarations[start:end], declaration_statuses=declaration_statuses, current_page=page, current_filter_id=filter_id, current_sort_id=sort_id, current_asc_id=asc_id, total_page=total_page, page_li=page_li, pre_page=pre_page, next_page=next_page, show_page=SHOW_PAGE) return context
def get(self, request: Request): flag, errorResponse = _generic_control(request) if flag: date_ = request.query_params["date"] sube = int(request.query_params["sube_id"]) expenses = extra_expenses(sube, date_) paginated_expenses = pagination(expenses, request.query_params.get("page"), request.query_params.get("size")) return createErrorResponse(200, paginated_expenses) else: return errorResponse
def search_view(request, page=1): categories = Category.objects.filter( post__category__isnull=False).distinct().all() keyword = request.GET.get('keyword') posts = Post.objects.filter(title__contains=keyword).all() pages, page_range = pagination(page=page, queryset=posts, per_page=5) context = template_context(tag='blog', pages=pages, page_range=page_range, categories=categories) return render(request, 'blog.html', context)
def get(self, request : Request): try: subeId: str = request.query_params.get("sube-id") if request.user.is_superuser: if subeId is not None and subeId.isnumeric(): query = Randevu.objects.filter(secili_sube__id=int(subeId)).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")); return Response(self.__convertAppointments(paginated)) else: paginated = pagination(Randevu.objects.order_by("-id"), request.query_params.get("page"), request.query_params.get("size")).order_by("-id") return Response(self.__convertAppointments(paginated)) else: query = Randevu.objects if subeId is not None and subeId.isnumeric(): temsil = iliskiVarMi(request.user, int(subeId)) if temsil is not None: query = query.filter(secili_sube=temsil.sube).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")) return Response(self.__convertAppointments(paginated)) else: return createErrorResponse(403, {"message": "You aren't authenticated with this branch"}) else: iliskiliBranchler = iliskiliSubeler(request.user) query = Randevu.objects.filter(secili_sube__in=iliskiliBranchler).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")) return Response(self.__convertAppointments(paginated)) except Exception as exception: traceback.print_exc() return createErrorResponse(500, {"error": str(exception.__class__)})
def front_declaration_status_query(page=1,trade_id=0,status_id=0,sort_id=5,asc_id=2): import_declarations=g.front_user.company.business_import_declarations export_declarations=g.front_user.company.business_export_declarations business_company=g.front_user.company statuses=Declaration_Status.query.all() search=request.args.get('search') if search: declarations = list(import_declarations) + list(export_declarations) declarations=Search_Class.search_content(search,declarations,search_1='bl_code',search_2='declaration_code',search_3='customs_date') else: if trade_id==1: export_declarations=[] elif trade_id==2: import_declarations=[] declarations=list(import_declarations)+list(export_declarations) if status_id!=0: declarations=filter(lambda declaration:declaration.status_id==status_id,declarations) if declarations else [] asc=True if asc_id==1: asc=False if sort_id==5: declarations=sorted(declarations,key=lambda declaration: declaration.customs_date,reverse=asc) elif sort_id==2: declarations = sorted(declarations, key=lambda declaration: declaration.status_id, reverse=asc) elif sort_id==7: declarations = sorted(declarations, key=lambda declaration: declaration.tax_mode_id, reverse=asc) total_num=len(declarations) if declarations else 0 total_page,start,end,page_li,pre_page,next_page=pagination(page,total_num,SINGLE_PAGE_NUM,SHOW_PAGE) context=dict(declarations=declarations[start:end],total_page=total_page,page_li=page_li, pre_page=pre_page,next_page=next_page,show_page=SHOW_PAGE, business_company=business_company,statuses=statuses, current_page=page,current_status_id=status_id,current_trade_id=trade_id, current_sort_id=sort_id,current_asc_id=asc_id) return render_template('front/front_declaration_status_query.html',**context)
def cms_post_manage(request,page): search_content = request.GET.get('search') if search_content: articles=search(search_content) else: articles=bm.Article.objects.order_by('-create_time').all() total_num=len(articles) if articles else 0 total_page,start,end,page_li,show_end_num=pagination(page,total_num,SINGLE_PAGE_NUM,SHOW_PAGE_NUM) context=dict(articles=articles[start:end],total_page=total_page, page_li=page_li,current_page=int(page),search_content=search_content, show_page_num=SHOW_PAGE_NUM,show_end_num=show_end_num) return render(request,'cms_post_manage.html',context=context)
def yzb_view(request): # 增加访问数 if 'HTTP_X_FORWARDED_FOR' in request.META: ip = request.META.get('HTTP_X_FORWARDED_FOR') else: ip = request.META.get('REMOTE_ADDR') # region = ip2_region_by_138(ip) YzbVisit.objects.create(ip=ip, url=request.get_full_path()) # 查询 year = request.GET.get('year', '') code = request.GET.get('code', '') tj = request.GET.get('tj', '') order = request.GET.get('order', '') page = int(request.GET.get('p', 1)) yzb_while = {} if year: yzb_while['year'] = year if code: yzb_while['code'] = code if tj: yzb_while['is_tj'] = tj infos = Yzb.objects.filter(**yzb_while).order_by('num') if order: if order == 'zongfen': infos = infos.annotate(zongfen=F('chushi') + F('fushi')).order_by('-zongfen') else: infos = infos.order_by('-' + order) pages, page_range = pagination(page=page, queryset=infos, per_page=100) codes = Yzb.objects.values("code", "code_name").distinct() context = template_context(tag='project', pages=pages, page_range=page_range, page_count=(page - 1) * 100, codes=codes, year=year, code=code, tj=tj, order=order) return render(request, 'yzb.html', context=context)
def get(self, page): files = self.db.query(File).order_by(File.is_removed, File.create_time.desc()).all() current_page = int(page) total_page, start, end, page_list, pre_page, next_page = pagination( current_page=current_page, total_num=len(files), sing_page_num=SINGLE_PAGE_NUM, show_page=SHOW_PAGE, ) context = dict(files=files[start:end], current_page=current_page, total_page=total_page, page_list=page_list, pre_page=pre_page, next_page=next_page, show_page=SHOW_PAGE) self.render('cms/cms_file_table.html', **context)
def blog_articles(request, page): search_content = request.GET.get('search') if search_content: articles = search(search_content) else: articles = bm.Article.objects.filter( is_delete=0).order_by('-create_time').all() articles_len = len(articles) if articles else 0 total_page, start, end, page_li, show_end_num = pagination( page, articles_len, cfg.FRONT_SINGLE_PAGE_NUM, cfg.SHOW_PAGE_NUM) context = dict(articles=articles[start:end], total_page=total_page, page_li=page_li, show_end_num=show_end_num, current_page=page, single_page_num=cfg.FRONT_SINGLE_PAGE_NUM, show_page_num=cfg.FRONT_SHOW_PAGE_NUM) return render(request, 'blog_articles.html', context=context)