-# Content DB
+# ContentDB
# Copyright (C) 2018 rubenwardy
#
# This program is free software: you can redistribute it and/or modify
from . import app
import random, string, os, imghdr
from urllib.parse import urljoin
+from werkzeug.datastructures import MultiDict
+
+# These are given to Jinja in template_filters.py
def abs_url_for(path, **kwargs):
scheme = "https" if app.config["BASE_URL"][:5] == "https" else "http"
def abs_url(path):
return urljoin(app.config["BASE_URL"], path)
+def url_set_query(**kwargs):
+ args = MultiDict(request.args)
+
+ for key, value in kwargs.items():
+ if key == "_add":
+ for key2, value_to_add in value.items():
+ values = set(args.getlist(key2))
+ values.add(value_to_add)
+ args.setlist(key2, list(values))
+ elif key == "_remove":
+ for key2, value_to_remove in value.items():
+ values = set(args.getlist(key2))
+ values.discard(value_to_remove)
+ args.setlist(key2, list(values))
+ else:
+ args.setlist(key, [ value ])
+
+
+ dargs = dict(args.lists())
+
+ return url_for(request.endpoint, **dargs)
+
def get_int_or_abort(v, default=None):
if v is None:
return default
return decorated_function
-def addNotification(target, causer, title, url):
+def addNotification(target, causer, title, url, package=None):
try:
iter(target)
for x in target:
- addNotification(x, causer, title, url)
+ addNotification(x, causer, title, url, package)
return
except TypeError:
pass
if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer:
- Notification.query.filter_by(user=target, causer=causer, title=title, url=url).delete()
- notif = Notification(target, causer, title, url)
+ Notification.query.filter_by(user=target, causer=causer, title=title, url=url, package=package).delete()
+ notif = Notification(target, causer, title, url, package)
db.session.add(notif)
+def addAuditLog(severity, causer, title, url, package=None, description=None):
+ entry = AuditLogEntry(causer, severity, title, url, package, description)
+ db.session.add(entry)
+
+
def clearNotifications(url):
if current_user.is_authenticated:
Notification.query.filter_by(user=current_user, url=url).delete()
def isNo(val):
return val and not isYes(val)
+
+def nonEmptyOrNone(str):
+ if str is None or str == "":
+ return None
+
+ return str