示例#1
0
    def view(self, category_id, categroy_page):
        db = Session()
        c.alive = alive()

        result = db.execute(
            'select count(*) from LUM_Discussion where CategoryID=%s',
            category_id)
        c.topics_total = result.fetchone()[0]

        c.topics_start, c.topics_end, c.pages_current, c.pages_total = page_range(
            int(categroy_page), c.topics_total)
        log.debug('topics_total:%s start:%s end:%s', c.topics_total,
                  c.topics_start, c.topics_end)

        position = c.topics_start - 1
        length = c.topics_end - position

        #category title
        result = db.execute('select * from LUM_Category where CategoryID=%s',
                            int(category_id))
        c.category = result.fetchone()

        #topics
        #result = db.execute('select * from LUM_Discussion order by DiscussionID desc')
        result = db.execute(
            'select d.DiscussionID,d.Name,c.Name,u1.Name,u2.Name,d.CountComments,d.DateLastActive from LUM_Discussion AS d Left Join (LUM_User AS u1) on (d.AuthUserID=u1.UserID) Left Join (LUM_User AS u2) on (d.LastUserID=u2.UserID),LUM_Category AS c where d.CategoryID=c.CategoryID and d.CategoryID=%s order by d.DateLastActive desc LIMIT %s,%s',
            (int(category_id), position, length))
        c.topics = result.fetchall()

        return render('genshi', 'category')
示例#2
0
    def index(self):
        # Return a rendered template
        #   return render('/some/template.mako')
        # or, Return a response

        db = Session()
        c.alive = alive()

        result = db.execute('select * from LUM_Category')
        c.categories = result.fetchall()

        return render('genshi', 'categories')
示例#3
0
 def index(self):
     # Return a rendered template
     #   return render('/some/template.mako')
     # or, Return a response
     
     db = Session()
     c.alive = alive()
     
     result = db.execute('select * from LUM_Category')
     c.categories = result.fetchall()
     
     return render('genshi','categories')
示例#4
0
 def view(self,id):
     db = Session()
     c.alive = alive()
     
     log.debug('topic %s',id)
     result = db.execute('select * from LUM_Discussion,LUM_Category where LUM_Discussion.CategoryID = LUM_Category.CategoryID and LUM_Discussion.DiscussionID=%s',id)
     if result.rowcount != 1:
         return 'err'
     c.topic = result.fetchone()
     
     result = db.execute('select * from LUM_Comment,LUM_User where LUM_User.UserID=LUM_Comment.AuthUserID and LUM_Comment.DiscussionID=%s order by LUM_Comment.CommentID asc',id)
     c.comments = result.fetchall()
     
     return render('genshi','topic')
示例#5
0
 def post(self,category_id=0):
     c.alive = alive()
     if not c.alive:
         return redirect_to(controller='topics',action='index',category_id=None)
     
     db = Session()
     
     if request.method == 'POST':
         #valid the form
         schema = PostForm()
         
         try:
             form_result = schema.to_python(request.params)
         except formencode.Invalid, error:
             return 'Invalid: %s' % error
         else:
             db.execute('insert into LUM_Discussion (Name,CategoryID,DateCreated,DateLastActive,AuthUserID,LastUserID) values(%s,%s,%s,%s,%s,%s)',
                         (form_result.get('Name').encode('utf-8'),form_result.get('CategoryID'),datetime.now(),datetime.now(),session['user_id'],session['user_id']))
             
             result = db.execute('select * from LUM_Discussion order by DiscussionID desc')
             discussion_id = result.fetchone()[0]
             
             #add topic content
             db.execute('insert into LUM_Comment (Body,DiscussionID,DateCreated,AuthUserID) values(%s,%s,%s,%s)',
                         (form_result.get('Body').encode('utf-8'),discussion_id,datetime.now(),session['user_id']))
             
             Session.commit()
             log.debug('post submit')
             return redirect_to(controller='categories', action='view', category_id=form_result.get('CategoryID'))
示例#6
0
 def comment(self,id):
     
     log.debug('comment')
     if alive() and request.method == 'POST':
         #vaild form
         db = Session()
         db.execute('insert into LUM_Comment (DiscussionID, AuthUserID, Body) values(%s,%s,%s)',(str(id), session['user_id'], request.POST['Body'].encode('utf-8')))
         db.execute('update LUM_Discussion set CountComments = (select count(*) from LUM_Comment where DiscussionID=%s),LastUserID=%s,DateLastActive=%s where DiscussionID=%s', (str(id),session['user_id'],datetime.now(), str(id)))
         Session.commit()
         log.debug('comment submit')
     
     return redirect_to(controller='topics',action='view',id=id)
