1
0
mirror of https://github.com/djohnlewis/stackdump synced 2024-12-04 23:17:37 +00:00

Added method to make site logos appear if they exist, otherwise show unknown icon.

This commit is contained in:
Samuel Lai 2011-11-05 12:13:16 +11:00
parent dc7a923fa9
commit 365acbe80a
5 changed files with 22 additions and 4 deletions

View File

@ -19,3 +19,6 @@ tutorial/.*$
# Solr/Jetty
^java/solr/server/work/.*
^java/solr/server/solr/data/.*
# ignore the downloaded logos
^python/media/images/logos/.*

View File

@ -69,11 +69,13 @@
.available-sites img {
float: left;
margin-right: 7px;
}
.available-sites h6 {
padding-top: 7px;
line-height: normal;
margin-left: 55px; /* 48px for the logo, 7px for the padding */
}
.available-sites .tagline {

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

View File

@ -18,6 +18,19 @@ TEMPLATE_ENV = Environment(loader=PackageLoader('stackdump', 'templates'))
# WEB REQUEST METHODS
# this method MUST sit above the generic static media server, otherwise it won't
# be hit and you will get 'file not found' errors when looking for a
# non-existent logo.
@route('/media/logos/:site_key#[\w\.]+#.png')
def site_logos(site_key):
root = os.path.join(MEDIA_ROOT, 'images/logos')
filename = '%s.png' % site_key
path = os.path.join(root, filename)
if os.path.exists(path):
return static_file(filename, root=root)
else:
return static_file('images/unknown_site_logo.png', root=MEDIA_ROOT)
# Bottle will protect us against nefarious peeps using ../ hacks.
@route('/media/:filename#.*#')
def serve_static(filename):
@ -30,8 +43,8 @@ def index():
context['sites'] = Site.select()
return render_template('index.html', context)
@route('/:site_key#\w+#')
@route('/:site_key#\w+#/')
@route('/:site_key#[\w\.]+#')
@route('/:site_key#[\w\.]+#/')
def site_index(site_key):
context = { }
context['site_root_path'] = '%s/' % site_key
@ -62,7 +75,7 @@ def search():
return render_template('results.html', context)
@route('/:site_key#\w+#/search')
@route('/:site_key#[\w\.]+#/search')
def site_search(site_key):
context = { }
context['site_root_path'] = '%s/' % site_key

View File

@ -37,7 +37,7 @@
<ul class="available-sites">
{% for s in sites %}
<li>
<img src="{{ SETTINGS.APP_URL_ROOT }}media/images/logos/{{ s.key }}.png" alt="{{ s.name }} logo" />
<img src="{{ SETTINGS.APP_URL_ROOT }}media/logos/{{ s.key }}.png" alt="{{ s.name }} logo" />
<h6>
<a href="{{ SETTINGS.APP_URL_ROOT }}{{ s.key }}/">{{ s.name }}</a>
<small class="tagline">{{ s.dump_date }}</small>