1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/home/models.py

26 lines
974 B
Python
Raw Normal View History

2016-11-22 21:50:21 +00:00
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
2016-12-29 15:47:09 +00:00
from project.blog.models import BlogPage
2016-12-29 17:41:31 +00:00
from project.projects.models import ProjectPage
2016-11-25 20:23:02 +00:00
from project.common.models import Entity
2016-12-29 17:41:31 +00:00
from project.common.utils import round_to_multiple
2016-11-22 21:50:21 +00:00
2016-11-25 20:23:02 +00:00
class HomePage(Entity):
2016-11-24 23:36:52 +00:00
is_home = True
2016-11-25 20:23:02 +00:00
2016-11-22 21:50:21 +00:00
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full")
]
2016-12-29 15:47:09 +00:00
def get_context(self, *args, **kwargs):
context = super().get_context(*args, **kwargs)
context['blog_posts'] = BlogPage.objects.live().order_by('-post_date')[:4]
2016-12-29 17:41:31 +00:00
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]
2016-12-29 15:47:09 +00:00
return context