1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

shorten wiki url

This commit is contained in:
Steffo 2019-07-11 16:00:32 +03:00
parent 44053eef4e
commit 87c616e041
3 changed files with 8 additions and 3 deletions

View file

@ -3,6 +3,7 @@ from sqlalchemy import Column, \
String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declared_attr
from royalnet.web.shortcuts import to_urluuid
class WikiPage:
@ -31,3 +32,7 @@ class WikiPage:
@declared_attr
def css(self):
return Column(String)
@property
def page_short_id(self):
return to_urluuid(self.page_id)

View file

@ -19,7 +19,7 @@
{% endif %}
<ul>
{% for page in pages %}
<li><a href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">{{ page.title }}</a></li>
<li><a href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_short_id, title=page.title) }}">{{ page.title }}</a></li>
{% endfor %}
</ul>
</div>

View file

@ -9,8 +9,8 @@ def error(code, reason):
def to_urluuid(uuid: _uuid.UUID) -> str:
"""Return a base64 url-friendly short UUID."""
return str(base64.urlsafe_b64encode(uuid.bytes), encoding="ascii")
return str(base64.urlsafe_b64encode(uuid.bytes), encoding="ascii").rstrip("=")
def from_urluuid(b: str) -> _uuid.UUID:
return _uuid.UUID(bytes=base64.urlsafe_b64decode(bytes(b, encoding="ascii")))
return _uuid.UUID(bytes=base64.urlsafe_b64decode(bytes(b + "==", encoding="ascii")))