Created random header image code

This commit is contained in:
Gergely Polonkai 2013-10-01 23:39:27 +02:00
parent a99ca61159
commit 414ff5b4a4
7 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,13 @@ from django.db.models import Count
from taggit.models import Tag from taggit.models import Tag
from math import floor from math import floor
from operator import itemgetter from operator import itemgetter
from django.conf import settings
import os
from random import choice
def randomheader(request):
header_file = choice(filter(lambda x: os.path.isfile(settings.HEADER_DIR + os.path.sep + x), os.listdir(settings.HEADER_DIR)))
return {'header': header_file}
def tagcloud(request): def tagcloud(request):
tagcloudlist = Tag.objects.annotate(ct=Count('taggit_taggeditem_items')).order_by('-ct') tagcloudlist = Tag.objects.annotate(ct=Count('taggit_taggeditem_items')).order_by('-ct')

View File

@ -131,6 +131,7 @@ INSTALLED_APPS = (
# Uncomment the next line to enable admin documentation: # Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs', # 'django.contrib.admindocs',
'blog', 'blog',
'basics',
) )
# A sample logging configuration. The only tangible logging # A sample logging configuration. The only tangible logging
@ -170,5 +171,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.static", "django.core.context_processors.static",
"django.core.context_processors.tz", "django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages", "django.contrib.messages.context_processors.messages",
'gergelypolonkai_django.taghelper.tagcloud', 'gergelypolonkai_django.helper.tagcloud',
'gergelypolonkai_django.helper.randomheader',
) )
HEADER_DIR = SITE_ROOT + os.path.sep + "static" + os.path.sep + "images" + os.path.sep + "header"

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -18,7 +18,7 @@
</head> </head>
<body> <body>
<div id="content-wrapper"> <div id="content-wrapper">
<div id="header" style="background-image: url('{% static "images/random_header.jpg" %}');"> <div id="header" style="background-image: url('{% static "images/header/"|add:header %}');">
<div id="picture"> <div id="picture">
<img src="{% static "images/profile.png" %}" alt="" /> <img src="{% static "images/profile.png" %}" alt="" />
</div> </div>