def register(): uuid = request.form.get('uuid') channel_key = request.form.get('channel_key') if not uuid: return to_error_json("uuid is required") elif not channel_key: return to_error_json("channel_key is required") sub = Subscription.query.filter_by(uuid=uuid).filter_by( channel_key=channel_key).first() if sub is None: channel_name = Channel.query.with_entities( Channel.name).filter_by(listen_key=channel_key).first() subscription = Subscription(uuid=uuid, channel_key=channel_key, channel_name=channel_name[0]) db.session.add(subscription) db.session.commit() return jsonify(subscription.dict()) else: return to_error_json("Subscription already exists")