Add package update configuration for polling

This commit is contained in:
rubenwardy
2020-12-15 19:05:29 +00:00
parent 7461acdd1f
commit 14a67b99ba
17 changed files with 327 additions and 10 deletions

View File

@@ -253,3 +253,30 @@ def nonEmptyOrNone(str):
return None
return str
def post_system_thread(package: Package, title: str, message: str):
system_user = User.query.filter_by(username="ContentDB").first()
assert system_user
thread = package.threads.filter_by(author=system_user).first()
if not thread:
thread = Thread()
thread.package = package
thread.title = "System Notifications"
thread.author = system_user
thread.private = True
thread.watchers.append(package.author)
db.session.add(thread)
db.session.flush()
reply = ThreadReply()
reply.thread = thread
reply.author = system_user
reply.comment = "# {}\n\n{}".format(title, message)
db.session.add(reply)
addNotification(thread.watchers, system_user, NotificationType.THREAD_REPLY,
title, thread.getViewURL(), thread.package)
thread.replies.append(reply)