mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add Base.as_dict() and Base.json()
Two utility functions for all of our ORM models that will allow us to easily convert them to Python structures and JSON data. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
be3bab2ce0
commit
bd8f528011
3 changed files with 57 additions and 0 deletions
|
@ -3,6 +3,7 @@ import random
|
|||
import re
|
||||
import string
|
||||
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from email_validator import EmailNotValidError, EmailUndeliverableError, validate_email
|
||||
|
@ -94,3 +95,10 @@ def account_url(context, user):
|
|||
if request.url.scheme == "http" and request.url.port != 80:
|
||||
base += f":{request.url.port}"
|
||||
return f"{base}/account/{user.Username}"
|
||||
|
||||
|
||||
def jsonify(obj):
|
||||
""" Perform a conversion on obj if it's needed. """
|
||||
if isinstance(obj, datetime):
|
||||
obj = int(obj.timestamp())
|
||||
return obj
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue