Skip to content

Commit

Permalink
slight refactoring of get motds
Browse files Browse the repository at this point in the history
  • Loading branch information
Ina committed Aug 4, 2022
1 parent 794670c commit d2f5dda
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions dds_web/api/superadmin_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,20 @@ def post(self):
def get(self):
"""Return list of all active MOTDs to super admin."""
active_motds = models.MOTD.query.filter_by(active=True).all()
if active_motds:
motd_info = [
{
"MOTD ID": m.id,
"Message": m.message,
"Created": m.date_created.strftime("%Y-%m-%d %H:%M"),
}
for m in active_motds
]

return {
"motds": motd_info,
"keys": [
"MOTD ID",
"Message",
"Created",
],
}
else:
if not active_motds:
return {"message": "There are no active MOTDs."}

motd_info = [
{
"MOTD ID": m.id,
"Message": m.message,
"Created": m.date_created.strftime("%Y-%m-%d %H:%M"),
}
for m in active_motds
]

return {"motds": motd_info, "keys": ["MOTD ID", "Message", "Created"]}

@auth.login_required(role=["Super Admin"])
@logging_bind_request
@json_required
Expand Down

0 comments on commit d2f5dda

Please sign in to comment.