Skip to content

Commit

Permalink
Merge pull request #442 from ox-it/date-tabs-in-browse
Browse files Browse the repository at this point in the history
Date tabs in browse - 3067
  • Loading branch information
ahaith committed May 3, 2016
2 parents 6b3d5b7 + 9113dff commit 1029465
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
5 changes: 4 additions & 1 deletion static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ a.formatting-link:hover {
.nav-tabs {
border-bottom: 0;
}
.nav-tabs.nav-justified a {
white-space: nowrap;
}
div.add-to-collections,
div.manage-lists-buttons {
display: inline-block;
Expand Down Expand Up @@ -157,4 +160,4 @@ div.share-this-links span {
}
.active-collection {
background-color: #E4F0FC;
}
}
46 changes: 42 additions & 4 deletions talks/events/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import date, timedelta
from datetime import date, timedelta, datetime

from django.core.urlresolvers import reverse
from django.http.response import Http404
Expand Down Expand Up @@ -60,10 +60,7 @@ def browse_events(request):
modified_request_parameters['subdepartments'] = "false"
if (len(request.GET) == 0) or (len(request.GET) == 1) and request.GET.get('limit_to_collections'):
today = date.today()
defaultEndDate = date.today() + timedelta(days=7*8)
modified_request_parameters['start_date'] = today.strftime("%Y-%m-%d")
if len(request.GET) == 0:
modified_request_parameters['to'] = defaultEndDate.strftime("%Y-%m-%d")
modified_request_parameters['include_subdepartments'] = True
modified_request_parameters['subdepartments'] = 'true'
elif request.GET.get('include_subdepartments'):
Expand Down Expand Up @@ -103,13 +100,54 @@ def browse_events(request):

fragment = '&'.join(["{k}={v}".format(k=k, v=v) for k, v in args.iteritems()])

old_query = request.META['QUERY_STRING']
dates_start = old_query.find("start_date=")
dates_end = dates_start + 35
today = date.today()
offset_Sunday = (6 - today.weekday()) % 7 # weekday(): Monday=0 .... Sunday=6
tab_dates = [
{
'label': 'All',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today) + old_query[dates_end:],
'active': False
}, {
'label': 'Today',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today) + '&to=' + str(today) + old_query[dates_end:],
'active': False
}, {
'label': 'Tomorrow',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today+timedelta(days=1)) + '&to=' + str(today+timedelta(days=1)) + old_query[dates_end:],
'active': False
}, {
'label': 'This week',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today) + '&to=' + str(today+timedelta(days=offset_Sunday)) + old_query[dates_end:],
'active': False
}, {
'label': 'Next week',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today+timedelta(days=offset_Sunday+1)) + '&to=' + str(today+timedelta(days=offset_Sunday+7)) + old_query[dates_end:],
'active': False
}, {
'label': 'Next 30 days',
'href': 'browse?' + old_query[:dates_start] + 'start_date='+ str(today) + '&to=' + str(today+timedelta(days=30)) + old_query[dates_end:],
'active': False
}
]

if not old_query:
tab_dates[0]['active'] = True
else:
for tab in tab_dates:
if tab['href'] == 'browse?' + old_query:
tab['active'] = True

context = {
'events': events,
'grouped_events': grouped_events,
'fragment': fragment,
'browse_events_form': browse_events_form,
'start_date': modified_request_parameters.get('start_date'),
'end_date': modified_request_parameters.get('to'),
'tab_dates': tab_dates,
}
return render(request, 'events/browse.html', context)

Expand Down
10 changes: 10 additions & 0 deletions talks/templates/events/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ <h3>Filters</h3>
{% block main %}


<ul class="nav nav-tabs nav-justified">
{% for tab in tab_dates %}
<li role="presentation" {% if tab.active %}class="active"{% endif %}>
<a href="{{tab.href}}">
{{tab.label}}
</a>
</li>
{% endfor %}
</ul>

<div class="js-upcoming-events">
{% if grouped_events %}
{% include 'events/_event_list.html' with show_event_time_only=True %}
Expand Down

0 comments on commit 1029465

Please sign in to comment.