Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show info about configured timezone in footer #78

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-howitz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ DEBUG = true
storage = "./howitz.sqlite3"
devmode = true
poll_interval = 30
timezone='LOCAL'

[zino.connections.default]
server =
Expand Down
5 changes: 3 additions & 2 deletions src/howitz/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


DEFAULT_STORAGE = "./howitz.sqlite3"
DEFAULT_TIMEZONE = 'UTC'


class ServerConfig(BaseModel):
Expand All @@ -28,10 +29,10 @@ class DevStorageConfig(StorageConfig):
class HowitzConfig(ServerConfig, StorageConfig):
devmode: bool = Literal[False]
poll_interval: int = 60
timezone: str = 'UTC'
timezone: str = DEFAULT_TIMEZONE


class DevHowitzConfig(DevServerConfig, DevStorageConfig):
devmode: bool = Literal[True]
poll_interval: int = 30
timezone: str = 'UTC'
timezone: str = DEFAULT_TIMEZONE
16 changes: 15 additions & 1 deletion src/howitz/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from zinolib.ritz import NotConnectedError, AuthenticationError

from howitz.users.utils import authenticate_user

from .config.models import DEFAULT_TIMEZONE
from .utils import login_check, date_str_without_timezone

main = Blueprint('main', __name__)
Expand Down Expand Up @@ -262,7 +264,19 @@ def get_event_details(id):
@main.route('/events')
@login_check()
def index():
return render_template('/views/events.html', poll_interval=current_app.howitz_config["poll_interval"])
return render_template('/views/events.html')


@main.get('/footer.html')
def footer():
tz = current_app.howitz_config["timezone"] # Get raw string from config. Accepted values are 'UTC' or 'LOCAL'.
if tz == 'LOCAL': # Change to a specific timezone name if 'LOCAL'
tz = datetime.now(timezone.utc).astimezone().tzinfo
elif not tz == DEFAULT_TIMEZONE: # Fall back to default if invalid value is provided
tz = f"{DEFAULT_TIMEZONE} (default)"

return render_template('/components/footer/footer.html', poll_interval=current_app.howitz_config["poll_interval"],
timezone=tz)


@main.route('/login')
Expand Down
9 changes: 7 additions & 2 deletions src/howitz/templates/components/footer/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<footer class="bg-slate-950">
<p class="p-2 text-white text-semibold">
<footer hx-get="/footer.html"
hx-trigger="load"
class="bg-slate-950">
<p class="p-2 text-white text-semibold inline-block">
Updating every {{ poll_interval }}s.
</p>
<p class="p-2 text-white text-semibold inline-block">
Configured timezone is {{ timezone }}.
</p>
</footer>
Loading