def POST(self, channel): x = web.input() print x channel = x['channel'] channel_uuid = str(uuid.uuid4()) lng = x['lng'] lat = x['lat'] desp = x['desp'] address = x['address'] values = {'channel':channel, 'uuid':channel_uuid, 'lng':lng, 'lat':lat, 'desp':desp, 'address':address, 'founder':session.session_id} count = db_api.channel_count_with_channel(channel) channel_is_existed = False if count == 0: channel = db_api.channel_create(values) else: channel_is_existed = True channel = db_api.channel_get_with_channel(channel) web.header("Content-Type", "application/json") i = channel data = {'id':i.id, 'channel':i.channel, 'lng':i.lng, 'lat':i.lat, 'founder':i.founder, 'uuid':i.uuid, 'desp':i.desp,'create_time':str(i.create_time), 'result':'SUCC', 'address':i.address, 'e':''} if channel_is_existed: data.update({ 'result':'error', 'e':'该名字已经存在,请换个名字'}) print data return json.dumps(data)
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)