Compare commits
5 commits
0ca50252dd
...
2f8d62649e
Author | SHA1 | Date | |
---|---|---|---|
2f8d62649e | |||
683adc1b46 | |||
cfeb206154 | |||
c5c0f4258b | |||
73addc2f75 |
14 changed files with 25 additions and 24 deletions
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'entries.apps.EntriesConfig'
|
|
|
@ -178,6 +178,7 @@ DATABASES = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'users.User'
|
AUTH_USER_MODEL = 'users.User'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from .base import *
|
from .base import *
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
META_SITE_DOMAIN = '00dani.dev'
|
META_SITE_DOMAIN = '00dani.lo'
|
||||||
META_FB_APPID = '142105433189339'
|
META_FB_APPID = '142105433189339'
|
||||||
STATIC_URL = 'https://static.00dani.dev/'
|
STATIC_URL = 'https://static.00dani.lo/'
|
||||||
MEDIA_URL = STATIC_URL + 'media/'
|
MEDIA_URL = 'https://media.00dani.lo/'
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'lemonshort.apps.LemonshortConfig'
|
|
|
@ -6,10 +6,11 @@ from string import ascii_lowercase, ascii_uppercase
|
||||||
chars = ascii_uppercase + ascii_lowercase
|
chars = ascii_uppercase + ascii_lowercase
|
||||||
conv = BaseConverter(chars)
|
conv = BaseConverter(chars)
|
||||||
|
|
||||||
|
class AbcIdConverter:
|
||||||
|
regex = '[a-zA-Z]+'
|
||||||
|
|
||||||
def abc_to_id(abc):
|
def to_python(self, value: str) -> int:
|
||||||
return int(conv.decode(abc))
|
return int(conv.decode(value))
|
||||||
|
|
||||||
|
def to_url(self, value: int) -> str:
|
||||||
def id_to_abc(id):
|
return conv.encode(value)
|
||||||
return conv.encode(id)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from typing import Any, Dict, Type
|
from typing import Any, Dict, Type
|
||||||
|
|
||||||
from .convert import id_to_abc
|
from .convert import AbcIdConverter
|
||||||
|
|
||||||
prefixes = {} # type: Dict[Type[Any], str]
|
prefixes = {} # type: Dict[Type[Any], str]
|
||||||
|
|
||||||
|
@ -14,4 +14,4 @@ def short_url(entity):
|
||||||
base = '/'
|
base = '/'
|
||||||
if hasattr(settings, 'SHORT_BASE_URL'):
|
if hasattr(settings, 'SHORT_BASE_URL'):
|
||||||
base = settings.SHORT_BASE_URL
|
base = settings.SHORT_BASE_URL
|
||||||
return base + prefixes[type(entity)] + id_to_abc(entity.id)
|
return base + prefixes[type(entity)] + AbcIdConverter().to_url(entity.id)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from .. import convert
|
from .. import convert
|
||||||
|
|
||||||
|
|
||||||
def test_abc_to_id():
|
def test_to_python():
|
||||||
samples = {
|
samples = {
|
||||||
'A': 0,
|
'A': 0,
|
||||||
'B': 1,
|
'B': 1,
|
||||||
|
@ -12,8 +12,9 @@ def test_abc_to_id():
|
||||||
'BA': 52,
|
'BA': 52,
|
||||||
'BAB': 2705,
|
'BAB': 2705,
|
||||||
}
|
}
|
||||||
|
converter = convert.AbcIdConverter()
|
||||||
for abc, id in samples.items():
|
for abc, id in samples.items():
|
||||||
assert convert.abc_to_id(abc) == id
|
assert converter.to_python(abc) == id
|
||||||
|
|
||||||
|
|
||||||
def test_id_to_abc():
|
def test_id_to_abc():
|
||||||
|
@ -26,5 +27,6 @@ def test_id_to_abc():
|
||||||
104: 'CA',
|
104: 'CA',
|
||||||
130: 'Ca',
|
130: 'Ca',
|
||||||
}
|
}
|
||||||
|
converter = convert.AbcIdConverter()
|
||||||
for id, abc in samples.items():
|
for id, abc in samples.items():
|
||||||
assert convert.id_to_abc(id) == abc
|
assert converter.to_url(id) == abc
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import path
|
from django.urls import path, register_converter
|
||||||
|
|
||||||
|
from .convert import AbcIdConverter
|
||||||
from .views import unshort
|
from .views import unshort
|
||||||
|
|
||||||
|
register_converter(AbcIdConverter, 'abc_id')
|
||||||
|
|
||||||
app_name = 'lemonshort'
|
app_name = 'lemonshort'
|
||||||
urlpatterns = tuple(
|
urlpatterns = tuple(
|
||||||
path('{0!s}<tiny>'.format(k), unshort, name=m, kwargs={'model': m})
|
path('{0!s}<abc_id:tiny>'.format(k), unshort, name=m, kwargs={'model': m})
|
||||||
for k, m in settings.SHORTEN_MODELS.items()
|
for k, m in settings.SHORTEN_MODELS.items()
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
|
||||||
from .convert import abc_to_id
|
from .convert import AbcIdConverter
|
||||||
|
|
||||||
|
|
||||||
def unshort(request, model, tiny):
|
def unshort(request, model, tiny):
|
||||||
entity = get_object_or_404(apps.get_model(model), pk=abc_to_id(tiny))
|
entity = get_object_or_404(apps.get_model(model), pk=tiny)
|
||||||
return redirect(entity, permanent=True)
|
return redirect(entity, permanent=True)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'micropub.apps.MicropubConfig'
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "lemoncurry",
|
"name": "lemoncurry",
|
||||||
"version": "1.10.3",
|
"version": "1.11.0",
|
||||||
"repository": "https://git.00dani.me/00dani/lemoncurry",
|
"repository": "https://git.00dani.me/00dani/lemoncurry",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'users.apps.UsersConfig'
|
|
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'webmention.apps.WebmentionConfig'
|
|
|
@ -1 +0,0 @@
|
||||||
default_app_config = 'wellknowns.apps.WellKnownsConfig'
|
|
Loading…
Reference in a new issue