mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* Make it possible to display the TOTP secret in text form instead of QR code only #947 * Show username *and* email address when user is logged in #484 * fix asn auto tool #959 * Trigger IX-F import when network sets allow_ixp_update to "yes" #499 * Ops: Log Melissa payload in django.log #1150 * Error-handling of failed creation of DeskPRO ticket #981 * email management changes #267 #736 #737 #738 #907 * block api write operations when using basic-auth to authenticate an MFA enabled account * add robots txt #1213 * DB clean-up of elderly ophaned user accounts #380 * linting * fix migrations * fix tests * dont flag new users for deletion * linting * docs Co-authored-by: dpoarch <dpoarch@20c.com>
38 lines
959 B
Python
38 lines
959 B
Python
"""
|
|
Assorted utility functions for peeringdb site templates.
|
|
"""
|
|
import ipaddress
|
|
from decimal import Decimal
|
|
|
|
from django_grainy.util import Permissions, check_permissions, get_permissions # noqa
|
|
|
|
from peeringdb_server.permissions import APIPermissionsApplicator # noqa
|
|
|
|
|
|
def disable_auto_now_and_save(entity):
|
|
updated_field = entity._meta.get_field("updated")
|
|
updated_field.auto_now = False
|
|
entity.save()
|
|
updated_field.auto_now = True
|
|
|
|
|
|
def round_decimal(value, places):
|
|
if value is not None:
|
|
return value.quantize(Decimal(10) ** -places)
|
|
return value
|
|
|
|
|
|
def coerce_ipaddr(value):
|
|
"""
|
|
ipaddresses can have multiple formats that are equivalent.
|
|
This function will standardize a ipaddress string.
|
|
|
|
Note: this function is not a validator. If it errors
|
|
It will return the original string.
|
|
"""
|
|
try:
|
|
value = str(ipaddress.ip_address(value))
|
|
except ValueError:
|
|
pass
|
|
return value
|