コード例 #1
0
ファイル: views.py プロジェクト: IFCA/lifewatch_osf
def autocomplete(field_name=None):
    """Auto-complete a form field."""
    term = request.args.get('term')  # value
    limit = request.args.get('limit', 50, type=int)

    form = InstrumentForm(request.values, crsf_enabled=False)
    result = form.autocomplete(field_name, term, limit=limit)
    result = result if result is not None else []

    # jsonify doesn't return lists as top-level items.
    resp = make_response(
        json.dumps(result, indent=None if request.is_xhr else 2))
    resp.mimetype = "application/json"
    return resp
コード例 #2
0
ファイル: views.py プロジェクト: rsalas82/lw-daap
def autocomplete(field_name=None):
    """Auto-complete a form field."""
    term = request.args.get('term')  # value
    limit = request.args.get('limit', 50, type=int)

    form = InstrumentForm(request.values, crsf_enabled=False)
    result = form.autocomplete(field_name, term, limit=limit)
    result = result if result is not None else []

    # jsonify doesn't return lists as top-level items.
    resp = make_response(
        json.dumps(result, indent=None if request.is_xhr else 2)
    )
    resp.mimetype = "application/json"
    return resp
コード例 #3
0
ファイル: views.py プロジェクト: rsalas82/lw-daap
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)
コード例 #4
0
ファイル: views.py プロジェクト: IFCA/lifewatch_osf
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)