def get_register_name(): try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_errors(api_error) available_stores = logic.filter_available_stores(user["stores"]) snap_name = flask.request.args.get("snap_name", default="", type=str) conflict_str = flask.request.args.get( "conflict", default="False", type=str ) conflict = conflict_str == "True" already_owned_str = flask.request.args.get( "already_owned", default="False", type=str ) already_owned = already_owned_str == "True" is_private_str = flask.request.args.get( "is_private", default="False", type=str ) is_private = is_private_str == "True" context = { "snap_name": snap_name, "is_private": is_private, "conflict": conflict, "already_owned": already_owned, "available_stores": available_stores, } return flask.render_template("publisher/register-snap.html", **context)
def get_register_name(): try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_errors(api_error) available_stores = logic.filter_available_stores(user["stores"]) snap_name = flask.request.args.get("snap_name", default="", type=str) conflict_str = flask.request.args.get( "conflict", default="False", type=str ) conflict = conflict_str == "True" already_owned_str = flask.request.args.get( "already_owned", default="False", type=str ) already_owned = already_owned_str == "True" is_private_str = flask.request.args.get( "is_private", default="False", type=str ) is_private = is_private_str == "True" context = { "snap_name": snap_name, "is_private": is_private, "conflict": conflict, "already_owned": already_owned, "available_stores": available_stores, } return flask.render_template("publisher/register-snap.html", **context)
def post_register_name(): snap_name = flask.request.form.get("snap-name") if not snap_name: return flask.redirect(flask.url_for(".get_register_name")) is_private = flask.request.form.get("is_private") == "private" store = flask.request.form.get("store") registrant_comment = flask.request.form.get("registrant_comment") try: api.post_register_name( session=flask.session, snap_name=snap_name, is_private=is_private, store=store, registrant_comment=registrant_comment, ) except ApiResponseErrorList as api_response_error_list: try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_error(api_error) available_stores = logic.filter_available_stores(user["stores"]) if api_response_error_list.status_code == 409: for error in api_response_error_list.errors: if error["code"] == "already_claimed": return flask.redirect( flask.url_for("account.get_account_details")) elif error["code"] == "already_registered": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, conflict=True, )) elif error["code"] == "already_owned": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, already_owned=True, )) elif error["code"] == "reserved_name": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, reserved=True, )) context = { "snap_name": snap_name, "is_private": is_private, "available_stores": available_stores, "errors": api_response_error_list.errors, } return flask.render_template("publisher/register-snap.html", **context) except ApiError as api_error: return _handle_error(api_error) flask.flash("".join([ snap_name, " registered.", ' <a href="https://docs.snapcraft.io/build-snaps/upload"', ' class="p-link--external"', ' target="blank">How to upload a Snap</a>', ])) return flask.redirect(flask.url_for("account.get_account"))
def post_register_name(): snap_name = flask.request.form.get("snap-name") if not snap_name: return flask.redirect(flask.url_for(".get_register_name")) is_private = flask.request.form.get("is_private") == "private" store = flask.request.form.get("store") registrant_comment = flask.request.form.get("registrant_comment") try: api.post_register_name( session=flask.session, snap_name=snap_name, is_private=is_private, store=store, registrant_comment=registrant_comment, ) except ApiResponseErrorList as api_response_error_list: try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_errors(api_error) available_stores = logic.filter_available_stores(user["stores"]) if api_response_error_list.status_code == 409: for error in api_response_error_list.errors: if error["code"] == "already_claimed": return flask.redirect( flask.url_for("account.get_account_details") ) elif error["code"] == "already_registered": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, conflict=True, ) ) elif error["code"] == "already_owned": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, already_owned=True, ) ) context = { "snap_name": snap_name, "is_private": is_private, "available_stores": available_stores, "errors": api_response_error_list.errors, } return flask.render_template("publisher/register-snap.html", **context) except ApiError as api_error: return _handle_errors(api_error) flask.flash( "".join( [ snap_name, " registered.", ' <a href="https://docs.snapcraft.io/build-snaps/upload"', ' class="p-link--external"', ' target="blank">How to upload a Snap</a>', ] ) ) return flask.redirect(flask.url_for("account.get_account"))