Пример #1
0
def add_facility():
    session_init(session, db)
    error = None
    if session['username'] is None:
        error = 'must be logged in to add a facility'
        return redirect(url_for('beamlines', error=error))

    if request.method == 'POST':
        fac_name = request.form['facility_name']
        _facnames = [s.name for s in db.filtered_query('facility')]
        try:
            fac_name = unique_name(fac_name,
                                   _facnames,
                                   msg='facility',
                                   maxcount=5)
        except:
            error = 'a facility named %s exists'
        db.add_beamline(fac_name)
        time.sleep(1)
        return redirect(url_for('list_facilities', error=error))
    else:
        facilities = []
        for r in db.filtered_query('facility'):
            facilities.append({'id': r.id, 'name': r.name})
        return render_template('add_facility.html',
                               error=error,
                               facilities=facilities)
Пример #2
0
def add_beamline():
    session_init(session, db)
    error=None
    if session['username'] is None:
        error='must be logged in to add a beamline'
        return redirect(url_for('beamlines', error=error))

    if request.method == 'POST':
        bl_name = request.form['beamline_name']
        notes = request.form['notes']
        fac_id = int(request.form['fac_id'])
        source = request.form['xray_source']

        _blnames = [s.name for s in db.filtered_query('beamline')]
        try:
            bl_name = unique_name(bl_name, _blnames,
                                  msg='beamline', maxcount=5)
        except:
            error = 'a beamline named %s exists'

        db.add_beamline(bl_name, notes=notes, xray_source=source,
                        facility_id=fac_id)

        time.sleep(1)
        return redirect(url_for('beamlines', error=error))
    else:
        facilities = []
        for r in db.filtered_query('facility'):
            facilities.append({'id': r.id, 'name': r.name})
        return render_template('add_beamline.html', error=error,
                               facilities=facilities)
Пример #3
0
def add_suite():
    session_init(session, db)
    error=None
    if session['username'] is None:
        error='must be logged in to add a suite'
        return redirect(url_for('suites', error=error))

    if request.method == 'POST':
        suite_name = request.form['suite_name']
        person_id = request.form['person']
        notes = request.form['notes']
        _sname = [s.name for s in db.filtered_query('suite')]
        try:
            suite_name = unique_name(suite_name, _sname,  msg='suite')
        except:
            error = 'a suite named %s exists'
        db.add_suite(suite_name, notes=notes, person_id=int(person_id))
        time.sleep(0.5)
        return redirect(url_for('suites', error=error))
    else:

        return render_template('add_suite.html', error=error,
                               person_id=session['person_id'])
Пример #4
0
def add_facility():
    session_init(session, db)
    error=None
    if session['username'] is None:
        error='must be logged in to add a facility'
        return redirect(url_for('beamlines', error=error))

    if request.method == 'POST':
        fac_name = request.form['facility_name']
        _facnames = [s.name for s in db.filtered_query('facility')]
        try:
            fac_name = unique_name(fac_name, _facnames,  msg='facility', maxcount=5)
        except:
            error = 'a facility named %s exists'
        db.add_beamline(fac_name)
        time.sleep(1)
        return redirect(url_for('list_facilities', error=error))
    else:
        facilities = []
        for r in db.filtered_query('facility'):
            facilities.append({'id': r.id, 'name': r.name})
        return render_template('add_facility.html', error=error,
                               facilities=facilities)
Пример #5
0
def add_suite():
    session_init(session, db)
    error = None
    if session['username'] is None:
        error = 'must be logged in to add a suite'
        return redirect(url_for('suites', error=error))

    if request.method == 'POST':
        suite_name = request.form['suite_name']
        person_id = request.form['person']
        notes = request.form['notes']
        _sname = [s.name for s in db.filtered_query('suite')]
        try:
            suite_name = unique_name(suite_name, _sname, msg='suite')
        except:
            error = 'a suite named %s exists'
        db.add_suite(suite_name, notes=notes, person_id=int(person_id))
        time.sleep(0.5)
        return redirect(url_for('suites', error=error))
    else:

        return render_template('add_suite.html',
                               error=error,
                               person_id=session['person_id'])
Пример #6
0
def add_beamline():
    session_init(session, db)
    error = None
    if session['username'] is None:
        error = 'must be logged in to add a beamline'
        return redirect(url_for('beamlines', error=error))

    if request.method == 'POST':
        bl_name = request.form['beamline_name']
        notes = request.form['notes']
        fac_id = int(request.form['fac_id'])
        source = request.form['xray_source']

        _blnames = [s.name for s in db.filtered_query('beamline')]
        try:
            bl_name = unique_name(bl_name,
                                  _blnames,
                                  msg='beamline',
                                  maxcount=5)
        except:
            error = 'a beamline named %s exists'

        db.add_beamline(bl_name,
                        notes=notes,
                        xray_source=source,
                        facility_id=fac_id)

        time.sleep(1)
        return redirect(url_for('beamlines', error=error))
    else:
        facilities = []
        for r in db.filtered_query('facility'):
            facilities.append({'id': r.id, 'name': r.name})
        return render_template('add_beamline.html',
                               error=error,
                               facilities=facilities)