How to use current_page method in pom

Best Python code snippet using pom_python

views.py

Source:views.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Create your views here.3#from django.template.loader import get_template 4#from django.template import Template, Context 5#from django.http import Http404, HttpResponse 6from django.shortcuts import render_to_response7from django.utils import timezone8from sample_board.models import DjangoBoard9from django.views.decorators.csrf import csrf_exempt10from django.http import HttpResponseRedirect11from sample_board.pagingHelper import pagingHelper12#from django.core.urlresolvers import reverse13# 한글!!14#===========================================================================================15rowsPerPage = 2 16 17def home(request): 18 #OK19 #url = '/listSpecificPageWork?current_page=1' 20 #return HttpResponseRedirect(url) 21 boardList = DjangoBoard.objects.order_by('-id')[0:2] 22 current_page =123 totalCnt = DjangoBoard.objects.all().count() 24 25 pagingHelperIns = pagingHelper();26 totalPageList = pagingHelperIns.getTotalPageList( totalCnt, rowsPerPage)27 print 'totalPageList', totalPageList28 29 return render_to_response('listSpecificPage.html', {'boardList': boardList, 'totalCnt': totalCnt, 30 'current_page':current_page ,'totalPageList':totalPageList} ) 31 32#===========================================================================================33def show_write_form(request):34 return render_to_response('writeBoard.html') 35#===========================================================================================36@csrf_exempt37def DoWriteBoard(request):38 br = DjangoBoard (subject = request.POST['subject'],39 name = request.POST['name'],40 mail = request.POST['email'],41 memo = request.POST['memo'],42 created_date = timezone.now(),43 hits = 044 )45 br.save()46 47 # 다시 조회 48 url = '/listSpecificPageWork?current_page=1' 49 return HttpResponseRedirect(url) 50 51#===========================================================================================52def viewWork(request):53 pk= request.GET['memo_id'] 54 #print 'pk='+ pk55 boardData = DjangoBoard.objects.get(id=pk)56 #print boardData.memo57 58 # Update DataBase59 print 'boardData.hits', boardData.hits60 DjangoBoard.objects.filter(id=pk).update(hits = boardData.hits + 1)61 62 return render_to_response('viewMemo.html', {'memo_id': request.GET['memo_id'], 63 'current_page':request.GET['current_page'], 64 'searchStr': request.GET['searchStr'], 65 'boardData': boardData } ) 66 67#===========================================================================================68def listSpecificPageWork(request): 69 current_page = request.GET['current_page']70 totalCnt = DjangoBoard.objects.all().count() 71 72 print 'current_page=', current_page73 74 # 페이지를 가지고 범위 데이터를 조회한다 => raw SQL 사용함75 boardList = DjangoBoard.objects.raw('SELECT Z.* FROM(SELECT X.*, ceil( rownum / %s ) as page FROM ( SELECT ID,SUBJECT,NAME, CREATED_DATE, MAIL,MEMO,HITS \76 FROM SAMPLE_BOARD_DJANGOBOARD ORDER BY ID DESC ) X ) Z WHERE page = %s', [rowsPerPage, current_page])77 78 print 'boardList=',boardList, 'count()=', totalCnt79 80 # 전체 페이지를 구해서 전달...81 pagingHelperIns = pagingHelper();82 83 totalPageList = pagingHelperIns.getTotalPageList( totalCnt, rowsPerPage)84 85 print 'totalPageList', totalPageList86 87 return render_to_response('listSpecificPage.html', {'boardList': boardList, 'totalCnt': totalCnt, 88 'current_page':int(current_page) ,'totalPageList':totalPageList} )89#===========================================================================================90def listSpecificPageWork_to_update(request):91 memo_id = request.GET['memo_id']92 current_page = request.GET['current_page']93 searchStr = request.GET['searchStr']94 95 #totalCnt = DjangoBoard.objects.all().count()96 print 'memo_id', memo_id97 print 'current_page', current_page98 print 'searchStr', searchStr99 100 boardData = DjangoBoard.objects.get(id=memo_id)101 102 return render_to_response('viewForUpdate.html', {'memo_id': request.GET['memo_id'], 103 'current_page':request.GET['current_page'], 104 'searchStr': request.GET['searchStr'], 105 'boardData': boardData } ) 106#===========================================================================================107@csrf_exempt108def updateBoard(request):109 memo_id = request.POST['memo_id']110 current_page = request.POST['current_page']111 searchStr = request.POST['searchStr'] 112 113 print '#### updateBoard ######'114 print 'memo_id', memo_id115 print 'current_page', current_page116 print 'searchStr', searchStr117 118 # Update DataBase119 DjangoBoard.objects.filter(id=memo_id).update(120 mail= request.POST['mail'],121 subject= request.POST['subject'],122 memo= request.POST['memo']123 )124 125 # Display Page => POST 요청은 redirection!126 url = '/listSpecificPageWork?current_page=' + str(current_page)127 return HttpResponseRedirect(url) 128 129#===========================================================================================130def DeleteSpecificRow(request):131 memo_id = request.GET['memo_id']132 current_page = request.GET['current_page']133 print '#### DeleteSpecificRow ######'134 print 'memo_id', memo_id135 print 'current_page', current_page136 137 p = DjangoBoard.objects.get(id=memo_id)138 p.delete()139 140 # Display Page 141 # 마지막 메모를 삭제하는 경우, 페이지를 하나 줄임.142 totalCnt = DjangoBoard.objects.all().count() 143 pagingHelperIns = pagingHelper();144 145 totalPageList = pagingHelperIns.getTotalPageList( totalCnt, rowsPerPage)146 print 'totalPages', totalPageList147 148 if( int(current_page) in totalPageList):149 print 'current_page No Change'150 current_page=current_page151 else:152 current_page= int(current_page)-1153 print 'current_page--' 154 155 url = '/listSpecificPageWork?current_page=' + str(current_page)156 return HttpResponseRedirect(url) 157#===========================================================================================158@csrf_exempt159def searchWithSubject(request):160 searchStr = request.POST['searchStr']161 print 'searchStr', searchStr162 163 url = '/listSearchedSpecificPageWork?searchStr=' + searchStr +'&pageForView=1'164 return HttpResponseRedirect(url) 165 166 167#=========================================================================================== 168def listSearchedSpecificPageWork(request):169 searchStr = request.GET['searchStr']170 pageForView = request.GET['pageForView']171 print 'listSearchedSpecificPageWork:searchStr', searchStr, 'pageForView=', pageForView172 173 #boardList = DjangoBoard.objects.filter(subject__contains=searchStr)174 #print 'boardList=',boardList175 176 totalCnt = DjangoBoard.objects.filter(subject__contains=searchStr).count()177 print 'totalCnt=',totalCnt178 179 pagingHelperIns = pagingHelper();180 totalPageList = pagingHelperIns.getTotalPageList( totalCnt, rowsPerPage)181 182 # like 구문 적용방법 183 boardList = DjangoBoard.objects.raw("""SELECT Z.* FROM ( SELECT X.*, ceil(rownum / %s) as page \184 FROM ( SELECT ID,SUBJECT,NAME, CREATED_DATE, MAIL,MEMO,HITS FROM SAMPLE_BOARD_DJANGOBOARD \185 WHERE SUBJECT LIKE '%%'||%s||'%%' ORDER BY ID DESC) X ) Z WHERE page = %s""", [rowsPerPage, searchStr, pageForView])186 187 print'boardList=',boardList188 189 return render_to_response('listSearchedSpecificPage.html', {'boardList': boardList, 'totalCnt': totalCnt, 190 'pageForView':int(pageForView) ,'searchStr':searchStr, 'totalPageList':totalPageList} ) 191 192#===========================================================================================...

