-
Notifications
You must be signed in to change notification settings - Fork 17
Pagination #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,62 +63,126 @@ | |
@app.route("/") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def home(auth_dict=None): | ||
def home_def(auth_dict=None): | ||
return redirect("/1") | ||
|
||
@app.route("/<int:page>") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def home(page, auth_dict=None): | ||
# Retrieve list of files for templating | ||
db_files = File.query.all() | ||
query = File.query | ||
rows = query.count() | ||
rows = int(rows // 10 + bool(rows % 10)) | ||
|
||
if page > rows or page < 1: | ||
return "Page Out of Bounds", 404 | ||
|
||
db_files = File.query.offset((page-1) * 10).limit(10).all() | ||
harolds = get_harold_list(auth_dict["uid"]) | ||
tour_harolds = get_harold_list("root") | ||
|
||
is_rtp = ldap_is_rtp(auth_dict["uid"]) | ||
is_eboard = ldap_is_eboard(auth_dict["uid"]) | ||
|
||
return render_template("main.html", db_files=db_files, | ||
get_date_modified=get_date_modified, s3_bucket=s3_bucket, | ||
auth_dict=auth_dict, harolds=harolds, tour_harolds=tour_harolds, | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False) | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False, | ||
current="", page=page, rows=rows, begin=max(1, page-6), | ||
end=min(page+6, rows) + 1) | ||
Comment on lines
88
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: one arg per line. this has gotten too long to be readable like this
Comment on lines
+92
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment about begin and end as your other pagination pr. can this be done in the jinja since you're passing page? |
||
|
||
@app.route("/mine") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def mine(auth_dict=None): | ||
def mine_def(auth_dict=None): | ||
return redirect("/mine/1") | ||
|
||
@app.route("/mine/<int:page>") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def mine(page, auth_dict=None): | ||
query = File.query.filter_by(author=auth_dict["uid"]) | ||
rows = query.count() | ||
rows = int(rows // 10 + bool(rows % 10)) | ||
|
||
if page > rows or page < 1: | ||
return "Page Out of Bounds", 404 | ||
|
||
is_rtp = ldap_is_rtp(auth_dict["uid"]) | ||
is_eboard = ldap_is_eboard(auth_dict["uid"]) | ||
|
||
# Retrieve list of files for templating | ||
db_files = File.query.filter_by(author=auth_dict["uid"]).all() | ||
db_files = query.offset((page-1) * 10).limit(10).all() | ||
harolds = get_harold_list(auth_dict["uid"]) | ||
tour_harolds = get_harold_list("root") | ||
return render_template("main.html", db_files=db_files, | ||
get_file_s3=get_file_s3, get_date_modified=get_date_modified, | ||
s3_bucket=s3_bucket, auth_dict=auth_dict, harolds=harolds, | ||
tour_harolds=tour_harolds, is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False) | ||
tour_harolds=tour_harolds, is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False, | ||
current="/mine", page=page, rows=rows, begin=max(1, page-6), | ||
end=min(page+6, rows) + 1) | ||
Comment on lines
+106
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above re |
||
|
||
@app.route("/selected") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def selected(auth_dict=None): | ||
is_rtp = ldap_is_rtp(auth_dict["uid"]) | ||
is_eboard = ldap_is_eboard(auth_dict["uid"]) | ||
def selected_def(auth_dict=None): | ||
return redirect("/selected/1") | ||
|
||
@app.route("/selected/<int:page>") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def selected(page, auth_dict=None): | ||
#Retrieve list of files for templating | ||
harolds = get_harold_list(auth_dict["uid"]) | ||
query = File.query.filter(File.file_hash.in_(harolds)) | ||
rows = query.count() | ||
rows = int(rows // 10 + bool(rows % 10)) | ||
|
||
if page > rows or page < 1: | ||
return "Page Out of Bounds", 404 | ||
|
||
is_rtp = ldap_is_rtp(auth_dict["uid"]) | ||
is_eboard = ldap_is_eboard(auth_dict["uid"]) | ||
|
||
tour_harolds = get_harold_list("root") | ||
db_files = File.query.filter(File.file_hash.in_(harolds)).all() | ||
db_files = query.offset((page-1) * 10).limit(10).all() | ||
return render_template("main.html", db_files=db_files, | ||
get_date_modified=get_date_modified, s3_bucket=s3_bucket, | ||
auth_dict=auth_dict, harolds=harolds, tour_harolds=tour_harolds, | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False) | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=False, | ||
current="/selected", page=page, rows=rows, begin=max(1, page-6), | ||
end=min(page+6, rows) + 1) | ||
Comment on lines
+139
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
@app.route("/tour_page") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def admin(auth_dict=None): | ||
def admin_def(auth_dict=None): | ||
return redirect("/tour_page/1") | ||
|
||
@app.route("/tour_page/<int:page>") | ||
@auth.oidc_auth('default') | ||
@audiophiler_auth | ||
def admin(page, auth_dict=None): | ||
tour_harolds = get_harold_list("root") | ||
query = File.query.filter(File.file_hash.in_(tour_harolds)) | ||
rows = query.count() | ||
rows = int(rows // 10 + bool(rows % 10)) | ||
|
||
if page > rows or page < 1: | ||
return "Page Out of Bounds", 404 | ||
|
||
is_rtp = ldap_is_rtp(auth_dict["uid"]) | ||
is_eboard = ldap_is_eboard(auth_dict["uid"]) | ||
|
||
if is_eboard or is_rtp: | ||
harolds = get_harold_list(auth_dict["uid"]) | ||
tour_harolds = get_harold_list("root") | ||
db_files = File.query.filter(File.file_hash.in_(tour_harolds)).all() | ||
db_files = query.offset((page-1) * 10).limit(10).all() | ||
return render_template("main.html", db_files=db_files, | ||
get_date_modified=get_date_modified, s3_bucket=s3_bucket, | ||
auth_dict=auth_dict, harolds=harolds, tour_harolds=tour_harolds, | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=True, is_tour_mode=get_tour_lock_status()) | ||
is_rtp=is_rtp, is_eboard=is_eboard, is_tour_page=True, is_tour_mode=get_tour_lock_status(), | ||
current="/tour_page", page=page, rows=rows, begin=max(1, page-6), end=min(page+6, rows) + 1) | ||
Comment on lines
+169
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return "Permission Denied", 403 | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -80,6 +80,36 @@ <h6>Owner: {{ file.author }} uploaded {{ get_date_modified(s3_bucket, file.file_ | |||||||||||||||||||
{% if not loop.index0 is divisibleby 2 %} | ||||||||||||||||||||
</div> | ||||||||||||||||||||
{% endif %} | ||||||||||||||||||||
{% if loop.index0 is divisibleby 2 and loop.last %} | ||||||||||||||||||||
</div> | ||||||||||||||||||||
{% endif %} | ||||||||||||||||||||
Comment on lines
80
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: this could be a bit more compact I think |
||||||||||||||||||||
{% endfor %} | ||||||||||||||||||||
<div class="col" align="center"> | ||||||||||||||||||||
<nav aria-label="page selector"> | ||||||||||||||||||||
<ul class="pagination pagination-lg justify-content-center"> | ||||||||||||||||||||
{% if page == 1 %} | ||||||||||||||||||||
<li class="page-item disabled"> | ||||||||||||||||||||
<a class="page-link" href="{{ current }}{{ page - 1 }}" tabindex="-1">Previous</a> | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would |
||||||||||||||||||||
{% else %} | ||||||||||||||||||||
<li class="page-item"> | ||||||||||||||||||||
<a class="page-link" href="{{ current }}/{{ page - 1 }}">Previous</a> | ||||||||||||||||||||
{% endif %} | ||||||||||||||||||||
</li> | ||||||||||||||||||||
{% for num in range(begin, end) %} | ||||||||||||||||||||
<li class="page-item"> | ||||||||||||||||||||
<a class="page-link" href="{{ current }}/{{ num }}">{{ num }}</a> | ||||||||||||||||||||
</li> | ||||||||||||||||||||
{% endfor %} | ||||||||||||||||||||
Comment on lines
+98
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plan to do anything special for the current page? |
||||||||||||||||||||
{% if page == rows %} | ||||||||||||||||||||
<li class="page-item disabled"> | ||||||||||||||||||||
<a class="page-link" href="{{ current }}/{{ page + 1 }}" tabindex="-1">Next</a> | ||||||||||||||||||||
{% else %} | ||||||||||||||||||||
<li class="page-item"> | ||||||||||||||||||||
<a class="page-link" href="{{ current }}/{{ page + 1 }}">Next</a> | ||||||||||||||||||||
{% endif %} | ||||||||||||||||||||
</li> | ||||||||||||||||||||
</ul> | ||||||||||||||||||||
</nav> | ||||||||||||||||||||
</div> | ||||||||||||||||||||
</div> | ||||||||||||||||||||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment on the naming of rows as your other pagination pr. this feels like it could be named better