Ejemplo n.º 1
0
def save():
    is_submit = request.args.get('submit') == '1'
    is_complete_form = request.args.get('all') == '1'


    if request.method != 'POST':
        abort(400)

    data = request.json or MultiDict({})

    if 'access_groups' in data:
        del data['access_groups']
    uid = current_user.get_id()

    instrument = Instrument(user_id=uid, **data)
    dummy_form, validated, result = instrument.process(
        data, complete_form=is_complete_form or is_submit
    )

    # if validated and is_submit:
    #     instrument.complete()

    try:
        return jsonify(result)
    except TypeError:
        return jsonify(None)
Ejemplo n.º 2
0
def index(p, so, page):
    page = max(page, 1)
    per_page = cfg.get('INSTRUMENTS_DISPLAYED_PER_PAGE', 9)

    instruments = getPaginatedInstrumentsByIdUser(current_user['id'],p, page, per_page)
    count = getCountInstrumentsByIdUser(current_user['id'],p)
    instruments_json = json.loads(instruments)

    form = SearchForm()

    my_array = [None] * 0
    for instrument in instruments_json:
       i = Instrument.from_json(instrument)
       my_array.append(i)

    pagination = Pagination(page, per_page, count)

    ctx = dict(
        instruments=my_array,
        form=form,
        page=page,
        per_page=per_page,
        pagination = pagination,
    )

    return render_template(
        "instruments/index.html",
        **ctx
    )
Ejemplo n.º 3
0
def index(p, so, page):
    page = max(page, 1)
    per_page = cfg.get('INSTRUMENTS_DISPLAYED_PER_PAGE', 9)

    instruments = getPaginatedInstrumentsByIdUser(current_user['id'], p, page,
                                                  per_page)
    count = getCountInstrumentsByIdUser(current_user['id'], p)
    instruments_json = json.loads(instruments)

    form = SearchForm()

    my_array = [None] * 0
    for instrument in instruments_json:
        i = Instrument.from_json(instrument)
        my_array.append(i)

    pagination = Pagination(page, per_page, count)

    ctx = dict(
        instruments=my_array,
        form=form,
        page=page,
        per_page=per_page,
        pagination=pagination,
    )

    return render_template("instruments/index.html", **ctx)
Ejemplo n.º 4
0
def save():
    is_submit = request.args.get('submit') == '1'
    is_complete_form = request.args.get('all') == '1'

    if request.method != 'POST':
        abort(400)

    data = request.json or MultiDict({})

    if 'access_groups' in data:
        del data['access_groups']
    uid = current_user.get_id()

    instrument = Instrument(user_id=uid, **data)
    dummy_form, validated, result = instrument.process(
        data, complete_form=is_complete_form or is_submit)

    # if validated and is_submit:
    #     instrument.complete()

    try:
        return jsonify(result)
    except TypeError:
        return jsonify(None)
Ejemplo n.º 5
0
def new():
    uid = current_user.get_id()
    form = InstrumentForm(request.values, crsf_enabled=False)

    ctx = {
        'form': form,
        'is_new': True,
        'instruments': None,
    }

    if request.method == 'POST' and form.validate():
        data = form.data

        # Extract access_groups from Instrument data
        access_groups = data['access_groups']
        del data['access_groups']

        # Depends on the access right selected, clean some instrument fields
        i = Instrument(user_id=uid, **data)
        if i.access_right == "open":
            i.access_conditions = ""
            i.embargo_date = ""
        elif i.access_right == "embargoed":
            i.access_conditions = ""
        elif i.access_right == "restricted":
            i.embargo_date = ""
            i.license = ""
        else:
            i.access_conditions = ""
            i.embargo_date = ""
            i.license = ""

        db.session.commit()

        # Check if logged user has configured the profile BD fields
        userInfo = getUserInfoByPortalUser(current_user['nickname'])
        userInfoJson = json.loads(userInfo)
        if userInfoJson['databaseUser']:
            # If already exists an instrument with the chosen name: show an error message
            # Else: Save instrument data
            try:
                instrumentWithSameName = findInstrumentByName(i.name)
                flash("Already exists an instrument with the same name. Please choose another name.", category='error')
            except Exception as e:
                instrument = createInstrument(i.name, i.embargo_date, i.access_right, i.user_id, i.license, i.access_conditions, userInfoJson['databaseUser'], current_user['nickname'])
                jsonInstrument = json.loads(instrument)
                if (jsonInstrument['idInstrument']) >= 0:
                    i.id = int(jsonInstrument['idInstrument'])
                    if i.access_right == 'restricted':
                        for group in access_groups:
                            try:
                                addPermissionGroup(i.name, group['identifier'])
                            except Exception as e:
                                flash("There was an error. Please, contact with the Lifewatch site administrator.", category='error')
                    flash("Instrument was successfully created.", category='success')
                    return redirect(url_for('.show', instrument_id=i.id))
                else:
                    flash("There was an error. Please, contact with the Lifewatch site administrator.", category='error')
        else:
            flash("The database user doesn't exist. Please update your profile before registering an instrument.", category='error')


    return render_template("instruments/new.html", **ctx)
Ejemplo n.º 6
0
def new():
    uid = current_user.get_id()
    form = InstrumentForm(request.values, crsf_enabled=False)

    ctx = {
        'form': form,
        'is_new': True,
        'instruments': None,
    }

    if request.method == 'POST' and form.validate():
        data = form.data

        # Extract access_groups from Instrument data
        access_groups = data['access_groups']
        del data['access_groups']

        # Depends on the access right selected, clean some instrument fields
        i = Instrument(user_id=uid, **data)
        if i.access_right == "open":
            i.access_conditions = ""
            i.embargo_date = ""
        elif i.access_right == "embargoed":
            i.access_conditions = ""
        elif i.access_right == "restricted":
            i.embargo_date = ""
            i.license = ""
        else:
            i.access_conditions = ""
            i.embargo_date = ""
            i.license = ""

        db.session.commit()

        # Check if logged user has configured the profile BD fields
        userInfo = getUserInfoByPortalUser(current_user['nickname'])
        userInfoJson = json.loads(userInfo)
        if userInfoJson['databaseUser']:
            # If already exists an instrument with the chosen name: show an error message
            # Else: Save instrument data
            try:
                instrumentWithSameName = findInstrumentByName(i.name)
                flash(
                    "Already exists an instrument with the same name. Please choose another name.",
                    category='error')
            except Exception as e:
                instrument = createInstrument(i.name, i.embargo_date,
                                              i.access_right, i.user_id,
                                              i.license, i.access_conditions,
                                              userInfoJson['databaseUser'],
                                              current_user['nickname'])
                jsonInstrument = json.loads(instrument)
                if (jsonInstrument['idInstrument']) >= 0:
                    i.id = int(jsonInstrument['idInstrument'])
                    if i.access_right == 'restricted':
                        for group in access_groups:
                            try:
                                addPermissionGroup(i.name, group['identifier'])
                            except Exception as e:
                                flash(
                                    "There was an error. Please, contact with the Lifewatch site administrator.",
                                    category='error')
                    flash("Instrument was successfully created.",
                          category='success')
                    return redirect(url_for('.show', instrument_id=i.id))
                else:
                    flash(
                        "There was an error. Please, contact with the Lifewatch site administrator.",
                        category='error')
        else:
            flash(
                "The database user doesn't exist. Please update your profile before registering an instrument.",
                category='error')

    return render_template("instruments/new.html", **ctx)