Full Screen

Full Screen

pagination.py

Source:pagination.py Github

copy

Full Screen

1"""2分页组件3"""456class Pagination(object):7 def __init__(self, current_page, all_count, base_url, query_params, per_page=20, pager_page_count=11):8 """9 分页初始化10 :param current_page: 当前页码11 :param per_page: 每页显示数据条数12 :param all_count: 数据库中总条数13 :param base_url: 基础URL14 :param query_params: QueryDict对象,内部含所有当前URL的原条件15 :param pager_page_count: 页面上最多显示的页码数量16 """17 self.base_url = base_url18 try:19 self.current_page = int(current_page)20 if self.current_page <= 0:21 raise Exception()22 except Exception as e:23 self.current_page = 124 self.query_params = query_params25 self.per_page = per_page26 self.all_count = all_count27 self.pager_page_count = pager_page_count28 pager_count, b = divmod(all_count, per_page)29 if b != 0:30 pager_count += 131 self.pager_count = pager_count3233 half_pager_page_count = int(pager_page_count / 2)34 self.half_pager_page_count = half_pager_page_count3536 @property37 def start(self):38 """39 数据获取值起始索引40 :return:41 """42 return (self.current_page - 1) * self.per_page4344 @property45 def end(self):46 """47 数据获取值结束索引48 :return:49 """50 return self.current_page * self.per_page5152 def page_html(self):53 """54 生成HTML页码55 :return:56 """57 # 如果数据总页码pager_count<11 pager_page_count58 if self.pager_count < self.pager_page_count:59 pager_start = 160 pager_end = self.pager_count61 else:62 # 数据页码已经超过1163 # 判断: 如果当前页 <= 5 half_pager_page_count64 if self.current_page <= self.half_pager_page_count:65 pager_start = 166 pager_end = self.pager_page_count67 else:68 # 如果: 当前页+5 > 总页码69 if (self.current_page + self.half_pager_page_count) > self.pager_count:70 pager_end = self.pager_count71 pager_start = self.pager_count - self.pager_page_count + 172 else:73 pager_start = self.current_page - self.half_pager_page_count74 pager_end = self.current_page + self.half_pager_page_count7576 page_list = []7778 if self.current_page <= 1:79 prev = '<li><a href="#">上一页</a></li>'80 else:81 self.query_params['page'] = self.current_page - 182 prev = '<li><a href="%s?%s">上一页</a></li>' % (self.base_url, self.query_params.urlencode())83 page_list.append(prev)84 for i in range(pager_start, pager_end + 1):85 self.query_params['page'] = i86 if self.current_page == i:87 tpl = '<li class="active"><a href="%s?%s">%s</a></li>' % (88 self.base_url, self.query_params.urlencode(), i,)89 else:90 tpl = '<li><a href="%s?%s">%s</a></li>' % (self.base_url, self.query_params.urlencode(), i,)91 page_list.append(tpl)9293 if self.current_page >= self.pager_count:94 nex = '<li><a href="#">下一页</a></li>'95 else:96 self.query_params['page'] = self.current_page + 197 nex = '<li><a href="%s?%s">下一页</a></li>' % (self.base_url, self.query_params.urlencode(),)98 page_list.append(nex)99 page_str = "".join(page_list) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful