Esempio n. 1
0
def delete_field(id):
    field = JsonMethods.get_field(id)
    endpoint_id = int(field.get('endpoint_id'))
    response = JsonMethods.delete_field(id)
    if response.get('status') == 'error':
        flash(response.get('message'), 'danger')
    else:
        flash(response.get('message'), 'success')
    return redirect(url_for('views.detail_endpoint', id=endpoint_id))
Esempio n. 2
0
def search_by_tags():
    tags = request.args.get('tags')
    apis = JsonMethods.get_apis(tags=tags)
    endpoints = JsonMethods.get_endpoints(tags=tags)
    edit_api_form = EditApiForm()
    add_endpoint_form = AddEndpointForm()
    edit_endpoint_form = EditEndpointForm()
    add_field_form = AddFieldForm()
    return render_template('search_by_tags.html',
                           apis=apis,
                           endpoints=endpoints,
                           edit_api_form=edit_api_form,
                           add_endpoint_form=add_endpoint_form,
                           edit_endpoint_form=edit_endpoint_form,
                           add_field_form=add_field_form)
Esempio n. 3
0
def detail_api(id):
    page = request.args.get('page', type=int, default=1)
    api = JsonMethods.get_api(id)
    endpoints = api.get('endpoints')
    total = len(endpoints)
    if total:
        try:
            endpoints = paginate(endpoints, Globals.ITEM_PER_PAGE, page,
                                 lambda x: int(x.get('id')))
        except:
            flash(
                'There is no %d pages of endpoints for API %d' %
                (page, api_id), 'danger')
            return redirect(url_for('views.list_endpoints'))

    pagination = Pagination(page=page,
                            per_page=Globals.ITEM_PER_PAGE,
                            total=total,
                            record_name='endpoints',
                            css_framework='bootstrap4')
    edit_api_form = EditApiForm()
    add_endpoint_form = AddEndpointForm()
    edit_endpoint_form = EditEndpointForm()
    add_field_form = AddFieldForm()
    return render_template('api_detailing.html',
                           api=api,
                           endpoints=endpoints,
                           pagination=pagination,
                           edit_api_form=edit_api_form,
                           add_endpoint_form=add_endpoint_form,
                           edit_endpoint_form=edit_endpoint_form,
                           add_field_form=add_field_form)
Esempio n. 4
0
def delete_endpoint(id):
    response = JsonMethods.delete_endpoint(id)
    if response.get('status') == 'error':
        flash(response.get('message'), 'danger')
    else:
        flash(response.get('message'), 'success')
    return redirect(url_for('views.list_endpoints'))
Esempio n. 5
0
def list_endpoints():
    page = request.args.get(get_page_parameter(), type=int, default=1)
    endpoints = JsonMethods.get_endpoints(page=page)
    total = JsonMethods.get_endpoints_count().get('count')
    pagination = Pagination(page=page,
                            per_page=Globals.ITEM_PER_PAGE,
                            total=total,
                            record_name='endpoints',
                            css_framework='bootstrap4')
    edit_endpoint_form = EditEndpointForm()
    add_field_form = AddFieldForm()
    return render_template('endpoints_listing.html',
                           endpoints=endpoints,
                           pagination=pagination,
                           edit_endpoint_form=edit_endpoint_form,
                           add_field_form=add_field_form)
Esempio n. 6
0
def detail_endpoint(id):
    endpoint = JsonMethods.get_endpoint(id)
    add_field_form = AddFieldForm()
    edit_endpoint_form = EditEndpointForm()
    edit_field_form = EditFieldForm()
    return render_template('endpoint_detailing.html',
                           endpoint=endpoint,
                           add_field_form=add_field_form,
                           edit_endpoint_form=edit_endpoint_form,
                           edit_field_form=edit_field_form)
Esempio n. 7
0
def edit_field(id):
    form = EditFieldForm()
    field = JsonMethods.get_field(id)
    endpoint_id = int(field.get('endpoint_id'))
    if form.validate_on_submit():
        response = JsonMethods.edit_field(id,
                                          label=form.label.data,
                                          field_type=form.type.data,
                                          required=form.required.data,
                                          default=form.default.data,
                                          description=form.description.data)
        if response.get('status') == 'error':
            flash(response.get('message'), 'danger')
        else:
            flash(response.get('message'), 'success')
    else:
        flash(
            "The following errors occured while editing field #%s: %s" %
            (id, form.errors), 'danger')
    return redirect(url_for('views.detail_endpoint', id=endpoint_id))
Esempio n. 8
0
def add_api():
    form = AddApiForm()
    if form.validate_on_submit():
        response = JsonMethods.add_api(label=form.label.data,
                                       url=form.url.data,
                                       description=form.description.data,
                                       tags=form.tags.data)
        if response.get('status') == 'ok':
            flash(response.get('message'), 'success')
            id = response.get('id')
            return redirect(url_for('views.detail_api', id=id))
        else:
            flash(response.get('message'), 'danger')
            return redirect(url_for('views.add_api'))
    return render_template('api_adding.html', form=form)
Esempio n. 9
0
def edit_endpoint(id):
    form = EditEndpointForm()
    if form.validate_on_submit():
        response = JsonMethods.edit_endpoint(id,
                                             label=form.label.data,
                                             url=form.url.data,
                                             description=form.description.data,
                                             tags=form.tags.data)
        if response.get('status') == 'error':
            flash(response.get('message'), 'danger')
        else:
            flash(response.get('message'), 'success')
    else:
        flash(
            "The following errors occured while editing endpoint #%s: %s" %
            (id, form.errors), 'danger')
    return redirect(url_for('views.detail_endpoint', id=id))