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)
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)
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
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)
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
def channel_get_with_channel(channel): channel = session.query(Channel).filter(Channel.channel==channel).one() return channel
def channel_count_with_channel(channel): count = session.query(Channel).filter(Channel.channel==channel).count() return count
def channel_get_with_uuid(channel_uuid): channel = session.query(Channel).filter(Channel.uuid==channel_uuid).one() return channel
def notice_count_with_parent(parent_uuid): count = session.query(Notice).filter(Notice.parent_uuid==parent_uuid).count() return count
def notice_get_all(): notices = session.query(Notice).all() return notices
def notice_count_with_channel(channel_uuid): count = session.query(Notice).filter(Notice.channel_uuid==channel_uuid).count() return count
def notice_get_with_channel(channel_uuid): notices = session.query(Notice).filter(Notice.channel_uuid==channel_uuid).all() return notices
def notice_delete_with_uuid(notice_uuid): notice = session.query(Notice).filter(Notice.uuid==notice_uuid).one() session.delete(notice) session.commit()
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