Skip to content

Commit

Permalink
Merge branch 'shrivaths/changelog-announcement-2' into shrivaths/chan…
Browse files Browse the repository at this point in the history
…gelog-announcement-3
  • Loading branch information
shrivaths16 committed Dec 5, 2023
2 parents 944428f + 59f07ae commit 793faa6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions sleap/gui/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,24 @@ def _read_bulletin_data(self) -> Optional[Dict]:
except FileNotFoundError:
self._latest_data = None

@property
def new_announcement_available(self):
def new_announcement_available(self) -> bool:
"""Check if latest announcement is available."""
self._read_bulletin_data()
latest_date = datetime.strptime(self._latest_data["date"], "%m/%d/%Y")
previous_date = datetime.strptime(self.previous_announcement_date, "%m/%d/%Y")
if (
self._latest_data
and self.previous_announcement_date
and latest_date > previous_date
):
if self.previous_announcement_date and self._latest_data:
latest_date = datetime.strptime(self._latest_data["date"], "%m/%d/%Y")
previous_date = datetime.strptime(
self.previous_announcement_date, "%m/%d/%Y"
)
if latest_date > previous_date:
return True
else:
return False
else:
return True
return False

def get_latest_announcement(self) -> Optional[Tuple[str, str, str]]:
"""Return latest announcements on the releases page not seen by user."""
if self.new_announcement_available:
if self.new_announcement_available():
return (
self._latest_data["title"],
self._latest_data["date"],
Expand All @@ -203,7 +205,8 @@ def update_announcement(self):
if announcement is None:
return
self.state["announcement last seen date"] = announcement[1]
self.state["announcement"] = announcement[2]
new_announcement = "\n".join(announcement[2].split("\n"))
self.state["announcement"] = "## " + announcement[0] + "\n" + new_announcement


def get_analytics_data() -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion tests/gui/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_announcementchecker(bulletin_json_path):
# Check if announcement is updated
checker.update_announcement()
assert context.state["announcement last seen date"] == "10/12/2023"
assert context.state["announcement"] == "New announcement"
assert context.state["announcement"] == "## title1\nNew announcement"

# Create dummy JSON file
bulletin_data = [
Expand Down

0 comments on commit 793faa6

Please sign in to comment.