Пример #1
0
    def renderPage(self, query):
        # If we are at root page in URL
        if self.path == '/' + self.lang + '/':
            self.toTemplate.currentPage = UI.getStartPage(self.lang, self.pageRefresh)
            # We need at least one page as startpage
            if self.toTemplate.currentPage is None:
                self.toTemplate.error = { 'code' : '500', 'message' : 'Missing startpage. Select a start page under tab "Page Settings"' }
                return False
            # Get page modules associated with startpage
            pageModule = PageModules.getByPageKeyAndLanguage(self.toTemplate.currentPage.key(), self.lang)
        else:
            # Get page modules associated with url path
            pageModule = PageModules.getByPath(self.path)
        # We need at least one pageModule to display any page
        if pageModule is None:
            self.toTemplate.error = { 'code' : '404', 'message' : 'Can\'t find request page' }
            return False
        else:
            # If no current page is set, set pageModules's page as currentpage
            if not self.toTemplate.currentPage:
                # TODO: Remove reference property since it causes an extra query.
                #self.toTemplate.currentPage = Pages.getByKeyForMainView(pageModule.pageKey.key())
                self.toTemplate.currentPage = pageModule.pageKey
                
            # templateType is stored with entire class path, we only need the last name
            pageTemplateType = self.toTemplate.currentPage.templateType.split('.')[-1]

            # Set up memcacheid based on language
            memcacheid = "mainView_pageTemplate_%s" % self.path
            pageTemplate = memcache.get(memcacheid)
            # If pageTemplate is not in memcache
            if pageTemplate is None or self.pageRefresh:
                # Find pageTemplate class
                pageTemplateClass = getattr(PageTemplates, pageTemplateType, None)
                #invoke class and store it in memcache
                pageTemplate = pageTemplateClass(page = self.toTemplate.currentPage, query = query, language = self.lang)
                pageTemplate.postRender(self.lang, query)
                memcache.set(memcacheid, pageTemplate, Settings.memcacheTimeout)

            # Do stuff after saved to cache
            pageTemplate.postCache(self.lang, query)
            # Bind pageTemplate to view
            self.toTemplate.pageTemplate = pageTemplate
            self.templateFile = pageTemplate.templateFile
            self.toTemplate.pageType = pageTemplateType
            self.toTemplate.pageModule = self.toTemplate.pageTemplate.pageModules[self.lang]
            self.toTemplate.pageContent = self.toTemplate.pageTemplate.pageData[self.lang]
            self.toTemplate.language = self.lang
    def __init__(self, **kwargs):
        # Get page from kwargs
        page = kwargs['page']
        # Set reference to page.key()
        pageKey = page.key()
        # Get pageModules associated with page
        pageModuleList = PageModules.getByPageKey(pageKey)
        pageData = {}
        pageModules = {}
        blogPosts = {}
        # Set up pageModules dict with lang as keys
        for market in Settings.markets:
            pageModules[market['language']] = {}
            blogPosts[market['language']] = []

        for pageModule in pageModuleList:
            pageModules[pageModule.lang] = pageModule
            blogPosts[pageModule.lang] = Blog.getByPageModuleKey(
                pageModule.key())
            # All content data in store in dbContentModules.ContentModules and not in the pageModules them self
            # Get dbContentModules.ContentModules for pageModule
            pageData[pageModule.lang] = ContentModules.getByPageModuleKey(
                pageModule.key())

        # Store all data
        self.blogPosts = blogPosts
        self.pageModules = pageModules
        self.pageKey = pageKey
        self.pageData = self.parsePageData(pageData)
        self.modules = []
    def __init__(self, **kwargs):
        # Get page from kwargs
        page = kwargs['page']
        # Set reference to page.key()
        pageKey = page.key()
        # Get pageModules associated with page
        pageModuleList = PageModules.getByPageKey(pageKey)
        pageData = {}
        pageModules = {}
        blogPosts = {}
        # Set up pageModules dict with lang as keys
        for market in Settings.markets:
            pageModules[market['language']] = {}
            blogPosts[market['language']] = []

        for pageModule in pageModuleList:
            pageModules[pageModule.lang] = pageModule
            blogPosts[pageModule.lang] = Blog.getByPageModuleKey(pageModule.key())
            # All content data in store in dbContentModules.ContentModules and not in the pageModules them self
            # Get dbContentModules.ContentModules for pageModule
            pageData[pageModule.lang] = ContentModules.getByPageModuleKey(pageModule.key())

        # Store all data
        self.blogPosts = blogPosts
        self.pageModules = pageModules
        self.pageKey = pageKey
        self.pageData = self.parsePageData(pageData)
        self.modules = []
