diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a2802d..be3474e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,11 +24,11 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.1.0 hooks: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v2.31.0 + rev: v2.31.1 hooks: - id: pyupgrade args: @@ -37,9 +37,9 @@ repos: rev: 1.4.0 hooks: - id: django-upgrade - args: [--target-version, "3.2"] + args: [--target-version, "4.0"] - repo: https://github.com/rtts/djhtml - rev: v1.4.11 + rev: v1.5.0 hooks: - id: djhtml - repo: https://github.com/flakeheaven/flakeheaven @@ -57,12 +57,12 @@ repos: - flake8-noqa - pep8-naming - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.5.1 + rev: v2.6.1 hooks: - id: prettier types_or: [javascript, css] - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.7.0 + rev: v8.11.0 hooks: - id: eslint types_or: [javascript, css] diff --git a/poetry.lock b/poetry.lock index be7564c..ae7d94f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -440,8 +440,8 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" -python-versions = "^3.9" -content-hash = "66becd63613c6a294bb592257135a7f67fb03e4b9e0b1917ba9d6862b8316dd2" +python-versions = "^3.10" +content-hash = "b4862f3fb2a75ea6e86535e516d5d62d64b6eae9ca59b9d319d3bd89e9c2030e" [metadata.files] asgiref = [ diff --git a/pyproject.toml b/pyproject.toml index ef9e3fd..4bd8ff7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "" authors = ["Gabriel Augendre "] [tool.poetry.dependencies] -python = "^3.9" +python = "^3.10" requests = "^2.25.1" gunicorn = "^20.1.0" Django = "^4.0" @@ -25,7 +25,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.black] -target-version = ['py38'] +target-version = ['py310'] [tool.isort] profile = "black" diff --git a/src/redirect/admin.py b/src/redirect/admin.py index dd8ed28..dd9cc02 100644 --- a/src/redirect/admin.py +++ b/src/redirect/admin.py @@ -2,6 +2,7 @@ from django.contrib import admin from django.contrib.auth import get_permission_codename from django.contrib.auth.admin import UserAdmin from django.http import HttpRequest +from django.utils.safestring import mark_safe from redirect.models import Redirect @@ -10,7 +11,11 @@ from .models import RedirectUser @admin.register(Redirect) class RedirectAdmin(admin.ModelAdmin): - list_display = ["short_code", "owner", "group_owner", "target_url"] + list_display = ["short_code", "link", "owner", "group_owner", "target_url"] + + def changelist_view(self, request, extra_context=None): + self.request = request + return super().changelist_view(request, extra_context) def has_change_permission(self, request: HttpRequest, obj: Redirect = None): opts = self.opts @@ -29,5 +34,10 @@ class RedirectAdmin(admin.ModelAdmin): get_data["owner"] = request.user.pk return get_data + def link(self, instance: Redirect) -> str: + url = instance.get_absolute_url() + url = self.request.build_absolute_uri(url) + return mark_safe(f'link') + admin.site.register(RedirectUser, UserAdmin) diff --git a/src/redirect/models.py b/src/redirect/models.py index 666529e..fadb1b7 100644 --- a/src/redirect/models.py +++ b/src/redirect/models.py @@ -1,6 +1,7 @@ from django.conf import settings from django.contrib.auth.models import AbstractUser, Group from django.db import models +from django.urls import reverse class Redirect(models.Model): @@ -30,6 +31,9 @@ class Redirect(models.Model): def __str__(self): return f"{self.short_code} => {self.target_url}" + def get_absolute_url(self): + return reverse("redirect", args=(self.short_code,)) + class RedirectUser(AbstractUser): pass