def api_collection_status(collection): ''' Update collection status ------------------------ Update the status of collection. :: /api/collection/<collection branchname>/status/ Accepts POST query only. :arg branch: String of the collection branch name to change. :arg clt_status: String of the status to change the collection to Sample response: :: { "output": "ok", "messages": ["Collection updated to \"EOL\""] } { "output": "notok", "error": ["You are not allowed to edit collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.CollectionStatusForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_branchname = form.branch.data clt_status = form.clt_status.data if collection == clt_branchname: try: message = pkgdblib.update_collection_status( SESSION, clt_branchname, clt_status, user=flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500 else: output['output'] = 'notok' output['error'] = "You're trying to update the " \ "wrong collection" httpcode = 500
def api_collection_status(collection): ''' Update collection status ------------------------ Update the status of collection. :: /api/collection/<collection branchname>/status/ Accept POST query only. :arg collection_branchname: String of the collection branch name to change. :arg collection_status: String of the status to change the collection to Sample response: :: { "output": "ok", "messages": ["Collection updated to \"EOL\""] } { "output": "notok", "error": ["You are not allowed to edit collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.CollectionStatusForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_branchname = form.collection_branchname.data clt_status = form.collection_status.data if collection == clt_branchname: try: message = pkgdblib.update_collection_status( SESSION, clt_branchname, clt_status, user=flask.g.fas_user ) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500 else: output['output'] = 'notok' output['error'] = "You're trying to update the " \ "wrong collection" httpcode = 500
def api_collection_status(collection): ''' Update collection status ------------------------ Update the status of collection. :: /api/collection/<collection branchname>/status/ Accepts POST query only. :arg branch: String of the collection branch name to change. :arg clt_status: String of the status to change the collection to Sample response: :: { "output": "ok", "messages": ["Collection updated to \"EOL\""] } { "output": "notok", "error": ["You are not allowed to edit collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.CollectionStatusForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_branchname = form.branch.data clt_status = form.clt_status.data if collection == clt_branchname: try: message = pkgdblib.update_collection_status( SESSION, clt_branchname, clt_status, user=flask.g.fas_user ) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] except PkgdbException as err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500 else: output['output'] = 'notok' output['error'] = "You're trying to update the " \ "wrong collection" 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