Пример #4
0
 def editViewUpdatePage(self, request):
     message = PageModules.addUpdatePageModule(
         request.get('page_string_key'), request.get('page_module_name'),
         request.get('language'), request.get('publish'))
     if message['status'] == 1:
         ContentModules.addUpdateContentModule(message['pageModuleKey'],
                                               request)
     return message
    def setUp(self):
        self.page = dbPages.Pages()
        self.page.name = 'test'
        self.page.put()

        stringKey = str(self.page.key())
        message = PageModules.addUpdatePageModule(stringKey, 'test', 'se-sv', 'on')
        self.pageModuleKey = message['pageModuleKey']
 def postRender(self, language, query):
     galleryPages = Pages.getPagesByStringKey(str(self.pageKey))
     self.childGalleryPages = []
     for page in galleryPages:
         pageModule = PageModules.getByPageKeyAndLanguage(page.key(), language)
         contentModule = ContentModules.getByNameAndPageModuleKey('AlbumThumbnail', pageModule.key())
         image = ImageStore.getImageWithDescription(contentModule.content, language)
         self.childGalleryPages.append(dict(name = pageModule.name, path = pageModule.path, image = image))
    def setUp(self):
        self.page = dbPages.Pages()
        self.page.name = 'test'
        self.page.put()

        stringKey = str(self.page.key())
        message = PageModules.addUpdatePageModule(stringKey, 'test', 'se-sv',
                                                  'on')
        self.pageModuleKey = message['pageModuleKey']
 def postRender(self, language, query):
     galleryPages = Pages.getPagesByStringKey(str(self.pageKey))
     self.childGalleryPages = []
     for page in galleryPages:
         pageModule = PageModules.getByPageKeyAndLanguage(
             page.key(), language)
         contentModule = ContentModules.getByNameAndPageModuleKey(
             'AlbumThumbnail', pageModule.key())
         image = ImageStore.getImageWithDescription(contentModule.content,
                                                    language)
         self.childGalleryPages.append(
             dict(name=pageModule.name, path=pageModule.path, image=image))
Пример #9
0
    def renderPage(self, query):
        # If we are at root page in URL
        if self.path == '/' + self.lang + '/':
            self.toTemplate.currentPage = UI.getStartPage(
                self.lang, self.pageRefresh)
            # We need at least one page as startpage
            if self.toTemplate.currentPage is None:
                self.toTemplate.error = {
                    'code':
                    '500',
                    'message':
                    'Missing startpage. Select a start page under tab "Page Settings"'
                }
                return False
            # Get page modules associated with startpage
            pageModule = PageModules.getByPageKeyAndLanguage(
                self.toTemplate.currentPage.key(), self.lang)
        else:
            # Get page modules associated with url path
            pageModule = PageModules.getByPath(self.path)
        # We need at least one pageModule to display any page
        if pageModule is None:
            self.toTemplate.error = {
                'code': '404',
                'message': 'Can\'t find request page'
            }
            return False
        else:
            # If no current page is set, set pageModules's page as currentpage
            if not self.toTemplate.currentPage:
                # TODO: Remove reference property since it causes an extra query.
                #self.toTemplate.currentPage = Pages.getByKeyForMainView(pageModule.pageKey.key())
                self.toTemplate.currentPage = pageModule.pageKey

            # templateType is stored with entire class path, we only need the last name
            pageTemplateType = self.toTemplate.currentPage.templateType.split(
                '.')[-1]

            # Set up memcacheid based on language
            memcacheid = "mainView_pageTemplate_%s" % self.path
            pageTemplate = memcache.get(memcacheid)
            # If pageTemplate is not in memcache
            if pageTemplate is None or self.pageRefresh:
                # Find pageTemplate class
                pageTemplateClass = getattr(PageTemplates, pageTemplateType,
                                            None)
                #invoke class and store it in memcache
                pageTemplate = pageTemplateClass(
                    page=self.toTemplate.currentPage,
                    query=query,
                    language=self.lang)
                pageTemplate.postRender(self.lang, query)
                memcache.set(memcacheid, pageTemplate,
                             Settings.memcacheTimeout)

            # Do stuff after saved to cache
            pageTemplate.postCache(self.lang, query)
            # Bind pageTemplate to view
            self.toTemplate.pageTemplate = pageTemplate
            self.templateFile = pageTemplate.templateFile
            self.toTemplate.pageType = pageTemplateType
            self.toTemplate.pageModule = self.toTemplate.pageTemplate.pageModules[
                self.lang]
            self.toTemplate.pageContent = self.toTemplate.pageTemplate.pageData[
                self.lang]
            self.toTemplate.language = self.lang
Пример #10
0
 def editViewUpdatePage(self, request):
     message = PageModules.addUpdatePageModule(request.get('page_string_key'), request.get('page_module_name'), request.get('language'), request.get('publish'))
     if message['status'] == 1:
         ContentModules.addUpdateContentModule(message['pageModuleKey'], request)
     return message