1
Fork 0

added projects to index

This commit is contained in:
Jake Howard 2016-12-29 17:41:31 +00:00
parent 9769cc58c4
commit a5feb97f1b
3 changed files with 25 additions and 1 deletions

3
project/common/utils.py Normal file
View file

@ -0,0 +1,3 @@
def round_to_multiple(value, base):
return value - value % base

View file

@ -2,7 +2,9 @@ from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from project.blog.models import BlogPage
from project.projects.models import ProjectPage
from project.common.models import Entity
from project.common.utils import round_to_multiple
class HomePage(Entity):
@ -17,4 +19,7 @@ class HomePage(Entity):
def get_context(self, *args, **kwargs):
context = super().get_context(*args, **kwargs)
context['blog_posts'] = BlogPage.objects.live().order_by('-post_date')[:4]
projects = ProjectPage.objects.live().filter(search_image__isnull=False)
projects_to_show = round_to_multiple(projects.count(), 3) if projects.count() >= 3 else projects.count()
context['projects'] = projects[:projects_to_show]
return context

View file

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-homepage{% endblock %}
@ -77,6 +77,22 @@
<section id="projects">
<div class="container-fluid">
<div class="row no-gutter">
{% for project in projects %}
<div class="col-sm-4">
{% image project.image max-1000x1000 as project_image %}
<a href="{{ project.url }}" class="portfolio-box image" data-image="{{ project_image.url }}">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-name">
<h2>
{{ project.title }}
</h2>
</div>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
<div class="row">
<div class="col-xs-12 text-center">