Skip to content

Commit

Permalink
Merge pull request #892 from akvo/feature/890_v3_timeline
Browse files Browse the repository at this point in the history
[#890] Added first version of timeline
  • Loading branch information
kardan committed Nov 6, 2014
2 parents c68a752 + 8514d73 commit ca28054
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
4 changes: 2 additions & 2 deletions akvo/rsr/static/rsr/v3/css/src/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions akvo/rsr/static/rsr/v3/css/src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ header {
background: #ccc;
}
#timeline {
height: 200px;
background: #ccc;
height: 400px;
background: #FFFFFF;
}

/* UPDATE */
Expand Down
71 changes: 61 additions & 10 deletions akvo/rsr/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,67 @@

import json

from akvo.rsr.models import Project
from akvo.utils import pagination
from ..models import Invoice, Project
from ...utils import pagination

from django.shortcuts import get_object_or_404, render


def _get_accordion_data(project):
accordion_data = dict()
accordion_data['background'] = project.background
accordion_data['current_status'] = project.current_status
accordion_data['project_plan'] = project.project_plan
accordion_data['target_group'] = project.target_group
accordion_data['sustainability'] = project.sustainability
return accordion_data


def _get_timeline_data(project):
timeline_data = {'timeline': {'type': 'default'}}
timeline_dates = []

# Project start and end dates
date_start = (project.date_start_actual, 'Start', 'actual') if project.date_start_actual else \
(project.date_start_planned, 'Start', 'planned')
date_end = (project.date_end_actual, 'End', 'actual') if project.date_end_actual else \
(project.date_end_planned, 'End', 'planned') if project.date_end_planned else None

for date in (date_start, date_end):
if date:
timeline_dates.append({
'startDate': ','.join((str(date[0].year), str(date[0].month), str(date[0].day))),
'headline': date[1] + " date of project" if date[2] == 'actual' else date[1] +
" date of project (planned)",
})

# Project updates
for update in project.updates_desc():
date = update.last_modified_at
timeline_dates.append({
'startDate': ','.join((str(date.year), str(date.month), str(date.day))),
'headline': 'Project update added',
'text': '<a href="' + update.get_absolute_url() + '">' + update.title + '</a>',
'asset': {
'thumbnail': update.photo.url if update.photo else None,
'media': update.photo.url if update.photo else None,
}
})

# Donations
for donation in Invoice.objects.filter(project=project):
date = donation.time
timeline_dates.append({
'startDate': ','.join((str(date.year), str(date.month), str(date.day))),
'headline': 'Donation added',
'text': 'by ' + donation.name if donation.name else 'Anonymous',
})

timeline_data['timeline']['date'] = timeline_dates

return timeline_data


def _get_carousel_data(project):
photos = []
if project.current_image:
Expand All @@ -32,6 +87,7 @@ def _get_carousel_data(project):
return {"photos": photos}



def directory(request):
projects_list = Project.objects.published()
page = request.GET.get('page')
Expand All @@ -49,20 +105,15 @@ def directory(request):
def main(request, project_id):
project = get_object_or_404(Project, pk=project_id)
carousel_data = _get_carousel_data(project)

accordion_data = dict()
accordion_data['background'] = project.background
accordion_data['current_status'] = project.current_status
accordion_data['project_plan'] = project.project_plan
accordion_data['target_group'] = project.target_group
accordion_data['sustainability'] = project.sustainability

updates = project.project_updates.all().order_by('-created_at')
accordion_data = _get_accordion_data(project)
timeline_data = _get_timeline_data(project)

context = {
'accordion_data': json.dumps(accordion_data),
'carousel_data': json.dumps(carousel_data),
'project': project,
'timeline_data': json.dumps(timeline_data),
'updates': updates,
}

Expand Down
22 changes: 19 additions & 3 deletions akvo/templates/project_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@
}
};
</script>

<!-- Timeline -->
<link rel="stylesheet" type="text/css" href="http://cdn.knightlab.com/libs/timeline/latest/css/timeline.css">
<script type="text/javascript" src="http://cdn.knightlab.com/libs/timeline/latest/js/storyjs-embed.js"></script>

<script>
$(document).ready(function() {
var timeline_data = {{ timeline_data|safe }}

createStoryJS({
type: 'timeline',
width: '100%',
height: '400',
source: timeline_data,
embed_id: 'timeline'
});
});
</script>
{% endblock %}

{% block maincontent %}
Expand Down Expand Up @@ -77,9 +95,7 @@ <h4 class="section">Finance</h4>
</div>
<div class="row">
<div class="col-sm-12">
<div id="timeline">
TIMELINE
</div>
<div id="timeline"></div>
</div>
</div>
<div class="row">
Expand Down

0 comments on commit ca28054

Please sign in to comment.