Ejemplo n.º 1
0
Archivo: main.py Proyecto: zz2/webchat
    def GET(self, channel):
        #web_input = web.input()
        rows = 7
        sord = 'desc'
        sidx = 'create_time'
        page = 1
        channel = db_api.channel_get_with_channel(channel)
        offset = rows*(page-1)
        limit = rows
        notice_count = db_session.query(Notice_)\
                .filter(Notice_.channel_uuid==channel.uuid)\
                .filter(Notice_.category=='root')\
                .filter(Notice_.is_locked==False)\
                .count()
        print notice_count
        notices = db_session.query(Notice_)\
                .filter(Notice_.channel_uuid==channel.uuid)\
                .filter(Notice_.category=='root')\
                .filter(Notice_.is_locked==False)\
                .limit(limit)\
                .offset(offset).all()
        channel.rows = rows
        channel.page = page
        channel.notice_count = notice_count
        channel.notices = notices 
        for notice in notices:
            children_count = db_api.notice_count_with_parent(notice.uuid)
            notice.children_count = children_count

        channel.page_total = notice_count / rows
        if not notice_count % rows == 0:
            channel.page_total += 1
        print channel.channel, notices
        return render.channel(channel=channel)
Ejemplo n.º 2
0
Archivo: main.py Proyecto: zz2/webchat
    def GET(self):
        x = web.input()
        print x
        channel_uuid = x.get('channel_uuid')
        rows = int(x.get('rows'))
        sord = x.get('sord')
        sidx = x.get('sidx')
        page = int(x.get('page'))
        offset = rows*(page-1)
        limit = rows
        print sord, sidx
        total = db_session.query(Notice_)\
                .filter(Notice_.channel_uuid==channel_uuid)\
                .filter(Notice_.is_locked==False)\
                .count()
        notices = db_session.query(Notice_)\
                .filter(Notice_.channel_uuid==channel_uuid)\
                .filter(Notice_.is_locked==False)\
                .order_by(getattr(sqlalchemy, sord.lower())(sidx))\
                .limit(limit)\
                .offset(offset).all()
        for notice in notices:
            children_count = db_api.notice_count_with_parent(notice.uuid)
            notice.children_count = children_count

        #设置显示id
        #if sord.lower() == 'asc':
            #index = offset + 1
            #for notice in notices:
                #notice.show_id = index
                #index += 1
        #else:
            #index = total - offset
            #for notice in notices:
                #notice.show_id = index
                #index -= 1

        page_total = total / rows
        if not total % rows == 0:
            page_total += 1
        return render.notice_grid(notices=notices, total=page_total, 
                page=page, records=total, channel_uuid=channel_uuid)
Ejemplo n.º 3
0
Archivo: main.py Proyecto: zz2/webchat
 def POST(self, notice_uuid):
     x = web.input()
     print x
     notice = x['notice']
     channel_uuid = x['channel_uuid']
     category = x.get('category')
     if category is None:
         category = 'root'
     parent_uuid = x.get('parent_uuid')
     if parent_uuid is None:
         parent_uuid = -1
     validity = 10
     values = {'notice':notice, 'validity':validity, 'category':category,
             'uuid':str(uuid.uuid4()), 'channel_uuid':channel_uuid, 
             'session_id':session.session_id, 'parent_uuid':parent_uuid}
     notice = db_api.notice_create(values)
     children_count = db_api.notice_count_with_parent(notice.uuid)
     notice.children_count = children_count
     if parent_uuid == -1:
         return render.notice_grid_raw(notice=notice)
     else:
         return render.notice_reply_grid_raw(notice_reply=notice)