Skip to content

Commit

Permalink
refactor: using pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichi3227 authored and LifeAdventurer committed May 24, 2024
1 parent feef0da commit 9927584
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/handlers/chal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ChalListHandler(RequestHandler):
@reqenv
async def get(self):
try:
off = int(self.get_argument('off'))
pageoff = int(self.get_argument('pageoff'))

except tornado.web.HTTPError:
off = 0
pageoff = 0

try:
ppro_id = str(self.get_argument('proid'))
Expand Down Expand Up @@ -60,7 +60,7 @@ async def get(self):

_, chalstat = await ChalService.inst.get_stat(self.acct, flt)

_, challist = await ChalService.inst.list_chal(off, 20, self.acct, flt)
_, challist = await ChalService.inst.list_chal(pageoff, 20, self.acct, flt)

isadmin = self.acct.is_kernel()
chalids = [chal['chal_id'] for chal in challist]
Expand All @@ -70,7 +70,7 @@ async def get(self):
chalstat=chalstat,
challist=challist,
flt=flt,
pageoff=off,
pageoff=pageoff,
ppro_id=ppro_id,
pacct_id=pacct_id,
acct=self.acct,
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class LogHandler(RequestHandler):
@require_permission(UserConst.ACCTTYPE_KERNEL)
async def get(self):
try:
off = int(self.get_argument('off'))
pageoff = int(self.get_argument('pageoff'))
except tornado.web.HTTPError:
off = 0
pageoff = 0

try:
logtype = str(self.get_argument('logtype'))
Expand All @@ -22,14 +22,14 @@ async def get(self):

err, logtype_list = await LogService.inst.get_log_type()

err, log = await LogService.inst.list_log(off, 50, logtype)
err, log = await LogService.inst.list_log(pageoff, 50, logtype)
if err:
self.error(err)
return

await self.render(
'loglist',
pageoff=off,
pageoff=pageoff,
lognum=log['lognum'],
loglist=log['loglist'],
logtype_list=logtype_list,
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ProsetHandler(RequestHandler):
@reqenv
async def get(self):
try:
off = int(self.get_argument('off'))
pageoff = int(self.get_argument('pageoff'))
except tornado.web.HTTPError:
off = 0
pageoff = 0

try:
order = self.get_argument('order')
Expand Down Expand Up @@ -123,17 +123,17 @@ async def get(self):
if order_reverse:
prolist.reverse()

pronum = len(prolist)
prolist = prolist[off : off + 40]
pro_total_cnt = len(prolist)
prolist = prolist[pageoff : pageoff + 40]

await self.render(
'proset',
pronum=pronum,
pro_total_cnt=pro_total_cnt,
prolist=prolist,
clas=clas,
pubclass_list=pubclass_list,
cur_pubclass=pubclass,
pageoff=off,
pageoff=pageoff,
flt=flt,
isadmin=self.acct.is_kernel(),
)
Expand Down
20 changes: 5 additions & 15 deletions src/static/templ/challist.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,11 @@
<div class="row">
<!-- <div class="col-1"></div> -->
<div class="col pt-3">
<nav aria-label="Page navigation">
<ul class="pagination">
<!-- this algorithm from toj -->
<!-- 我沒研究怎麼實現的,但能用 -->
<li class="page-item"><a class="page-link" href="?off=0{{ postfix }}">&#x21e4;</a></li>
{% import math %}
{% set ct = math.floor(pageoff / 20) %}
{% set st = min(max(0, ct - 9), max(0, math.ceil(chalstat['total_chal'] / 20) - 19)) %}
{% for i, off in enumerate(range(st * 20, min(chalstat['total_chal'], st * 20 + 380), 20)) %}
<li class="page-item {% if ct == (i + st) %} active {% end %}">
<a class="page-link {% if ct == (i + st) %} active{% end %}" href="?off={{ str(off) + postfix }}">{{i + 1 + st}}</a>
</li>
{% end %}
</ul>
</nav>
{% set _p_pageoff = pageoff %}
{% set _p_pagenum = 20 %}
{% set _p_total_cnt = chalstat['total_cnt'] %}
{% set _p_postfix = postfix %}
{% include "pagination.html" %}
</div>
</div>
</div>
Expand Down
32 changes: 11 additions & 21 deletions src/static/templ/loglist.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,20 @@
</tbody>
</table>


{% set postfix = '' %}
{% if cur_logtype is not None %}
{% set postfix = postfix + '&logtype=%s' % cur_logtype %}
{% end %}

<div class="row">
<div class="col-1"></div>
<div class="col pt-3">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<!-- this algorithm from toj -->
<!-- 我沒研究怎麼實現的,但能用 -->
{% set postfix = '' %}
{% if cur_logtype is not None %}
{% set postfix = postfix + '&logtype=%s' % cur_logtype %}
{% end %}

<li class="page-item"><a class="page-link" href="?off=0{{ postfix }}">&#x21e4;</a></li>
{% import math %}
{% set limit = 50 %}
{% set ct = math.floor(pageoff / limit) %}
{% set st = min(max(0, ct - 9), max(0, math.ceil(lognum / limit) - 19)) %}
{% for i, off in enumerate(range(st * limit, min(lognum, st * limit + 950), limit)) %}
<li class="page-item {% if ct == (i + st) %} active {% end %}">
<a class="page-link {% if ct == (i + st) %} active{% end %}" href="?off={{ str(off) + postfix }}">{{i + 1 + st}}</a>
</li>
{% end %}
</ul>
</nav>
{% set _p_pageoff = pageoff %}
{% set _p_pagenum = 50 %}
{% set _p_total_cnt = lognum %}
{% set _p_postfix = postfix %}
{% include "pagination.html" %}
</div>
</div>

Expand Down
25 changes: 7 additions & 18 deletions src/static/templ/proset.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
</script>

<style>
@media only screen and (min-width: 992px){

@media only screen and (min-width: 992px) {
.pagination {
justify-content: center;
}
Expand Down Expand Up @@ -241,22 +241,11 @@
<div class="row">
<div class="col-1"></div>
<div class="col pt-3">
<nav aria-label="Page navigation example">
<ul class="pagination">
<!-- this algorithm from toj -->
<!-- 我沒研究怎麼實現的,但能用 -->
<li class="page-item"><a class="page-link" href="?off=0{{ postfix }}">&#x21e4;</a></li>
{% import math %}
{% set limit = 40 %}
{% set ct = math.floor(pageoff / limit) %}
{% set st = min(max(0, ct - 9), max(0, math.ceil(pronum / limit) - 39)) %}
{% for i, off in enumerate(range(st * limit, pronum, limit)) %}
<li class="page-item {% if ct == (i + st) %} active {% end %}">
<a class="page-link {% if ct == (i + st) %} active{% end %}" href="?off={{ str(off) + postfix }}">{{i + 1 + st}}</a>
</li>
{% end %}
</ul>
</nav>
{% set _p_pageoff = pageoff %}
{% set _p_pagenum = 40 %}
{% set _p_total_cnt = pro_total_cnt %}
{% set _p_postfix = postfix %}
{% include "pagination.html" %}
</div>
</div>

Expand Down

0 comments on commit 9927584

Please sign in to comment.