def post(self): form = json.loads(self.request.body) if 'user_id' in form: user = User.getUser(form['user_id']) if not user: return self.respond(error="User %(user_id)r does not exist" % form) user_streams = [Stream.getStream(stream_id).dumpStream() for stream_id in user.user_streams if Stream.exists(stream_id)] sub_streams = [Stream.getStream(stream_id).dumpStream() for stream_id in user.subscribed_streams if Stream.exists(stream_id)] payload = {'user_streams': user_streams , 'subscribed_streams': sub_streams , 'status': "Grabbed streams for user %(user_id)r" % form} elif 'streams' in form: streams = [Stream.getStream(s_id).dumpStream() for s_id in form['streams'] if Stream.exists(s_id)] payload = {'streams': streams} self.respond(**payload)
def post(self): form = json.loads(self.request.body) user = User.getUser(form['user_id']) if not user: return self.respond(error="User %(user_id)r does not exist" % form) if Stream.exists(form['stream_id']): return self.respond(error="Stream %(stream_id)r already exists" % form) # Create a new stream new_stream = Stream(user_id=form['user_id'] ,stream_id=form['stream_id'] ,last_add=None ,tags=form['tags'] ,cover_url=form['cover_url'] if 'cover_url' in form else '') # Update the user's stream list and insert stream into db user.addStream(new_stream) self.respond(status="Created stream %(stream_id)r for user %(user_id)r." % form)