nopaque/app/utils.py

11 lines
270 B
Python
Raw Normal View History

2021-11-30 15:22:16 +00:00
from app import hashids
from werkzeug.routing import BaseConverter
class HashidConverter(BaseConverter):
2021-12-07 13:18:05 +00:00
def to_python(self, value: str) -> int:
2021-11-30 15:22:16 +00:00
return hashids.decode(value)[0]
2021-12-07 13:18:05 +00:00
def to_url(self, value: int) -> str:
2021-11-30 15:22:16 +00:00
return hashids.encode(value)