fluxscoreboard.util¶
Utility Functions¶
- fluxscoreboard.util.display_design(request)[source]¶
A function that returns True or False depending on whether the actual design should be displayed (True) or just a default one (False).
This is used to not disclose the real design until the CTF has started. The following logic is implemented:
- The admin backend has the default design (i.e. False).
- If it is a test-login from the backend, show the design.
- If the CTF has started, the real design is loaded for the frontpage (i.e. True).
- If no route is matched, the default design is loaded (False).
- Otherwise we fall back to not show the design (False).
The conditions are processed in order, i.e. the first match is returned.
- fluxscoreboard.util.random_token(length=64)[source]¶
Generate a random token hex-string of length characters. Due to it being encoded hex, its entropy is only half, so if you require a 256 bit entropy string, passing in 64 as length will yield exactly 64 / 2 * 8 = 256 bits entropy.
- fluxscoreboard.util.nl2br(text)[source]¶
Translate newlines into HTML <br /> tags.
- Usage:
<% from fluxscoreboard.util import nl2br %> ${some_string | nl2br}
- fluxscoreboard.util.random_str(len_, choice='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]¶
- fluxscoreboard.util.tz_str(timestamp, timezone=None)[source]¶
Create a localized timestring in a local timezone from the timezone-aware datetime.datetime object timestamp.
- class fluxscoreboard.util.not_logged_in(msg=None)[source]¶
Decorator for a view that should only be visible to users that are not logged in. They will be redirected to the frontpage and a message will be shown, that can be specified, but also has a sensible default.
- Usage:
@view_config(...) @not_logged_in() def some_view(request): pass