mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
shorten wiki url
This commit is contained in:
parent
44053eef4e
commit
87c616e041
3 changed files with 8 additions and 3 deletions
|
@ -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)
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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")))
|
||||||
|
|
Loading…
Reference in a new issue