Compare commits
No commits in common. "e36ad27d491eb26b52c1017729cd7b46fafb5623" and "880b899e815bb4a5f38f16c782cf02ba28c6754d" have entirely different histories.
e36ad27d49
...
880b899e81
9 changed files with 119 additions and 33 deletions
21
.gitlab-ci.yml
Normal file
21
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
image: python:3.6
|
||||||
|
services:
|
||||||
|
- postgres:latest
|
||||||
|
variables:
|
||||||
|
GIT_SUBMODULE_STRATEGY: normal
|
||||||
|
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
|
||||||
|
PIPENV_CACHE_DIR: $CI_PROJECT_DIR/.cache/pipenv
|
||||||
|
POSTGRES_HOST: postgres
|
||||||
|
POSTGRES_DB: nice_marmot
|
||||||
|
POSTGRES_USER: runner
|
||||||
|
POSTGRES_PASSWORD: ''
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .cache
|
||||||
|
|
||||||
|
test:
|
||||||
|
script:
|
||||||
|
- pip install pipenv
|
||||||
|
- pipenv sync --dev
|
||||||
|
- pipenv run pytest
|
41
.pre-commit-config.yaml
Normal file
41
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.4.0
|
||||||
|
hooks:
|
||||||
|
- id: check-ast
|
||||||
|
- id: check-builtin-literals
|
||||||
|
- id: check-case-conflict
|
||||||
|
- id: check-docstring-first
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
|
- id: check-json
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- id: check-symlinks
|
||||||
|
- id: check-toml
|
||||||
|
- id: check-vcs-permalinks
|
||||||
|
- id: check-yaml
|
||||||
|
- id: destroyed-symlinks
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: fix-byte-order-marker
|
||||||
|
- id: mixed-line-ending
|
||||||
|
args:
|
||||||
|
- --fix=lf
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.7.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
language_version: python3.11
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: pytest
|
||||||
|
name: Check pytest unit tests pass
|
||||||
|
entry: poetry run pytest
|
||||||
|
pass_filenames: false
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
|
- id: mypy
|
||||||
|
name: Check mypy static types match
|
||||||
|
entry: poetry run mypy . --ignore-missing-imports
|
||||||
|
pass_filenames: false
|
||||||
|
language: system
|
||||||
|
types: [python]
|
3
.pyup.yml
Normal file
3
.pyup.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
requirements:
|
||||||
|
- Pipfile
|
||||||
|
- Pipfile.lock
|
16
.travis.yml
Normal file
16
.travis.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
language: python
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $PIP_CACHE_DIR
|
||||||
|
- $PIPENV_CACHE_DIR
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- PIP_CACHE_DIR=$HOME/.cache/pip
|
||||||
|
- PIPENV_CACHE_DIR=$HOME/.cache/pipenv
|
||||||
|
python:
|
||||||
|
- '3.6'
|
||||||
|
install:
|
||||||
|
- pip install pipenv
|
||||||
|
- pipenv install --dev
|
||||||
|
script:
|
||||||
|
- pipenv run pytest
|
4
Forwardfile
Normal file
4
Forwardfile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# vim: set ft=yaml :
|
||||||
|
host: 00dani.dev
|
||||||
|
port: 443
|
||||||
|
cname: dev.00dani.me
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2017 - 2024 Danielle McLean
|
Copyright (c) 2017 - 2018 Danielle McLean
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,32 +1,35 @@
|
||||||
from typing import Callable
|
from django.core.paginator import Paginator
|
||||||
|
|
||||||
from django.core.paginator import Page, Paginator
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
from lemoncurry.middleware import ResponseException
|
from lemoncurry.middleware import ResponseException
|
||||||
|
|
||||||
|
|
||||||
def paginate(queryset, reverse: Callable[[int], str], page: int | None) -> Page:
|
def paginate(queryset, reverse, page):
|
||||||
def redirect_to_page(i: int):
|
class Page:
|
||||||
raise ResponseException(redirect(reverse(i)))
|
def __init__(self, i):
|
||||||
|
self.i = i
|
||||||
|
|
||||||
def reversible(p: Page) -> Page:
|
@property
|
||||||
p.reverse = reverse
|
def url(self):
|
||||||
return p
|
return reverse(self.i)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current(self):
|
||||||
|
return self.i == entries.number
|
||||||
|
|
||||||
|
# If the first page was requested, redirect to the clean version of the URL
|
||||||
|
# with no page suffix.
|
||||||
|
if page == 1:
|
||||||
|
raise ResponseException(redirect(Page(1).url))
|
||||||
|
|
||||||
paginator = Paginator(queryset, 10)
|
paginator = Paginator(queryset, 10)
|
||||||
|
entries = paginator.page(page or 1)
|
||||||
|
|
||||||
# If no page number was specified, return page one.
|
entries.pages = tuple(Page(i) for i in paginator.page_range)
|
||||||
if page is None:
|
|
||||||
return reversible(paginator.page(1))
|
|
||||||
|
|
||||||
# If the first page was explicitly requested, or the page number was negative, redirect to page one with no URL suffix.
|
if entries.has_previous():
|
||||||
if page <= 1:
|
entries.prev = Page(entries.previous_page_number())
|
||||||
redirect_to_page(1)
|
if entries.has_next():
|
||||||
|
entries.next = Page(entries.next_page_number())
|
||||||
|
|
||||||
# If the page requested is larger than the last page, then redirect to the last page.
|
return entries
|
||||||
if page > paginator.num_pages:
|
|
||||||
redirect_to_page(paginator.num_pages)
|
|
||||||
|
|
||||||
# Just return the current page! Hooray!
|
|
||||||
return reversible(paginator.page(page))
|
|
||||||
|
|
|
@ -110,29 +110,29 @@
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{% if entries.has_previous() %}
|
{% if entries.prev %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" rel="prev" href="{{ entries.reverse(entries.previous_page_number()) }}">
|
<a class="page-link" rel="prev" href="{{ entries.prev.url }}">
|
||||||
<i class="fas fa-step-backward" aria-hidden="true"></i> <span class="sr-only">previous page</span>
|
<i class="fas fa-step-backward" aria-hidden="true"></i> <span class="sr-only">previous page</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for i in entries.paginator.page_range %}
|
{% for page in entries.pages %}
|
||||||
{% if i == entries.number %}
|
{% if page.current %}
|
||||||
<li class="page-item active">
|
<li class="page-item active">
|
||||||
<span class="page-link">{{ i }} <span class="sr-only">(current page)</span></span>
|
<span class="page-link">{{ page.i }} <span class="sr-only">(current page)</span></span>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{{ entries.reverse(i) }}">{{ i }}</a>
|
<a class="page-link" href="{{ page.url }}">{{ page.i }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if entries.has_next() %}
|
{% if entries.next %}
|
||||||
|
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" rel="next" href="{{ entries.reverse(entries.next_page_number()) }}">
|
<a class="page-link" rel="next" href="{{ entries.next.url }}">
|
||||||
<i class="fas fa-step-forward" aria-hidden="true"></i> <span class="sr-only">next page</span>
|
<i class="fas fa-step-forward" aria-hidden="true"></i> <span class="sr-only">next page</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -53,6 +53,7 @@ dependencies = [
|
||||||
"greenlet",
|
"greenlet",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.pdm]
|
||||||
[tool.pdm.dev-dependencies]
|
[tool.pdm.dev-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
"mypy",
|
"mypy",
|
||||||
|
@ -70,9 +71,6 @@ dev = [
|
||||||
[tool.pdm.build]
|
[tool.pdm.build]
|
||||||
includes = []
|
includes = []
|
||||||
|
|
||||||
[tool.ruff.lint]
|
|
||||||
select = ["E4", "E7", "E9", "F", "I"]
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["pdm-backend"]
|
requires = ["pdm-backend"]
|
||||||
build-backend = "pdm.backend"
|
build-backend = "pdm.backend"
|
||||||
|
|
Loading…
Reference in a new issue