コード例 #1
0
ファイル: main.py プロジェクト: 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)
コード例 #2
0
ファイル: main.py プロジェクト: zz2/webchat
    def GET(self):
        x = web.input()
        print x
        parent_uuid = x.get('parent_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
        total = db_session.query(Notice_)\
                .filter(Notice_.parent_uuid==parent_uuid)\
                .filter(Notice_.is_locked==False)\
                .count()
        notices = db_session.query(Notice_)\
                .filter(Notice_.parent_uuid==parent_uuid)\
                .filter(Notice_.is_locked==False)\
                .order_by(getattr(sqlalchemy, sord.lower())(sidx))\
                .limit(limit)\
                .offset(offset).all()
        page_total = total / rows
        if not total % rows == 0:
            page_total += 1

        #设置显示id
        #index = offset + 1
        #for notice in notices:
            #notice.show_id = index
            #index += 1

        print notices
        return render.notice_reply_grid(notice_replys=notices, total=page_total, 
                page=page, records=total)
コード例 #3
0
ファイル: api.py プロジェクト: zz2/webchat
def channel_get_around(lng, lat):
    around = 0.05
    lng_min = float(lng) - around
    lng_max = float(lng) + around
    lat_min = float(lat) - around
    lat_max = float(lat) + around
    channels = session.query(Channel).filter(Channel.lng<lng_max) \
            .filter(Channel.lng>lng_min).filter(Channel.lat<lat_max) \
            .filter(Channel.lat>lat_min).all()
    return channels
コード例 #4
0
ファイル: main.py プロジェクト: 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)
コード例 #5
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_get_rows_with_channel(rows, sord, sidx, page, channel_uuid):
    '''page = 1++ 
        sord = desc, asc,
    '''
    assert page >= 1
    offset = rows*(page-1)
    limit = rows
    notices = session.query(Notice)\
            .filter(Notice.channel_uuid==channel_uuid)\
            .order_by(getattr(sqlalchemy, sord.lower())(sidx)).\
            limit(limit).offset(offset).all()
    return notices 
コード例 #6
0
ファイル: api.py プロジェクト: zz2/webchat
def channel_get_with_channel(channel):
    channel = session.query(Channel).filter(Channel.channel==channel).one()
    return channel
コード例 #7
0
ファイル: api.py プロジェクト: zz2/webchat
def channel_count_with_channel(channel):
    count = session.query(Channel).filter(Channel.channel==channel).count()
    return count
コード例 #8
0
ファイル: api.py プロジェクト: zz2/webchat
def channel_get_with_uuid(channel_uuid):
    channel = session.query(Channel).filter(Channel.uuid==channel_uuid).one()
    return channel
コード例 #9
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_count_with_parent(parent_uuid):
    count = session.query(Notice).filter(Notice.parent_uuid==parent_uuid).count()
    return count
コード例 #10
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_get_all():
    notices = session.query(Notice).all()
    return notices
コード例 #11
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_count_with_channel(channel_uuid):
    count = session.query(Notice).filter(Notice.channel_uuid==channel_uuid).count()
    return count
コード例 #12
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_get_with_channel(channel_uuid):
    notices = session.query(Notice).filter(Notice.channel_uuid==channel_uuid).all()
    return notices
コード例 #13
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_delete_with_uuid(notice_uuid):
    notice = session.query(Notice).filter(Notice.uuid==notice_uuid).one()
    session.delete(notice)
    session.commit()
コード例 #14
0
ファイル: api.py プロジェクト: zz2/webchat
def notice_update_with_uuid(notice_uuid, values):
    notice = session.query(Notice).filter(Notice.uuid==notice_uuid).one()
    notice.update(values)
    session.commit()
    return notice