1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +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 String
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from royalnet.web.shortcuts import to_urluuid
class WikiPage: class WikiPage:
@ -31,3 +32,7 @@ class WikiPage:
@declared_attr @declared_attr
def css(self): def css(self):
return Column(String) return Column(String)
@property
def page_short_id(self):
return to_urluuid(self.page_id)

View file

@ -19,7 +19,7 @@
{% endif %} {% endif %}
<ul> <ul>
{% for page in pages %} {% 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 %} {% endfor %}
</ul> </ul>
</div> </div>

View file

@ -9,8 +9,8 @@ def error(code, reason):
def to_urluuid(uuid: _uuid.UUID) -> str: def to_urluuid(uuid: _uuid.UUID) -> str:
"""Return a base64 url-friendly short UUID.""" """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: 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")))