Exemple #1
0
 def get(self):
     posts, age = Post.get_posts()
     age_str = utils.age_str(age)
     
     if self.format == 'html':
         self.render('front.html', posts = posts, age = age_str)
     elif self.format == 'json':
         return self.render_json([p.as_dict() for p in posts])
Exemple #2
0
    def get(self):
        posts, age = Post.get_posts()
        age_str = utils.age_str(age)

        if self.format == 'html':
            self.render('front.html', posts=posts, age=age_str)
        elif self.format == 'json':
            return self.render_json([p.as_dict() for p in posts])
Exemple #3
0
    def get(self, page_name):

        # if version requested, return appropriate wiki version
        version = self.request.get('v', '')
        logging.error('WIKI VERSION REQUEST = ' + version)

        #MEMCACHED DISABLED
        wiki = ''
        wiki_key = ''
        # wiki_key = 'WIKI_' + page_name
        # wiki, age = utils.age_get(wiki_key)

        #if wiki not returned by memcached, lookup from db
        if not wiki:
            #get wiki from db via gql query

            if version != '':
                wiki = Wiki.get_by_id(int(version), utils.wiki_key())
                logging.error("WIKI GET_BY_ID = " + repr(wiki))
            else:
                query = Wiki.gql(
                    "WHERE name =:page_name ORDER BY created desc LIMIT 1",
                    page_name=page_name)
                wikis = query.fetch(limit=1)
                if len(wikis) > 0:
                    wiki = wikis[0]
            if wiki:
                utils.age_set(wiki_key, wiki)
                age = 0

        #if wiki exists, render WikiPage
        if wiki:
            self.params['wiki'] = wiki
            self.params['age'] = utils.age_str(age)
            self.render("wiki-page.html")

        #if wiki doesn't exist and user is logged in, redirect to WikiEdit.py
        elif not wiki and self.user:
            self.redirect('/_edit%s' % page_name)
            return

        #if url doesn't exist and user is NOT logged in, redirect to login
        else:
            self.redirect('/login')
Exemple #4
0
    def post(self):
        logging.error(utils.blog_key())
        if not self.user:
            self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')
        parent = utils.blog_key()

        if subject and content:
            logging.error(utils.age_str(12345))
            p = Post(parent = parent, subject = subject, content = content)
                    
            add_post(p)
                    
            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html", subject = subject, content = content, error = error)
Exemple #5
0
    def get(self, page_name):

        # if version requested, return appropriate wiki version
        version = self.request.get('v', '')
        logging.error('WIKI VERSION REQUEST = ' + version)

        #MEMCACHED DISABLED
        wiki = ''
        wiki_key = ''
        # wiki_key = 'WIKI_' + page_name 
        # wiki, age = utils.age_get(wiki_key)
                
        #if wiki not returned by memcached, lookup from db
        if not wiki:
            #get wiki from db via gql query 
            
            if version != '':
                wiki = Wiki.get_by_id(int(version), utils.wiki_key())
                logging.error("WIKI GET_BY_ID = " + repr(wiki))
            else:            
                query = Wiki.gql("WHERE name =:page_name ORDER BY created desc LIMIT 1", page_name = page_name)
                wikis = query.fetch(limit=1)
                if len(wikis) > 0:
                    wiki = wikis[0]
            if wiki:
                utils.age_set(wiki_key, wiki)
                age = 0               

        #if wiki exists, render WikiPage        
        if wiki:            
            self.params['wiki'] = wiki
            self.params['age'] = utils.age_str(age)
            self.render("wiki-page.html")

        #if wiki doesn't exist and user is logged in, redirect to WikiEdit.py
        elif not wiki and self.user:
            self.redirect('/_edit%s' % page_name)
            return
        
        #if url doesn't exist and user is NOT logged in, redirect to login
        else:
            self.redirect('/login')
Exemple #6
0
 def get(self, post_id):
     post_key = 'POST_' + post_id
     
     post, age = utils.age_get(post_key)
     
     #if post not returned, lookup from db
     #TODO: move db logic to utils or Post
     if not post:
         key = db.Key.from_path('Post', int(post_id), parent=utils.blog_key())
         post = db.get(key)
         utils.age_set(post_key, post)
         age = 0
     
     if not post:
         self.error(404)
         return
     
     if self.format == 'html':
         self.render("permalink.html", post = post, age = utils.age_str(age))
     elif self.format == 'json':
         self.render_json(post.as_dict())
Exemple #7
0
    def get(self, post_id):
        post_key = "POST_" + post_id

        post, age = utils.age_get(post_key)

        # if post not returned, lookup from db
        # TODO: move db logic to utils or Post
        if not post:
            key = db.Key.from_path("Post", int(post_id), parent=utils.blog_key())
            post = db.get(key)
            utils.age_set(post_key, post)
            age = 0

        if not post:
            self.error(404)
            return

        if self.format == "html":
            self.render("permalink.html", post=post, age=utils.age_str(age))
        elif self.format == "json":
            self.render_json(post.as_dict())
Exemple #8
0
    def post(self):
        logging.error(utils.blog_key())
        if not self.user:
            self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')
        parent = utils.blog_key()

        if subject and content:
            logging.error(utils.age_str(12345))
            p = Post(parent=parent, subject=subject, content=content)

            add_post(p)

            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html",
                        subject=subject,
                        content=content,
                        error=error)