Use snake_case for method names

This commit is contained in:
rubenwardy
2023-06-19 21:27:49 +01:00
parent 16f93b3e13
commit 45ed12ddf0
53 changed files with 390 additions and 387 deletions

View File

@@ -27,7 +27,7 @@ from sqlalchemy.orm import sessionmaker
from app.models import User, NotificationType, Package, UserRank, Notification, db, AuditSeverity, AuditLogEntry, ThreadReply, Thread, PackageState, PackageType, PackageAlias
def getPackageByInfo(author, name):
def get_package_by_info(author, name):
user = User.query.filter_by(username=author).first()
if user is None:
return None
@@ -39,6 +39,7 @@ def getPackageByInfo(author, name):
return package
def is_package_page(f):
@wraps(f)
def decorated_function(*args, **kwargs):
@@ -48,9 +49,9 @@ def is_package_page(f):
author = kwargs["author"]
name = kwargs["name"]
package = getPackageByInfo(author, name)
package = get_package_by_info(author, name)
if package is None:
package = getPackageByInfo(author, name + "_game")
package = get_package_by_info(author, name + "_game")
if package and package.type == PackageType.GAME:
args = dict(kwargs)
args["name"] = name + "_game"
@@ -72,28 +73,28 @@ def is_package_page(f):
return decorated_function
def addNotification(target, causer: User, type: NotificationType, title: str, url: str, package: Package = None):
def add_notification(target, causer: User, type: NotificationType, title: str, url: str, package: Package = None):
try:
iter(target)
for x in target:
addNotification(x, causer, type, title, url, package)
add_notification(x, causer, type, title, url, package)
return
except TypeError:
pass
if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer:
if target.rank.at_least(UserRank.NEW_MEMBER) and target != causer:
Notification.query.filter_by(user=target, causer=causer, type=type, title=title, url=url, package=package).delete()
notif = Notification(target, causer, type, title, url, package)
db.session.add(notif)
def addAuditLog(severity: AuditSeverity, causer: User, title: str, url: typing.Optional[str],
package: Package = None, description: str = None):
def add_audit_log(severity: AuditSeverity, causer: User, title: str, url: typing.Optional[str],
package: Package = None, description: str = None):
entry = AuditLogEntry(causer, severity, title, url, package, description)
db.session.add(entry)
def clearNotifications(url):
def clear_notifications(url):
if current_user.is_authenticated:
Notification.query.filter_by(user=current_user, url=url).delete()
db.session.commit()
@@ -105,12 +106,12 @@ def get_system_user():
return system_user
def addSystemNotification(target, type: NotificationType, title: str, url: str, package: Package = None):
return addNotification(target, get_system_user(), type, title, url, package)
def add_system_notification(target, type: NotificationType, title: str, url: str, package: Package = None):
return add_notification(target, get_system_user(), type, title, url, package)
def addSystemAuditLog(severity: AuditSeverity, title: str, url: str, package=None, description=None):
return addAuditLog(severity, get_system_user(), title, url, package, description)
def add_system_audit_log(severity: AuditSeverity, title: str, url: str, package=None, description=None):
return add_audit_log(severity, get_system_user(), title, url, package, description)
def post_bot_message(package: Package, title: str, message: str):
@@ -133,8 +134,7 @@ def post_bot_message(package: Package, title: str, message: str):
reply.comment = "**{}**\n\n{}\n\nThis is an automated message, but you can reply if you need help".format(title, message)
db.session.add(reply)
addNotification(thread.watchers, system_user, NotificationType.BOT,
title, thread.get_view_url(), thread.package)
add_notification(thread.watchers, system_user, NotificationType.BOT, title, thread.get_view_url(), thread.package)
thread.replies.append(reply)