Пример #1
0
 def POST(self, slug):
     f = commentForm()
     entry = self.get_entry(slug)
     i = web.input()
     if f.validates():
         if i.url == "":
             i.url = "#"
             #createdTime = datetime.now().strftime("%Y-%m-%d %H:%M")
             #db.insert('comments', entryId=i.entryId, email=i.email, username=i.username, url=i.url, comment=i.comment,createdTime=createdTime)
             #db.update('entries', where = 'id=%s' % entry.entryId, commentNum = entry.commentNum + 1)
         comment = Comment(i.email, i.username, i.url, i.comment, entry.id)
         web.ctx.orm.add(comment)
         entry.commentNum = entry.commentNum + 1
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['f'] = f
         d['entry'] = entry
         return render.entry(**d)
Пример #2
0
 def POST(self, slug):
     f = commentForm()
     entry = self.get_entry(slug)
     i = web.input()
     if f.validates():
         if i.url == "":
             i.url = "#"
             #createdTime = datetime.now().strftime("%Y-%m-%d %H:%M")
             #db.insert('comments', entryId=i.entryId, email=i.email, username=i.username, url=i.url, comment=i.comment,createdTime=createdTime)
             #db.update('entries', where = 'id=%s' % entry.entryId, commentNum = entry.commentNum + 1)
         comment = Comment(i.email, i.username, i.url, i.comment, entry.id)
         web.ctx.orm.add(comment)
         entry.commentNum = entry.commentNum + 1
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['f'] = f
         d['entry'] = entry
         return render.entry(**d)
Пример #3
0
    def GET(self, slug):
        #entry = list(db.select('entries', where="slug=$slug", vars={'slug': slug}))
        #entry = list(db.query("select en.id AS entryId, en.title AS entry_title, en.slug AS entry_slug, en.content AS entry_content, en.createdTime AS entry_created_time, c.name AS entry_category, en.commentNum from entries en LEFT JOIN categories c ON en.categoryId = c.id where en.slug=$slug", vars={'slug': slug}))
        #entry[0].tags = db.query("select * from tags t LEFT JOIN entry_tag et ON t.id = et.tagId WHERE et.entryId = $id", vars={'id': entry[0].entry_id})
        ##for one in entry:
        ##    one.tags = db.query("select * from tags t left join entry_tag et on et.tagId=t.id where et.entryId=$id", vars={'id':one.entry_id})
        #comments = db.query("SELECT * FROM comments c WHERE c.entryId=$id", vars={'id': entry[0].entry_id})
        #if len(comments) > 0:
        #    d['comments'] = comments
        f = commentForm()
        entry = self.get_entry(slug)
        if entry:
            # select the previous and next entry of current entry.
            #preEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                         max(id) FROM entries WHERE id < %d)' % int(entry.id)))
            # preEntry is a tuple.
            preEntry = web.ctx.orm.query(Entry).filter(
                Entry.id < entry.id).order_by("entries.id desc").all()
            #print preEntry[0][1].id, preEntry[0][1].slug
            nextEntry = web.ctx.orm.query(Entry).filter(
                Entry.id > entry.id).order_by(Entry.id).all()
            #print nextEntry[0][1].id, nextEntry[0][1].title, entry.id
            #nextEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                          min(id) FROM entries WHERE id > %d)' % int(entry.id)))
            # update the viewNum
            entry.viewNum = entry.viewNum + 1
            #db.query('UPDATE entries SET viewNum = viewNum + 1 WHERE id=%d' % int(entry.id))
            #preEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            #posEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            d['entry'] = entry
            if preEntry:
                d['preEntry'] = preEntry[0]
            else:
                d['preEntry'] = None

            if nextEntry:
                #d['nextEntry'] = nextEntry[0][1]
                d['nextEntry'] = nextEntry[0]
            else:
                d['nextEntry'] = None
            d['f'] = f
            return render.entry(**d)
        else:
            return render.pageNotFound(**d)
Пример #4
0
    def GET(self, slug):
        #entry = list(db.select('entries', where="slug=$slug", vars={'slug': slug}))
        #entry = list(db.query("select en.id AS entryId, en.title AS entry_title, en.slug AS entry_slug, en.content AS entry_content, en.createdTime AS entry_created_time, c.name AS entry_category, en.commentNum from entries en LEFT JOIN categories c ON en.categoryId = c.id where en.slug=$slug", vars={'slug': slug}))
        #entry[0].tags = db.query("select * from tags t LEFT JOIN entry_tag et ON t.id = et.tagId WHERE et.entryId = $id", vars={'id': entry[0].entry_id})
        ##for one in entry:
        ##    one.tags = db.query("select * from tags t left join entry_tag et on et.tagId=t.id where et.entryId=$id", vars={'id':one.entry_id})
        #comments = db.query("SELECT * FROM comments c WHERE c.entryId=$id", vars={'id': entry[0].entry_id})
        #if len(comments) > 0:
        #    d['comments'] = comments
        f = commentForm()
        entry = self.get_entry(slug)
        if entry:
            # select the previous and next entry of current entry.
            #preEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                         max(id) FROM entries WHERE id < %d)' % int(entry.id)))
            # preEntry is a tuple.
            preEntry = web.ctx.orm.query(Entry).filter(Entry.id < entry.id).order_by("entries.id desc").all()
            #print preEntry[0][1].id, preEntry[0][1].slug
            nextEntry = web.ctx.orm.query(Entry).filter(Entry.id > entry.id).order_by(Entry.id).all()
            #print nextEntry[0][1].id, nextEntry[0][1].title, entry.id
            #nextEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                          min(id) FROM entries WHERE id > %d)' % int(entry.id)))
            # update the viewNum
            entry.viewNum = entry.viewNum + 1
            #db.query('UPDATE entries SET viewNum = viewNum + 1 WHERE id=%d' % int(entry.id))
            #preEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            #posEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            d['entry'] = entry
            if preEntry:
                d['preEntry'] = preEntry[0]
            else:
                d['preEntry'] = None

            if nextEntry:
                #d['nextEntry'] = nextEntry[0][1]
                d['nextEntry'] = nextEntry[0]
            else:
                d['nextEntry'] = None
            d['f'] = f
            return render.entry(**d)
        else:
            return render.pageNotFound(**d)