From 3baf75e59ede14c2c3ba08e375388769c99b61ab Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sun, 19 May 2024 13:03:57 +1000 Subject: [PATCH 1/4] Remove unused CI config files and the like --- .gitlab-ci.yml | 21 --------------------- .pre-commit-config.yaml | 41 ----------------------------------------- .pyup.yml | 3 --- .travis.yml | 16 ---------------- Forwardfile | 4 ---- 5 files changed, 85 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 .pre-commit-config.yaml delete mode 100644 .pyup.yml delete mode 100644 .travis.yml delete mode 100644 Forwardfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 4acbf9d..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 86a47d3..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,41 +0,0 @@ -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] diff --git a/.pyup.yml b/.pyup.yml deleted file mode 100644 index 98f8319..0000000 --- a/.pyup.yml +++ /dev/null @@ -1,3 +0,0 @@ -requirements: - - Pipfile - - Pipfile.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d551f1a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -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 diff --git a/Forwardfile b/Forwardfile deleted file mode 100644 index 784befe..0000000 --- a/Forwardfile +++ /dev/null @@ -1,4 +0,0 @@ -# vim: set ft=yaml : -host: 00dani.dev -port: 443 -cname: dev.00dani.me From 8d8aa4749b80de2ee8c92f4ab1d2d84e263bbc26 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sun, 19 May 2024 13:04:19 +1000 Subject: [PATCH 2/4] Update year range in LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index f96fa75..c28ac8d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 - 2018 Danielle McLean +Copyright (c) 2017 - 2024 Danielle McLean Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From d21d4bda836aecb3653ec8589d643549ba9de68a Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sun, 19 May 2024 15:59:43 +1000 Subject: [PATCH 3/4] Paginate without errors if a page doesn't exist --- entries/pagination.py | 45 +++++++++++------------- lemoncurry/jinja2/lemoncurry/layout.html | 16 ++++----- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/entries/pagination.py b/entries/pagination.py index aa7c174..67d1897 100644 --- a/entries/pagination.py +++ b/entries/pagination.py @@ -1,35 +1,32 @@ -from django.core.paginator import Paginator +from typing import Callable + +from django.core.paginator import Page, Paginator from django.shortcuts import redirect from lemoncurry.middleware import ResponseException -def paginate(queryset, reverse, page): - class Page: - def __init__(self, i): - self.i = i +def paginate(queryset, reverse: Callable[[int], str], page: int | None) -> Page: + def redirect_to_page(i: int): + raise ResponseException(redirect(reverse(i))) - @property - def url(self): - 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)) + def reversible(p: Page) -> Page: + p.reverse = reverse + return p paginator = Paginator(queryset, 10) - entries = paginator.page(page or 1) - entries.pages = tuple(Page(i) for i in paginator.page_range) + # If no page number was specified, return page one. + if page is None: + return reversible(paginator.page(1)) - if entries.has_previous(): - entries.prev = Page(entries.previous_page_number()) - if entries.has_next(): - entries.next = Page(entries.next_page_number()) + # If the first page was explicitly requested, or the page number was negative, redirect to page one with no URL suffix. + if page <= 1: + redirect_to_page(1) - return entries + # If the page requested is larger than the last page, then redirect to the last page. + if page > paginator.num_pages: + redirect_to_page(paginator.num_pages) + + # Just return the current page! Hooray! + return reversible(paginator.page(page)) diff --git a/lemoncurry/jinja2/lemoncurry/layout.html b/lemoncurry/jinja2/lemoncurry/layout.html index 22308c3..322c461 100644 --- a/lemoncurry/jinja2/lemoncurry/layout.html +++ b/lemoncurry/jinja2/lemoncurry/layout.html @@ -110,29 +110,29 @@