1
1
from DateTime import DateTime
2
2
from plone import api
3
3
from plone .memoize import ram
4
+ from Products .CMFPlone .browser .defaultpage import DefaultPage
4
5
from Products .Five .browser import BrowserView
5
6
from recensio .plone .browser .canonical import CanonicalURLHelper
6
7
@@ -9,6 +10,34 @@ def _render_cachekey(method, self, brain, lang):
9
10
return (brain .getPath (), lang , DateTime ().dayOfYear ())
10
11
11
12
13
+ class PublicationDefaultPage (DefaultPage ):
14
+ """Translated default page"""
15
+
16
+ def getDefaultPage (self ):
17
+ """Get the default page, if possible in the correct language.
18
+ We expect the default page to have no language suffix (e.g. 'index').
19
+ Translations should have a language suffix (e.g. 'index-en').
20
+ If this fails we check the language attribute of all contained documents.
21
+ If there is only one document with the right language we return that.
22
+ """
23
+ default_page = super ().getDefaultPage ()
24
+ language = api .portal .get_current_language ()
25
+ defob = self .context .get (default_page )
26
+ if not defob or defob .Language () == language :
27
+ return default_page
28
+ documents = self .context .listFolderContents (dict (portal_type = "Document" ))
29
+ id_match = [
30
+ item for item in documents if item .getId () == f"{ default_page } -{ language } "
31
+ ]
32
+ if len (id_match ) == 1 :
33
+ return id_match [0 ].getId ()
34
+
35
+ language_match = [item for item in documents if item .Language () == language ]
36
+ if len (language_match ) == 1 :
37
+ return language_match [0 ].getId ()
38
+ return default_page
39
+
40
+
12
41
class PublicationsView (BrowserView , CanonicalURLHelper ):
13
42
"""Overview page of publications."""
14
43
0 commit comments