|
1
|
|
|
import logging |
|
2
|
|
|
|
|
3
|
|
|
from fullcalendar.views import OccurrenceView |
|
4
|
|
|
|
|
5
|
|
|
from website.jdpages.models import HomePage |
|
6
|
|
|
from website.jdpages.models import SidebarSocial |
|
7
|
|
|
from website.jdpages.models import PageHeaderImage |
|
8
|
|
|
|
|
9
|
|
|
logger = logging.getLogger(__name__) |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
def get_page_header(page): |
|
13
|
|
|
""" |
|
14
|
|
|
:returns: the page header for a given page. |
|
15
|
|
|
Uses parent page image when none is defined. |
|
16
|
|
|
Top parent is the HomePage. |
|
17
|
|
|
None when there is no Hompage or when the HomePage has no header. |
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
# Get a random page header, or the first one if there is only one |
|
21
|
|
|
image = PageHeaderImage.objects.filter(page=page).order_by('?').first() |
|
22
|
|
|
if image is not None: |
|
23
|
|
|
return image |
|
24
|
|
|
|
|
25
|
|
|
# No image found! If we received an integer, then do not search further |
|
26
|
|
|
if isinstance(page, int): |
|
27
|
|
|
return None |
|
28
|
|
|
|
|
29
|
|
|
# Try from parent |
|
30
|
|
|
if page.parent: |
|
31
|
|
|
return get_page_header(page.parent) |
|
32
|
|
|
|
|
33
|
|
|
# Try from first homepage |
|
34
|
|
|
homepage = HomePage.objects.values_list('id').first() |
|
35
|
|
|
if len(homepage) != 0: |
|
36
|
|
|
# Since we give get_page_header an integer, there is no infinite recursion here... |
|
37
|
|
|
return get_page_header(homepage[0]) |
|
38
|
|
|
|
|
39
|
|
|
return None |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def get_homepage_header(): |
|
43
|
|
|
""" Returns the page header image of the homepage """ |
|
44
|
|
|
homepage = HomePage.objects.values_list('id').first() |
|
45
|
|
|
if not homepage: |
|
46
|
|
|
return None |
|
47
|
|
|
return get_page_header(homepage[0]) |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
class OccuranceJDView(OccurrenceView): |
|
51
|
|
|
|
|
52
|
|
|
def get_context_data(self, **kwargs): |
|
53
|
|
|
context = super().get_context_data(**kwargs) |
|
54
|
|
|
context['page_for_sidebars'] = HomePage.objects.all().first() |
|
55
|
|
|
return context |
|
56
|
|
|
|