예제 #1
0
    def get(self, page_id, sub_page_id=""):

        has_sub_page = False
        curr_page_id = page_id

        #If the current page is a sub_page set the curr_page id. 
        if sub_page_id:
            has_sub_page = True
            curr_page_id = sub_page_id
        
        #Get all sub_pages for page id. 
        all_pages = PageModel.query() 
        sub_pages = []
        for _page in all_pages.iter():
            if _page.parent:
                if _page.parent.get().page_id == page_id:
                    sub_pages.append((_page.page_id, _page.title))
                    has_sub_page = True
        
        #Get the current page:
        pages = PageModel.query(PageModel.page_id == curr_page_id)
        page = pages.get()

        try: 
            self.render("page_template_%s.html" % page.template, 
                active_main_page=page_id,
                active_page = curr_page_id,
                page = page,
                has_sub_page = has_sub_page,
                sub_pages = sub_pages)
        except: #If the template somehow is misloaded, just tell that the page doesn't exist. 
            self.redirect("/error404")
예제 #2
0
    def post(self):
        try:

            parent = self.request.get('parent')            
            page_id = self.request.get('id')
            template = self.request.get('template');

            #Check that a page with the given id doesn't exist already.
            all_pages = PageModel.query()
            for _page in all_pages.iter():
                if _page.page_id == page_id:
                    raise Exception('Page with that id exists')

            #Now generate the database object and store it. 
            page = PageModel(
                page_id = page_id,
                title = self.request.get('title'),
                text = self.request.get('text'),
                template = template,
            )

            if parent != "None":
                parent_key = ndb.Key(urlsafe=parent)
                page.parent = parent_key
            else:
                is_valid_main_page = False
                #Make sure only the wanted main pages are created:
                for main_page_id, main_page_title in Config.MAIN_PAGES:
                    if main_page_id == page_id:
                        is_valid_main_page = True

                if page_id == "frontpage":
                    is_valid_main_page = True

                if not is_valid_main_page:
                    raise Exception('That is not a main page')


            #Find out how many images needed for the chosen template. 
            template_images_count = images_for_template(template)

            #Add the chosen images. 
            for i in range(1, template_images_count + 1):
                img_key = self.request.get('image%s' % i)
                img = ndb.Key(urlsafe=img_key)
                page.images.append(img)

            page.put()

            #Redirect to the upload site and tell it that it succeeded. 
            self.redirect('/admin/create_page#success')

        except:
            #Redirect to upload site and tell that something went wrong. 
            self.redirect('/admin/create_page#fail')
예제 #3
0
 def get(self):
     pages = PageModel.query(PageModel.page_id == "frontpage")
     try:
         page = pages.get()
         self.render("page_template_frontpage.html", page=page)
     except:
         self.redirect("/error404")
예제 #4
0
    def get(self, curr_page_id="main"):
        redirect_if_not_admin(self)

        pages = PageModel.query()
        images = ImageModel.query()

        curr_page = ""
        if curr_page_id:
            curr_page_query = PageModel.query(PageModel.page_id == curr_page_id)
            curr_page = curr_page_query.get()

        self.render('page_admin.html', 
            active="pages", 
            pages=pages,
            templates = Config.TEMPLATES,
            images = images,
            main_pages = Config.MAIN_PAGES,
            curr_page = curr_page,
            curr_page_id = curr_page_id)
예제 #5
0
    def get(self):
        redirect_if_not_admin(self)

        templates = Config.TEMPLATES
        images = ImageModel.query()
        main_pages = PageModel.query(PageModel.parent == None)

        self.render("page_creation.html", active="create_page", 
            templates=templates, 
            main_pages=main_pages,
            images=images)
예제 #6
0
    def render_str(self, template, **params):
        t = jinja_env.get_template(template)

        return t.render(params, all_pages=PageModel.query(), galleries=GalleryModel.query())