Parent
99a344794e
révision
936921b4dc
|
@ -289,7 +289,12 @@ class SitePage(mixins.SetSiteTheme, Page):
|
|||
def get_context(self, request):
|
||||
context = super().get_context(request)
|
||||
|
||||
excluded = [self.id]
|
||||
if hasattr(self, 'contenu4') and self.contenu4:
|
||||
excluded = utils.get_streamfield_pined(self.contenu4) + [self.id]
|
||||
elif hasattr(self, 'contenu') and self.contenu:
|
||||
excluded = utils.get_streamfield_pined(self.contenu) + [self.id]
|
||||
else:
|
||||
excluded = [self.id]
|
||||
|
||||
for idx, key in [
|
||||
[self.get_current_actualite_index(), 'last_articles'],
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
|
||||
from django.utils.html import strip_tags
|
||||
from wagtail.core.blocks.stream_block import StreamValue
|
||||
|
||||
|
||||
def resume(x):
|
||||
|
@ -20,3 +21,23 @@ def resume(x):
|
|||
def streamfield_to_resume(stream):
|
||||
s = " | ".join([resume(stream.stream_data) for x in stream])
|
||||
return re.sub(r'\s+', ' ', strip_tags(s)).strip()
|
||||
|
||||
|
||||
def get_streamfield_pined(x):
|
||||
'''
|
||||
Prend des datas StreamField et en extrait la liste des pages épinglées.
|
||||
'''
|
||||
if isinstance(x, StreamValue):
|
||||
return get_streamfield_pined(x.stream_data)
|
||||
elif isinstance(x, list):
|
||||
return [
|
||||
item for sublist in
|
||||
[get_streamfield_pined(item) for item in x]
|
||||
for item in sublist
|
||||
]
|
||||
elif not isinstance(x, dict):
|
||||
return []
|
||||
elif x.get('type', None) == 'page':
|
||||
return [x['value']['page']]
|
||||
else:
|
||||
return get_streamfield_pined([v for v in x.values()])
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket