Ejemplo n.º 1
0
def inquiries_privacy(id):
    '''
    This is for privacy settings.
    '''
    #access is only allowed if gdpr is set to true
    cnfg = ConfigurationModel.find()
    if cnfg is None:
        abort(404)
    if cnfg.dsgvo != 1:
        print("info works")
        return redirect(url_for('gdpr'))

    inq = ClientInquiriesModel.find_by_id(id)
    if inq is None:
        abort(404)

    form = PrivacyForm()

    if form.validate_on_submit():
        #answer = form.answer.data
        locked = form.locked.data
        f = form.f.data
        p = convert_range(form.p.data)
        q = convert_range(form.q.data)

        if not check_fpq(f, p, q):
            print("Only values between 0 and 1 allowed for f,p,q!")  #debug
            flash("Only values between 0 and 1 allowed for f,p,q!")
            return render_template('inquiries/privacy.html',
                                   inq=inq,
                                   form=form,
                                   title='privacy settings')

        inq.f = f
        inq.p = p
        inq.q = q
        try:
            inq.save_to_db()
        except:
            return render_template(
                '/error_pages/500.html',
                title='error while trying to save inquiries.')

    return render_template('inquiries/privacy.html',
                           inq=inq,
                           form=form,
                           title='privacy')
Ejemplo n.º 2
0
def inquiries_detail(id):
    '''
    Detailed view of an inquiry (web GUI).
    '''
    #access is only allowed if gdpr is set to true
    cnfg = ConfigurationModel.find()
    if cnfg is None:
        abort(404)
    if cnfg.dsgvo != 1:
        print("info works")
        return redirect(url_for('gdpr'))

    inq = ClientInquiriesModel.find_by_id(id)
    if inq is None:
        abort(404)

    # if the user changes a client inquiry, responded will be set to TRUE
    # and a PRR will be made with the answer value
    form = InquiryDetailForm()

    if inq.type == 'mc':
        form.radio_elem.description = inq.qdescription
        form.radio_elem.choices = [('_'.join(o.lower().split(' ')), o)
                                   for o in json.loads(inq.options)]
        form.radio_elem.name = inq.name

    elif inq.type == 'cbx':
        form.checkbox_elem.description = inq.qdescription
        form.checkbox_elem.name = inq.name
        form.checkbox_elem.choices = [('_'.join(o.lower().split(' ')), o)
                                      for o in json.loads(inq.options)]
    elif inq.type == 'bool':
        form.boolean_elem.description = inq.qdescription
        form.boolean_elem.name = inq.name
        form.boolean_elem.choices = [('_'.join(o.lower().split(' ')), o)
                                     for o in json.loads(inq.options)]
    else:
        abort(400, "Unknown question type {}".format(inq.type))

    if form.validate_on_submit():
        answer = form.answer.data
        locked = form.locked.data
        f = inq.f
        p = inq.p
        q = inq.q

        # check length of answer
        if not (len(json.loads(answer)) == len(json.loads(inq.answer))):
            print("answer must have the same ordinal values!")  #debug
            flash("answer must have the same ordinal values!")
            return render_template('inquiries/inquiry.html',
                                   inq=inq,
                                   form=form,
                                   title='question')

        # if bits are zero and one
        if not check_if_bits(json.loads(answer)):
            print("only 0s and 1s allowed in the answer list")  #debug
            flash("only 0s and 1s allowed in the answer list")
            return render_template('inquiries/inquiry.html',
                                   inq=inq,
                                   form=form,
                                   title='question')

        # a PRR and IRR will be set after a answer is was changed
        if (inq.answer != answer):
            prr = permanent_RandomizedResponse(float(f), json.loads(answer))
            inq.prr_answer = json.dumps(prr)
            irr = instantaneous_RandomizedResponse(float(p), float(q), prr)
            inq.irr_answer = json.dumps(irr)

        inq.answer = answer
        inq.responded = True  # if a answer was given by the user, responed will be set to TRUE
        inq.locked = locked
        # inq.f = inq.f
        # inq.p = inq.p
        # inq.q = inq.q
        try:
            inq.save_to_db()
        except:
            return render_template(
                '/error_pages/500.html',
                title='error while trying to save inquiries.')

    return render_template('inquiries/inquiry.html',
                           inq=inq,
                           form=form,
                           title='question')