Skip to content

Commit

Permalink
Merge pull request #39 from etalab/editorial
Browse files Browse the repository at this point in the history
Use editorial selection in homepage for dataset and reuse
  • Loading branch information
noirbizarre committed Jun 1, 2015
2 parents 61d8d92 + 1714fac commit 1675c8c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 63 deletions.
22 changes: 9 additions & 13 deletions udata/core/site/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from udata.frontend import csv
from udata.frontend.views import DetailView
from udata.i18n import I18nBlueprint, lazy_gettext as _
from udata.models import Dataset, Activity, Site, Reuse, Organization
from udata.models import Dataset, Activity, Site, Reuse, Organization, Post
from udata.utils import multi_to_dict

from udata.core.activity.views import ActivityView
Expand Down Expand Up @@ -68,20 +68,16 @@ def activity_feed():
return feed.get_response()


def default_home_context_processor(context):
recent_datasets, recent_reuses = search.multiquery(
search.SearchQuery(Dataset, sort='-created', page_size=12),
search.SearchQuery(Reuse, sort='-created', page_size=12),
)
context.update(recent_datasets=recent_datasets, recent_reuses=recent_reuses)
return context


@blueprint.route('/')
def home():
context = {}
processor = theme.current.get_processor('home', default_home_context_processor)
return theme.render('home.html', **processor(context))
context = {
'recent_datasets': Dataset.objects.visible().order_by('-created_at'),
'recent_reuses': Reuse.objects(featured=True).visible().order_by('-created_at'),
'last_post': Post.objects(private=False).order_by('-created_at').first(),
}
processor = theme.current.get_processor('home')
context = processor(context)
return theme.render('home.html', **context)


@noI18n.route('/robots.txt')
Expand Down
87 changes: 42 additions & 45 deletions udata/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,94 +23,91 @@

<!-- Wrapper for slides -->
<div class="carousel-inner">
{% if last_post %}
<div class="item active">
<div class="container">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Titre de l'actu
<h1 class="page-header">{{last_post.name}}
<small>Actualité du moment</small>
</h1>
</div>
</div>

<div class="row">
<div class="col-md-7">
<img class="img-responsive" src="http://placehold.it/650x300&text=Actualité">
<img class="img-responsive" src="{{last_post.image}}">
</div>
<div class="col-md-5">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae. Sed dui lorem, adipiscing in adipiscing et, interdum nec metus. Mauris ultricies, justo eu convallis placerat, felis enim.</p>
<h3>Project Details</h3>
<ul>
<li>Lorem Ipsum</li>
<li>Dolor Sit Amet</li>
<li>Consectetur</li>
<li>Adipiscing Elit</li>
</ul>
{{ last_post.headline }}
</div>
</div>

</div>
</div>
{% endif %}

<div class="item">
<div class="container">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Une réutilisation
<small>Réutilisation</small>
<h1 class="page-header">
{{ _('Featured datasets') }}
</h1>
</div>
</div>

<div class="row">
<ul class="card-list">
{% for dataset in current_site.settings.home_datasets %}
<li class="col-md-4 col-sm-6">
{% include theme('dataset/card.html') %}
</li>
{% endfor %}
</ul>
</div>

</div>
</div>
{% for reuse in current_site.settings.home_reuses %}
<div class="item">
<div class="container">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
{{reuse.title}}
<small>{{ _('Reuse')}}</small>
</h1>
</div>
</div>

<div class="row">
<div class="col-md-7">
<img class="img-responsive" src="http://placehold.it/650x300">
<img class="img-responsive" src="{{reuse.image}}">
</div>
<div class="col-md-5">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae. Sed dui lorem, adipiscing in adipiscing et, interdum nec metus. Mauris ultricies, justo eu convallis placerat, felis enim.</p>
<p>{{reuse.description | mdstrip(300) }}</p>

<div class="row">
<div class="col-lg-12">
<h3 class="page-header">Jeux de données utilisés</h3>
</div>

<div class="col-sm-3 col-xs-6">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x200">
</a>
</div>

<div class="col-sm-3 col-xs-6">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x200">
</a>
<h3 class="page-header">{{ _('Used datasets') }}</h3>
</div>

<div class="col-sm-3 col-xs-6">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x200">
</a>
</div>

<div class="col-sm-3 col-xs-6">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x200">
</a>
{% for dataset in reuse.datasets[:4] %}
<div class="col-xs-6">
{% include theme('dataset/card.html') %}
</div>
{% endfor %}
</div>
</div>
</div>

</div>
</div>
<div class="item">
<div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide Two');"></div>
<div class="carousel-caption">
<h1>Ready to Style &amp; Add Content</h1>
</div>
</div>
{% endfor %}
</div>

<!-- Controls -->
Expand All @@ -129,7 +126,7 @@ <h1>Ready to Style &amp; Add Content</h1>
<h2>{{ _('Last datasets') }}</h2>
</div>
<ul class="card-list">
{% for dataset in recent_datasets %}
{% for dataset in recent_datasets[:9] %}
<li class="col-md-4 col-sm-6">
{% include theme('dataset/card.html') %}
</li>
Expand All @@ -146,7 +143,7 @@ <h2>{{ _('Last datasets') }}</h2>
<h2>{{ _('Last reuses') }}</h2>
</div>
<ul class="card-list">
{% for reuse in recent_reuses %}
{% for reuse in recent_reuses[:9] %}
<li class="col-md-4 col-sm-6">{% include theme('reuse/card.html') %}</li>
{% endfor %}
</ul>
Expand Down
12 changes: 7 additions & 5 deletions udata/tests/site/test_site_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def test_render_robotstxt(self):

def test_render_home(self):
'''It should render the home page'''
with self.autoindex():
for i in range(3):
org = OrganizationFactory()
DatasetFactory(organization=org)
ReuseFactory(organization=org)
for i in range(3):
org = OrganizationFactory()
DatasetFactory(organization=org)
ReuseFactory(organization=org)

current_site.settings.home_datasets = [DatasetFactory() for _ in range(3)]
current_site.settings.home_reuses = [ReuseFactory() for _ in range(3)]

response = self.get(url_for('site.home'))
self.assert200(response)
Expand Down

0 comments on commit 1675c8c

Please sign in to comment.