Skip to content

Commit

Permalink
asset: fix dict comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 20, 2024
1 parent 9864703 commit 6865d52
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,34 @@ class Asset(NamedTuple):
moderated_by: Optional[str] = None

def to_dict(self, user_data=False, mod_data=False):
return (
{
"id": self.id,
"user": self.user,
"filetype": self.filetype,
"thumb": self.thumb,
"url": url_for("static", filename=cached_asset_name(self)),
}
| {
"state": self.state,
"starts": self.starts,
"ends": self.ends,
}
if user_data or mod_data
else {}
| (
result = {
"id": self.id,
"user": self.user,
"filetype": self.filetype,
"thumb": self.thumb,
"url": url_for("static", filename=cached_asset_name(self)),
}

if user_data or mod_data:
result.update(
{
"state": self.state,
"starts": self.starts,
"ends": self.ends,
}
)

if mod_data:
result.update(
{
"moderate_url": url_for(
"content_moderate", asset_id=self.id, _external=True
),
"moderated_by": self.moderated_by,
}
if mod_data
else {}
)
)

return result


def to_int(num):
Expand Down

0 comments on commit 6865d52

Please sign in to comment.