Commit 988848ef authored by Luuk Scholten's avatar Luuk Scholten
Browse files

Showcase two sponsors in header, in a randomly ordered list

parent 6cfa2491
from random import shuffle
from partners.models import Partner
def showcased_partners(request):
if 'partner_sequence' not in request.session:
partner_ids = [p.id for p in Partner.objects.filter(is_active=True)]
shuffle(partner_ids)
request.session['partner_sequence'] = partner_ids
sequence = request.session['partner_sequence']
chosen, rest = sequence[:2], sequence[2:]
request.session['partner_sequence'] = rest + chosen
partners = tuple(Partner.objects.get(id=id) for id in chosen)
return {'showcased_partners': partners}
<div id="partner-{{ position }}" class="partner-header">
<a href="{% url "partners:partner" partner.slug %}">
<img src="{{ partner.logo.url }}" alt="Logo {{ partner.name }}"/>
</a>
</div>
\ No newline at end of file
......@@ -81,6 +81,7 @@ TEMPLATES = [
'django.template.context_processors.media',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'partners.context_processors.showcased_partners',
],
},
},
......
......@@ -58,15 +58,15 @@
<!-- /#logo -->
<!-- #partner-left -->
<div id="partner-left" class="partner-header">
{% block partner_header_left %}{% endblock partner_header_left %}
</div>
{% if showcased_partners|length > 0 %}
{% include "partners/showcased_partner.html" with partner=showcased_partners.0 position="left" %}
{% endif %}
<!-- /#partner-left -->
<!-- #partner-right -->
<div id="partner-right" class="partner-header">
{% block partner_header_right %}{% endblock partner_header_right %}
</div>
{% if showcased_partners|length > 1 %}
{% include "partners/showcased_partner.html" with partner=showcased_partners.1 position="right" %}
{% endif %}
<!-- /#partner-right -->
</div>
<!-- /#logo-header -->
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment