def POST(self): data = web.input() if not data or not data.has_key('content') or len(data['content']) == 0: self.response.error = ResponseStatus.STATUS_INCORRECT_PARAMS self.response.msg = "invalid parameters" return self.render() content = data['content'] p = Post( username=self.session.user.username, author=self.session.user.username, content=content, create_time=int(time.time()) ) topics = Post.parse_topic(content) if not topics or len(topics) == 0: self.response.error = ResponseStatus.STATUS_INCORRECT_PARAMS self.response.msg = "missing topic" return self.render() web.ctx.orm.add(p) web.ctx.orm.flush() if 'position' in data and 'address' in data: geodata = data.position.split(',') (lat, lng) = geodata if len(geodata) == 2 else (None, None) if lat and lng and data.address: geo = PostGeo( post_id=p.id, lat=lat, lng=lng, address=data.address ) web.ctx.orm.add(geo) for topic in topics: post_topic = PostTopic( post_id=p.id, topic=topic ) web.ctx.orm.add(post_topic) mentions = Post.parse_mention(content) users = web.ctx.orm.query(User).filter(User.username.in_(mentions)).all() if len(mentions) > 0 else [] for user in users: mention = Mention( username=user.username, post_id=p.id ) web.ctx.orm.add(mention) return self.render()
def POST(self): data = web.input() if not data or not data.has_key('content') or len(data['content']) == 0: return "invalid post." content = data['content'] p = Post( username=self.session.user.username, author=self.session.user.username, content=content, create_time=int(time.time()) ) topics = Post.parse_topic(content) if not topics or len(topics) == 0: raise web.notfound web.ctx.orm.add(p) web.ctx.orm.flush() if 'position' in data: geodata = data.position.split(',') (lat, lng) = geodata if len(geodata) == 2 else (None, None) if lat and lng: geo = postGeo( post_id=p.id, lat=lat, lng=lng ) web.ctx.orm.add(geo) for topic in topics: post_topic = PostTopic( post_id=p.id, topic=topic ) web.ctx.orm.add(post_topic) mentions = Post.parse_mention(content) users = web.ctx.orm.query(User).filter(User.username.in_(mentions)).all() if len(mentions) > 0 else [] for user in users: mention = Mention( username=user.username, post_id=p.id ) web.ctx.orm.add(mention) return web.seeother('/post')