示例#7
0
 def index(self,page):
     # Return a rendered template
     #   return render('/some/template.mako')
     # or, Return a response
     
     db = Session()
     c.alive = alive()
     
     result = db.execute('select count(*) from LUM_Discussion')
     c.topics_total = result.fetchone()[0]
     c.topics_start, c.topics_end, c.pages_current, c.pages_total = page_range(int(page), c.topics_total)
     log.debug('input_page:%s topics_total:%s start:%s end:%s pages_current:%s , pages_total:%s',page,c.topics_total,c.topics_start, c.topics_end, c.pages_current, c.pages_total)
     
     position = c.topics_start - 1
     length = c.topics_end - position
     
     result = db.execute('select d.DiscussionID,d.Name,c.Name,u1.Name,u2.Name,d.CountComments,d.DateLastActive from LUM_Discussion AS d Left Join (LUM_User AS u1) on (d.AuthUserID=u1.UserID) Left Join (LUM_User AS u2) on (d.LastUserID=u2.UserID),LUM_Category AS c where d.CategoryID=c.CategoryID order by d.DateLastActive desc LIMIT %s,%s',(position,length))
     c.topics = result.fetchall()
     
     return render('genshi','topics')
示例#8
0
 def view(self,category_id, categroy_page):
     db = Session()
     c.alive = alive()
     
     result = db.execute('select count(*) from LUM_Discussion where CategoryID=%s', category_id)
     c.topics_total = result.fetchone()[0]
     
     c.topics_start, c.topics_end, c.pages_current, c.pages_total = page_range(int(categroy_page), c.topics_total)
     log.debug('topics_total:%s start:%s end:%s',c.topics_total,c.topics_start, c.topics_end)
     
     position = c.topics_start - 1
     length = c.topics_end - position
     
     #category title
     result = db.execute('select * from LUM_Category where CategoryID=%s',int(category_id))
     c.category = result.fetchone()
     
     #topics
     #result = db.execute('select * from LUM_Discussion order by DiscussionID desc')
     result = db.execute('select d.DiscussionID,d.Name,c.Name,u1.Name,u2.Name,d.CountComments,d.DateLastActive from LUM_Discussion AS d Left Join (LUM_User AS u1) on (d.AuthUserID=u1.UserID) Left Join (LUM_User AS u2) on (d.LastUserID=u2.UserID),LUM_Category AS c where d.CategoryID=c.CategoryID and d.CategoryID=%s order by d.DateLastActive desc LIMIT %s,%s',(int(category_id),position,length))
     c.topics = result.fetchall()
     
     return render('genshi','category')
示例#9
0
    def post(self, category_id=0):
        c.alive = alive()
        if not c.alive:
            return redirect_to(controller='topics',
                               action='index',
                               category_id=None)

        db = Session()

        if request.method == 'POST':
            #valid the form
            schema = PostForm()

            try:
                form_result = schema.to_python(request.params)
            except formencode.Invalid, error:
                return 'Invalid: %s' % error
            else:
                db.execute(
                    'insert into LUM_Discussion (Name,CategoryID,DateCreated,DateLastActive,AuthUserID,LastUserID) values(%s,%s,%s,%s,%s,%s)',
                    (form_result.get('Name').encode('utf-8'),
                     form_result.get('CategoryID'), datetime.now(),
                     datetime.now(), session['user_id'], session['user_id']))

                result = db.execute(
                    'select * from LUM_Discussion order by DiscussionID desc')
                discussion_id = result.fetchone()[0]

                #add topic content
                db.execute(
                    'insert into LUM_Comment (Body,DiscussionID,DateCreated,AuthUserID) values(%s,%s,%s,%s)',
                    (form_result.get('Body').encode('utf-8'), discussion_id,
                     datetime.now(), session['user_id']))

                Session.commit()
                log.debug('post submit')
                return redirect_to(controller='categories',
                                   action='view',
                                   category_id=form_result.get('CategoryID'))
示例#10
0
     return render('genshi','login')
 else:
     schema = LoginForm()
     #log.debug('%s',dir(schema))
     
     try:
         form_result = schema.to_python(request.params)
         
     except formencode.Invalid, error:
         return 'Invalid: %s' % error
     else:
         #log.debug('%s',request.POST['username'])
         #log.debug('%s',request.POST['password'])
         
         #look up in db for the username
         db = Session()
         result = db.execute('select * from LUM_User where Name=%s',form_result.get('username'))
         user_info = result.fetchone()
         
         if not user_info:
             c.err = 'user not exist'
             return 'login failed'
         
         log.debug('%s',user_info)
         
         if md5.md5(form_result.get('password')).hexdigest() == user_info[7]:
             #write session
             session['user_id'] = user_info[0]
             session['name'] = form_result.get('username')
             session.save()
             #return 'login success'