Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
4e9b7e32
Unverified
Commit
4e9b7e32
authored
Jan 10, 2018
by
Thom Wiggers
📐
Browse files
Refactor bannerdir to fix import in docs
parent
29a71089
Changes
1
Hide whitespace changes
Inline
Side-by-side
website/thaliawebsite/templatetags/pick_header_image.py
View file @
4e9b7e32
from
django
import
template
from
django.contrib.staticfiles.templatetags.staticfiles
import
static
import
functools
import
os
import
random
from
django
import
template
from
django.conf
import
settings
from
django.contrib.staticfiles
import
finders
register
=
template
.
Library
()
banner_dir
=
static
(
"/images/header_banners/"
)
current_dir
=
[
pic
for
pic
in
os
.
listdir
(
"thaliawebsite/"
+
banner_dir
)
if
pic
.
endswith
(
".jpg"
)]
bannerdir
=
'images/header_banners'
@
functools
.
lru_cache
()
def
_banners
():
imgdir
=
finders
.
find
(
bannerdir
)
return
[
pic
for
pic
in
os
.
listdir
(
imgdir
)
if
pic
.
endswith
(
'.jpg'
)]
@
register
.
simple_tag
def
pick_header_image
():
return
banner_dir
+
random
.
choice
(
current_dir
)
"""Renders a random header image"""
return
settings
.
STATIC_URL
+
bannerdir
+
'/'
+
random
.
choice
(
_banners
())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment