Skip to content

Commit

Permalink
Replace the __json__() method by as_dict()
Browse files Browse the repository at this point in the history
The "json" name is misleading as it does not, in fact, return JSON.

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
  • Loading branch information
abompard committed Apr 16, 2024
1 parent d163926 commit c0d8702
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tahrir_api/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def _adjust_ranks(self, person, old_rank):

self.session.flush()

body = dict(person=person.__json__(), old_rank=old_rank)
body = dict(person=person.as_dict(), old_rank=old_rank)
if self.notification_callback:
self.notification_callback(PersonRankAdvanceV1(body=body))

Expand Down
24 changes: 12 additions & 12 deletions tahrir_api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Issuer(DeclarativeBase):
def __str__(self):
return str(self.name)

def __json__(self):
def as_dict(self):
return dict(
origin=self.origin,
name=self.name,
Expand Down Expand Up @@ -58,7 +58,7 @@ class Badge(DeclarativeBase):
def __str__(self):
return str(self.name)

def __json__(self):
def as_dict(self):
if self.image.startswith("http"):
image = self.image
else:
Expand All @@ -69,7 +69,7 @@ def __json__(self):
image=image,
description=self.description,
criteria=self.criteria,
issuer=self.issuer.__json__(),
issuer=self.issuer.as_dict(),
created_on=time.mktime(self.created_on.timetuple()),
tags=self.tags,
)
Expand All @@ -90,7 +90,7 @@ class Team(DeclarativeBase):
series = relationship("Series", backref="team")
created_on = Column(DateTime, nullable=False, default=datetime.datetime.now)

def __json__(self):
def as_dict(self):
return dict(id=self.id, name=self.name, created_on=str(self.created_on))


Expand All @@ -110,13 +110,13 @@ class Series(DeclarativeBase):
milestone = relationship("Milestone", backref="series")
team_id = Column(Unicode(128), ForeignKey("team.id"), nullable=False)

def __json__(self):
def as_dict(self):
return dict(
id=self.id,
name=self.name,
created_on=str(self.created_on),
last_updated=str(self.last_updated),
team=self.team.__json__(),
team=self.team.as_dict(),
)


Expand All @@ -128,10 +128,10 @@ class Milestone(DeclarativeBase):
badge_id = Column(Unicode(128), ForeignKey("badges.id"), nullable=False)
series_id = Column(Unicode(128), ForeignKey("series.id"), nullable=False)

def __json__(self):
def as_dict(self):
return dict(
position=self.position,
badge=self.badge.__json__(),
badge=self.badge.as_dict(),
series_id=self.series.id,
)

Expand Down Expand Up @@ -174,7 +174,7 @@ def email_sha1(self):
def __str__(self):
return str(self.email)

def __json__(self):
def as_dict(self):
return dict(
email=self.email,
id=self.id,
Expand Down Expand Up @@ -262,8 +262,8 @@ def __str__(self):
def _recipient(self):
return f"sha256${self.recipient}"

def __json__(self):
result = dict(recipient=self._recipient, salt=self.salt, badge=self.badge.__json__())
def as_dict(self):
result = dict(recipient=self._recipient, salt=self.salt, badge=self.badge.as_dict())
# Eliminate this check since I made issued_on not nullable?
if self.issued_on:
result["issued_on"] = self.issued_on.strftime("%Y-%m-%d")
Expand All @@ -282,7 +282,7 @@ def __pygments__(self):
html_args = {"full": False}
pretty_encoder = simplejson.encoder.JSONEncoder(indent=2)
html = pygments.highlight(
pretty_encoder.encode(self.__json__()),
pretty_encoder.encode(self.as_dict()),
pygments.lexers.JavascriptLexer(),
pygments.formatters.HtmlFormatter(**html_args),
).strip()
Expand Down

0 comments on commit c0d8702

Please sign in to comment.