def tag_qc(id): record = api.get(f'/record/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs false boolean field if request.method == 'POST': form = RecordTagQCForm(request.form) else: record_tag = next( (tag for tag in record['tags'] if tag['tag_id'] == ODPRecordTag.QC and tag['user_id'] == current_user.id), None) form = RecordTagQCForm(data=record_tag['data'] if record_tag else None) if request.method == 'POST' and form.validate(): try: api.post( f'/record/{id}/tag', dict( tag_id=ODPRecordTag.QC, data={ 'pass_': form.pass_.data, 'comment': form.comment.data, }, )) flash(f'{ODPRecordTag.QC} tag has been set.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): role = api.get(f'/role/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs empty multiselect field if request.method == 'POST': form = RoleForm(request.form) else: form = RoleForm(data=role) utils.populate_collection_choices(form.collection_id, include_none=True) utils.populate_scope_choices(form.scope_ids, ('odp', 'client')) if request.method == 'POST' and form.validate(): try: api.put( '/role/', dict( id=id, collection_id=form.collection_id.data or None, scope_ids=form.scope_ids.data, )) flash(f'Role {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): project = api.get(f'/project/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs empty multiselect field if request.method == 'POST': form = ProjectForm(request.form) else: form = ProjectForm(data=project) utils.populate_collection_choices(form.collection_ids) if request.method == 'POST' and form.validate(): try: api.put( '/project/', dict( id=id, name=form.name.data, collection_ids=form.collection_ids.data, )) flash(f'Project {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): user = api.get(f'/user/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs empty multiselect field if request.method == 'POST': form = UserForm(request.form) else: form = UserForm(data=user) utils.populate_role_choices(form.role_ids) if request.method == 'POST' and form.validate(): try: api.put( '/user/', dict( id=id, active=form.active.data, role_ids=form.role_ids.data, )) flash(f'User {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): provider = api.get(f'/provider/{id}') form = ProviderForm(request.form, data=provider) if request.method == 'POST' and form.validate(): try: api.put('/provider/', dict( id=id, name=form.name.data, )) flash(f'Provider {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): client = api.get(f'/client/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs empty multiselect field if request.method == 'POST': form = ClientForm(request.form) else: form = ClientForm(data=client) form.secret.description = 'Client secret will remain unchanged if left blank.' utils.populate_collection_choices(form.collection_id, include_none=True) utils.populate_scope_choices(form.scope_ids) if request.method == 'POST' and form.validate(): try: api.put( '/client/', dict( id=id, name=form.name.data, secret=form.secret.data or None, collection_id=form.collection_id.data or None, scope_ids=form.scope_ids.data, grant_types=form.grant_types.data, response_types=form.response_types.data, redirect_uris=form.redirect_uris.data.split(), post_logout_redirect_uris=form.post_logout_redirect_uris. data.split(), token_endpoint_auth_method=form.token_endpoint_auth_method. data, allowed_cors_origins=form.allowed_cors_origins.data.split( ), )) flash(f'Client {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def edit(id): collection = api.get(f'/collection/{id}') form = CollectionForm(request.form, data=collection) utils.populate_provider_choices(form.provider_id) if request.method == 'POST' and form.validate(): try: api.put( '/collection/', dict( id=id, name=form.name.data, provider_id=form.provider_id.data, doi_key=form.doi_key.data or None, )) flash(f'Collection {id} has been updated.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
def tag_embargo(id): record = api.get(f'/record/{id}') if request.method == 'POST': form = RecordTagEmbargoForm(request.form) else: # embargo tag has cardinality 'multi', so this will always be an insert form = RecordTagEmbargoForm() if request.method == 'POST' and form.validate(): if not form.start.data and not form.end.data: flash('Please specify a start and/or end date.', category='error') else: try: api.post( f'/record/{id}/tag', dict( tag_id=ODPRecordTag.EMBARGO, data={ 'start': form.start.data.isoformat() if form.start.data else None, 'end': form.end.data.isoformat() if form.end.data else None, 'comment': form.comment.data, }, )) flash(f'{ODPRecordTag.EMBARGO} tag has been set.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response
utils.populate_scope_choices(form.scope_ids, ('odp', 'client')) if request.method == 'POST' and form.validate(): try: api.post( '/role/', dict( id=(id := form.id.data), collection_id=form.collection_id.data or None, scope_ids=form.scope_ids.data, )) flash(f'Role {id} has been created.', category='success') return redirect(url_for('.view', id=id)) except api.ODPAPIError as e: if response := api.handle_error(e): return response return render_template('role_edit.html', form=form) @bp.route('/<id>/edit', methods=('GET', 'POST')) @api.client(ODPScope.ROLE_ADMIN) def edit(id): role = api.get(f'/role/{id}') # separate get/post form instantiation to resolve # ambiguity of missing vs empty multiselect field if request.method == 'POST': form = RoleForm(request.form) else: