def api_collection_new(): ''' New collection -------------- Create a new collection. :: /api/collection/new/ Accept POST queries only. :arg clt_name: String of the collection name to be created. :arg version: String of the version of the collection. :arg clt_status: String of the name of the user owner of the collection. :arg summary: A summary description of the collection. :arg description: A description of the collection. :arg branchname: The short name of the collection (ie: F-18). :arg dist_tag: The dist tag used by rpm for this collection (ie: .fc18). :arg kojiname: the name of the collection in koji. Sample response: :: { "output": "ok", "messages": ["Collection F-20 created"] } { "output": "notok", "error": ["You are not allowed to create collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.AddCollectionForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_name = form.clt_name.data clt_version = form.version.data clt_status = form.clt_status.data clt_branchname = form.branchname.data clt_disttag = form.dist_tag.data clt_koji_name = form.kojiname.data try: message = pkgdblib.add_collection( SESSION, clt_name=clt_name, clt_version=clt_version, clt_status=clt_status, clt_branchname=clt_branchname, clt_disttag=clt_disttag, clt_koji_name=clt_koji_name, user=flask.g.fas_user, ) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] # Apparently we're pretty tight on checks and looks like we cannot # raise this exception in a normal situation except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def api_collection_new(): ''' New collection -------------- Create a new collection. :: /api/collection/new/ Accepts POST queries only. :arg clt_name: String of the collection name to be created. :arg version: String of the version of the collection. :arg clt_status: String of the name of the user owner of the collection. :arg summary: A summary description of the collection. :arg description: A description of the collection. :arg branchname: The short name of the collection (ie: F-18). :arg dist_tag: The dist tag used by rpm for this collection (ie: .fc18). :arg kojiname: the name of the collection in koji. :kwarg allow_retire: a boolean specifying if the collection should allow retiring a package or not. Defaults to ``False``. Sample response: :: { "output": "ok", "messages": ["Collection F-20 created"] } { "output": "notok", "error": ["You are not allowed to create collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.AddCollectionForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_name = form.clt_name.data clt_version = form.version.data clt_status = form.clt_status.data clt_branchname = form.branchname.data clt_disttag = form.dist_tag.data clt_koji_name = form.kojiname.data clt_allow_retire = form.allow_retire.data or False try: message = pkgdblib.add_collection( SESSION, clt_name=clt_name, clt_version=clt_version, clt_status=clt_status, clt_branchname=clt_branchname, clt_disttag=clt_disttag, clt_koji_name=clt_koji_name, clt_allow_retire=clt_allow_retire, user=flask.g.fas_user, ) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] # Apparently we're pretty tight on checks and looks like we cannot # raise this exception in a normal situation except PkgdbException as err: # pragma: no cover SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500 else: output['output'] = 'notok' output['error'] = 'Invalid input submitted' if form.errors: detail = [] for error in form.errors: detail.append('%s: %s' % (error, '; '.join(form.errors[error]))) output['error_detail'] = detail httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout