Skip to content

Commit

Permalink
Småjusteringer på last_seen_td_html
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Sep 14, 2023
1 parent 84336de commit 4fd3b26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 13 additions & 6 deletions BookingSystem/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ def last_seen_td_html(self) -> str:
if not self.last_seen:
return ''
parsed = parser.parse(self.last_seen)
# Show last seen within 3hrs as new (color in table)
within_3hrs = 'class="last-seen-new"' if parsed > datetime.now() - timedelta(hours=3) else ''
# 1yr = 1 school year (300 days) (color in table)
over_1yr = 'class="last-seen-old"' if parsed < datetime.now() - timedelta(days=300) else ''
inject_class = f'{within_3hrs}{over_1yr}'
now = datetime.now()
innertext = parsed.strftime('%d.%m.%Y')

# Modify text and class if necessary (recently seen, stale)
inject_class = ''
if parsed > now - timedelta(hours=3):
innertext = 'Nå nettopp'
inject_class = ' class="last-seen-recent"'
elif parsed < now - timedelta(days=300): # School year is ~300 days (10 months)
innertext += ' <i class="fa fa-warning"></i>'
inject_class = ' class="last-seen-stale"'

# Construct HTML
return f"<td data-sort=\"{self.last_seen}\"{inject_class}>{parsed.strftime('%d.%m.%Y')}</td>"
return f'<td data-sort="{self.last_seen}"{inject_class}>{innertext}</td>'

@property
def user(self) -> dict:
Expand Down
8 changes: 4 additions & 4 deletions BookingSystem/templates/partials/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
color: var(--form-element-color);
}

.last-seen-new {
color: var(--form-element-valid-active-border-color);
.last-seen-recent {
font-style: italic;
}

.last-seen-old {
color: var(--form-element-invalid-active-border-color);
.last-seen-stale {
color: var(--del-color);
}

/* Use the same max-width as body main */
Expand Down

0 comments on commit 4fd3b26

Please sign in to comment.