def edit(crawler, data, app_hash): crawler.go(conf.YOM_EDIT_URL.format(app_hash=app_hash)) scopes_check = decompress_scopes(data.get('scopes', [])) scopes_uncheck = decompress_scopes(data.get('scopes_uncheck', [])) for field_name, value in data.items(): if not field_name.startswith('scopes'): crawler.doc.set_input(field_name, value) for scopes, value in ((scopes_check, True), (scopes_uncheck, False)): for scope in scopes: crawler.doc.set_input('scopes:%s' % scope, value) inputs = crawler.doc.form.inputs if scopes_uncheck \ and not any(inputs[name].checked for name in inputs.keys() if name.startswith('scopes')): raise YomValidationError('There should remain at least one scope') app_hash = crawler.doc.url.replace( conf.YOM_EDIT_URL.format(app_hash=''), '') crawler.doc.submit() app_data = get_detail(crawler, app_hash) title = dict(app_data)['title'] return { 'header': 'The "%s" application has been edited' % title, 'table': app_data }
def create(crawler, data): scopes = data.get('scopes', []) for field_name, value in data.items(): if not field_name.startswith('scopes'): crawler.doc.set_input(field_name, value) for scope in decompress_scopes(scopes): crawler.doc.set_input('scopes:%s' % scope, True) crawler.doc.submit() app_hash = crawler.doc.url.replace( conf.YOM_DETAIL_URL.format(app_hash=''), '') app_data = get_detail(crawler, app_hash) title = dict(app_data)['title'] return { 'header': 'The "%s" application has been created' % title, 'table': app_data }
def scopes_set(data): return set(decompress_scopes(data))