コード例 #1
0
def item_edit(done=False, id=-1):
    try:
        common_details = tables.prepare_item_config_for_view(
            configuration, 'edit')
        if done:
            user = User.query.get(id)
            form = EditForm(request.form)
            if form.validate() and request.method == 'POST':
                form.populate_obj(user)
                db.session.commit()
                return redirect(url_for('user.show'))
            else:
                return render_template('user/user.html',
                                       form_details=form,
                                       common_details=common_details)
        else:
            chbx_id_list = request.form.getlist('chbx')
            if chbx_id_list:
                id = int(chbx_id_list[0])  # only the first one can be edited
            if id > -1:
                user = User.query.get(id)
                form = EditForm(obj=user, formdata=None)
                common_details['item_id'] = id
            else:
                return redirect(url_for('user.show'))
            return render_template('user/user.html',
                                   form_details=form,
                                   common_details=common_details)
    except Exception as e:
        log.error(u'Could not edit user {}'.format(e))
        flash_plus(u'Kan gebruiker niet aanpassen', e)
    return redirect(url_for('user.show'))
コード例 #2
0
def ajax(table_configuration):
    try:
        data_list, total_count, filtered_count = prepare_data_for_ajax(table_configuration)
        datatable = format_datatable(data_list, total_count, filtered_count)
    except Exception as e:
        flash_plus(f'Tabel kan niet getoond worden (ajax)', e)
        datatable =  format_datatable([], 0, 0)
    return datatable
コード例 #3
0
def show(table_configuration):
    filters = []
    config = None
    try:
        config = tables.prepare_config_table_for_view(table_configuration)
    except Exception as e:
        flash_plus(f'Tabel kan niet getoond worden (show)', e)
    return render_template('base_multiple_items.html', table_config=config, filters=filters)
コード例 #4
0
def item_delete():
    try:
        chbx_id_list = request.form.getlist('chbx')
        mregister.delete_registration(chbx_id_list)
    except Exception as e:
        log.error(u'Could not delete registration: {}'.format(e))
        flash_plus('Could not delete registration', e)
    return redirect(url_for('registration.show'))
コード例 #5
0
def ajax(table_configuration):
    try:
        output = prepare_data_for_ajax(table_configuration)
        fml = get_flashed_messages()
        if not not fml:
            output['flash'] = fml
    except Exception as e:
        flash_plus(f'Table cannot be displayed (ajax)', e)
        output = []
    return jsonify(output)
コード例 #6
0
ファイル: views.py プロジェクト: manuelborowski/datacollector
def login():
    form = LoginForm(request.form)
    if form.validate() and request.method == 'POST':
        user = User.query.filter_by(
            username=func.binary(form.username.data)).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            log.info(u'user {} logged in'.format(user.username))
            user.last_login = datetime.datetime.now()
            try:
                db.session.commit()
            except Exception as e:
                log.error(u'Could not save timestamp: {}'.format(e))
                utils.flash_plus(u'Fout in database', e)
                return redirect(url_for('auth.login'))
            # Ok, continue
            return redirect(url_for('user.show'))
        else:
            utils.flash_plus(u'Ongeldige gebruikersnaam of paswoord')
            log.error(u'Invalid username/password')
    return render_template('auth/login.html', form=form, title='Login')
コード例 #7
0
def item_view(done=False, id=-1):
    try:
        common_details = tables.prepare_item_config_for_view(
            configuration, 'view')
        if done:
            pass
            # nothing to do)
        else:
            chbx_id_list = request.form.getlist('chbx')
            if chbx_id_list:
                id = int(chbx_id_list[0])  # only the first one can be viewed
                user = User.query.get(id)
                form = ViewForm(obj=user, formdata=None)
                common_details['item_id'] = id
            else:
                return redirect(url_for('user.show'))
            return render_template('user/user.html',
                                   form_details=form,
                                   common_details=common_details)
    except Exception as e:
        log.error(u'Could not view user {}'.format(e))
        flash_plus(u'Kan gebruiker niet bekijken', e)
    return redirect(url_for('user.show'))
コード例 #8
0
def item_add(done=False):
    try:
        common_details = tables.prepare_item_config_for_view(
            configuration, 'add')
        if done:
            form = AddForm(request.form)
            if form.validate() and request.method == 'POST':
                if form.user_type.data == User.USER_TYPE.LOCAL:
                    password = form.password.data
                else:
                    password = ''
                user = User(email=form.email.data,
                            username=form.username.data,
                            first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            password=password,
                            level=form.level.data,
                            user_type=form.user_type.data)
                db.session.add(user)
                db.session.commit()
                log.info('add: {}'.format(user.log()))
                return redirect(url_for('user.show'))
            else:
                return render_template('user/user.html',
                                       form_details=form,
                                       common_details=common_details)
        else:
            form = AddForm()
            return render_template('user/user.html',
                                   form_details=form,
                                   common_details=common_details)
    except Exception as e:
        log.error(u'Could not add user {}'.format(e))
        flash_plus(u'Kan gebruikers niet toevoegen', e)
        db.session.rollback()
    return redirect(url_for('user.show'))
コード例 #9
0
def item_delete():
    try:
        chbx_id_list = request.form.getlist('chbx')
        for id in chbx_id_list:
            if int(id) == 1:
                log.error(u'cannot delete this user')
                utils.flash_plus(u'Kan de gebruiker admin niet verwijderen')
                continue
            if int(id) == current_user.id:
                log.error(u'user cannot delete himself')
                utils.flash_plus(
                    u'Een gebruiker kan niet zichzelf verwijderen.')
                continue
            user = User.query.get(int(id))
            db.session.delete(user)
        db.session.commit()
    except Exception as e:
        log.error(u'Could not delete user: {}'.format(e))
        utils.flash_plus(u'Kan de gebruikers niet verwijderen', e)
    return redirect(url_for('user.show'))