Exemplo n.º 1
0
def delete_test():
    form = DeleteForm()
    if form.validate_on_submit():
        print(form.fields.data)
    else:
        print(form.errors)
    return render_template('DeleteTest.html', form=form)
Exemplo n.º 2
0
def delete():
    form = DeleteForm()
    context = dict()
    context['pagename'] = 'Удаление ссылки'
    context['form'] = form
    if form.validate_on_submit():
        if form.alias.data in path.values():
            flash('Нельзя удалить ссылку, необходимую для работы сайта',
                  'danger')
            return render_template('delete.html', context=context)
        cur = g.db.execute('select password from entries where alias = (?)',
                           (form.alias.data, ))
        try:
            password = str(cur.fetchall()[0][0])
            if password == form.password.data:
                g.db.execute('delete from entries where alias = (?)',
                             (form.alias.data, ))
                cur_seq = g.db.execute('select seq from sqlite_sequence')
                ids = int(cur_seq.fetchall()[0][0]) - 1
                g.db.execute('update sqlite_sequence set seq = (?)', (ids, ))
                g.db.commit()
                flash('Успешное удаление', 'success')
                return render_template('delete.html', context=context)
            else:
                flash('Неверный пароль', 'danger')
                return render_template('delete.html', context=context)
        except IndexError:
            flash('Несуществующая ссылка', 'danger')
            return render_template('delete.html', context=context)
    return render_template('delete.html', context=context)
Exemplo n.º 3
0
def delete():
    form = DeleteForm()
    if form.validate_on_submit():
        Employee.query.filter_by(id=form.bartender_id.data).delete()
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('delete.html', form=form)
Exemplo n.º 4
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    if current_user.role != "Member":
        form = DeleteForm()
        form2 = ChangeRoleForm()
        form3 = MakePostForm()
        if form.submit.data and form.validate():
            if form.confirm.data == "Confirm":
                db.session.delete(user)
                db.session.commit()
        if form2.submit2.data and form2.validate():
            if form2.confirm2_1.data == "Confirm":
                print(form2.radio_buttons.data)
                user.role = form2.radio_buttons.data
                db.session.add(user)
                db.session.commit()
                return redirect(url_for('admin_settings'))
        if form3.submit3.data and form3.validate():
            p = Post(body=form3.body.data, author=user)
            db.session.add(p)
            db.session.commit()
        return render_template('user.html',
                               title=user.username,
                               user=user,
                               om_admin='ja',
                               form=form,
                               form2=form2,
                               form3=form3)
    return redirect(url_for('admin_settings'))
Exemplo n.º 5
0
def delete():
    form = DeleteForm()
    if form.validate_on_submit():
        employee = db.session.query(Employee).filter_by(
            id=form.id.data).first()
        db.session.delete(employee)
        db.session.commit()
        flash('Congratulations, you deleted an employee!')
        return redirect(url_for('index'))
    return render_template('delete.html', title='Delete', form=form)
Exemplo n.º 6
0
def delete():
    form = DeleteForm()
    data = form.data
    if form.validate_on_submit():
        id_ = data.pop('id')
        redis.delete_men([id_])
        return redirect(url_for('index',
                                message='Пользователь успешно удалён'))
    else:
        flash('Введены некорректные данные')
    return render_template('delete_form.html', form=form)
Exemplo n.º 7
0
def delete():
    form = DeleteForm()
    if form.validate_on_submit():
        collections = Collection.query.filter_by(user_id=current_user.id, numb=form.numb.data, name=form.name.data).first()
        if collections is None:
            flash('Not found')
        else:
            db.session.delete(collections)
            db.session.commit()
            flash('Congratulations, you deleted deal "'+str(form.name.data) + '" planed on '+form.numb.data.strftime('%d.%m.%Y')+'!')
        return render_template('delete.html', title='Delete', form=form)
    return render_template('delete.html', title='Delete', form=form)
Exemplo n.º 8
0
def delete_student():
    form = DeleteForm()
    if form.validate_on_submit():
        id_number = form.id_number.data
        if Student_Profile().student_exist(id_number):
            Student_Profile().delete_students(id_number)
            flash('Student deleted Successfully!')
            redirect(url_for('delete_student'))
        else:
            flash('Student with id number {} do not exist!'.format(id_number))
            redirect(url_for('delete_student'))
    return render_template('delete_student.html', form=form, title='Delete')
Exemplo n.º 9
0
def delete(cid, name):
    if current_user.permissions == 'delete' or 'crud':
        form = DeleteForm()
        coisa = Coisa.query.filter_by(id=cid,
                                      name=name,
                                      user_id=current_user.id).first_or_404()
        if form.validate_on_submit():
            db.session.delete(coisa)
            db.session.commit()
            flash('{} Excluido.'.format(name))
            return redirect(url_for('read'))
        return render_template('delete_date.html', form=form, coisas=coisa)
Exemplo n.º 10
0
def delete(address_id):
    address = Address.query.filter_by(id=address_id).first_or_404()
    form = DeleteForm(current_user.username)
    if form.validate_on_submit():
        g.db.execute('delete from address where id = address_id',
                     [request.form['address']])
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return render_template('edit_address.html',
                               title=_('Edit Address'),
                               form=form,
                               address=address)
Exemplo n.º 11
0
def delete_confirm(record_id):
    # auth process
    if current_user.is_authenticated is True:
        account = get_account_info_by_account_id(current_user.account_id)
    else:
        return redirect(url_for('auth.login_view'))
    # process end
    form = DeleteForm()
    # Get record info
    record_url = 'http://' + Config.DB_OPS_URL + \
                 '/api/gas/document/rid/' + str(record_id)
    result = requests.get(record_url)
    # Functional Part
    if form.validate_on_submit():
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['employee_no']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                flash('试图删除不属于自己的数据', 'danger')
                return redirect(
                    url_for('auth.home_view',
                            account_id=current_user.account_id))

            # main function process below
            delete_url = 'http://' + Config.DB_OPS_URL + \
                         '/api/gas/document/' + str(record_id)
            requests.delete(delete_url)
            flash('数据删除成功', 'success')
            return redirect(
                url_for('auth.home_view', account_id=current_user.account_id))
    # View Part
    else:
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['employee_no']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                return redirect(
                    url_for('auth.home_view',
                            account_id=current_user.account_id))

            # main function process below
            competition = get_api_info(result)[0]
            return render_template('recordDelete.html',
                                   form=form,
                                   account=account)
Exemplo n.º 12
0
def admin():
    #if current_user.get_id() == '1' or current_user.get_id() == '2':
    if current_user.role == 'admin':
        #if 0 == 0 :
        form = RegistrationForm()
        if form.validate_on_submit():
            user = User(username=form.username.data,
                        role=form.role.data)  # email=form.email.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Congratulations, you are now a registered user!')
            return redirect(url_for('admin'))
        form2 = DeleteForm()
        if form2.validate_on_submit():
            user = User(username=form2.username.data)  # email=form.email.data)
            mystring = str(user)
            ##########
            keyword = '>'
            before_keyword, keyword, after_keyword = mystring.partition(
                keyword)
            mystring = before_keyword
            keyword = '<User '
            before_keyword, keyword, after_keyword = mystring.partition(
                keyword)
            mystring = after_keyword
            print(mystring)
            ############
            conn = sqlite3.connect(sqlite_file)
            c = conn.cursor()
            c.execute(
                'DELETE FROM user WHERE username ="******" '.format(mystring))
            conn.commit()
            conn.close()

            flash('Congratulations, you are delete user!')
            return redirect(url_for('admin'))
        conn = sqlite3.connect(sqlite_file)
        c = conn.cursor()
        #c.execute("SELECT * FROM user")
        c.execute("SELECT id, username, role FROM user")
        rows = c.fetchall()

        return render_template('admin.html',
                               title='Admin',
                               form=form,
                               form2=form2,
                               rows=rows)
    else:
        pass
Exemplo n.º 13
0
def delete_student():
    form = DeleteForm()
    if request.method == 'POST' and form.validate():
        student = Students(idNum=form.id_number.data)
        if student.exist():
            student.delete()
            flash("Deleted student with id number '{}'".format(
                form.id_number.data), category='success')
            return redirect(url_for('students'))
        else:
            flash("Student Does not exist.", category='danger')
            return redirect(url_for('delete_student'))
    else:
        return render_template('delete_student.html', form=form)
Exemplo n.º 14
0
def del_products():

    form = DeleteForm()

    if form.validate_on_submit():
        id = form.id.data
        product_name = Product.query.get(id)
        product_description = Product.query.get(id)
        db.session.delete(product_name)
        db.session.delete(product_description)
        db.session.commit()

        return redirect(url_for('list_products'))
    return render_template('delete.html', form=form)
Exemplo n.º 15
0
def past_entry(record_id):
    record = Post.query.get(int(record_id))
    form = DeleteForm()
    #Proceed with deleting the post if delete button pressed
    if form.is_submitted() or request.method == 'POST':
        db.session.delete(record)
        db.session.commit()
        flash("Journal entry deleted")
        return redirect(url_for('journal'))

    if record is not None:
        return render_template('post.html', record=record, form=form)
    else:
        return render_template('404.html')
Exemplo n.º 16
0
def delete():
    form = DeleteForm()
    if form.validate_on_submit():
        substance = Substance.query.filter_by(title=form.title.data.title).first_or_404()
        filename = secure_filename(str(substance.id) + '.pdf')
        try:
            os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        except Exception as ex:
            app.logger.error("Подобного файла в базе нет", ex)
            flash("Карточки вещества в базе не оказалось")
        db.session.delete(substance)
        db.session.commit()
        flash('Вещество удалено')
        return redirect(url_for('delete'))
    return render_template('delete.html', title='Удалить вещества', form=form)
Exemplo n.º 17
0
def asset_delete(asset_id=None):
    form = DeleteForm()
    asset = assets.GetAsset(a.GetAssetRequest(_id=asset_id))

    if form.validate_on_submit():
        deleted = assets.DeleteAsset(a.DeleteAssetRequest(_id=asset_id))
        if deleted and deleted.name and not deleted._id:
            flash('Asset deleted: {}'.format(deleted.name))
            return redirect('/assets')
        else:
            flash('Failed to delete asset: {}'.format(deleted))
            logging.error('Failed to delete asset: {}'.format(deleted))
            asset = 'error'
            return render_template('delete.html', form=form, view='delete', obj_type='Asset', obj=None, name='deleted?')
    return render_template('delete.html', form=form, view='delete', obj_type='Asset', obj=asset, name=asset.name)
Exemplo n.º 18
0
def rules():
    form = RuleForm()
    delete_forms = {
        rule.id: DeleteForm(obj=rule)
        for rule in current_user.rules
    }

    map_images = {}
    for rule in current_user.rules:
        dmap = DecoratedMap(key=Config.GOOGLEMAPS_KEY, size_x=280, size_y=280)
        dmap.add_marker(LatLonMarker(rule.lat, rule.lng))
        map_images[rule.id] = dmap.generate_url()

    # This is a hack to get the delete buttons to ignore submission of new rule forms.
    # It is inelegant.
    if form.errors is not {}:
        current_app.logger.info(form.errors)
    if form.validate_on_submit():
        for rule in current_user.rules:
            delete_forms[rule.id].id.data = None
        rule_day = timedelta(days=form.days.data)
        rule_time = form.time.data
        new_rule = current_user.make_rule(
            form.location.data,
            form.latitude.data,
            form.longitude.data,
            datetime.combine((ARBITRARY_MONDAY + rule_day), rule_time),
            form.activity_name.data,
        )
        new_rule.record()
        current_app.logger.debug("Rule form validated")
        return redirect("/index")

    if DeleteForm().validate_on_submit():
        rule = Rule.query.get(DeleteForm().id.data)
        rule.delete_rule()
        return redirect(url_for("main.rules"))

    flash_errors(form)

    return render_template(
        "rules.html",
        title="Rules",
        form=form,
        delete_forms=delete_forms,
        map_urls=map_images,
        maps_key=Config.GOOGLEMAPS_KEY,
    )
Exemplo n.º 19
0
def hello(user_ip=0, username='******'):
    user_ip = session.get('user_ip')
    username = current_user.id
    todo_form = todoForm()
    delete_form = DeleteForm()
    update_form = UpdateForm()

    context = {
        'user_ip': user_ip,
        'lista': get_todos(username),
        'username': username,
        'todo_form': todo_form,
        'delete_form': delete_form,
        'update_form': update_form
    }

    if todo_form.validate_on_submit():
        description = todo_form.description.data
        put_todo(description=description, user_name=username)

        flash('Tarea creada con exito')

        redirect(url_for('hello'))

    # users = get_users()
    #
    # for user in users:
    #     print(user.id)
    #     print(user.to_dict().get('password'))

    return render_template('hello.html', **context)
Exemplo n.º 20
0
def delete_record():
    form = DeleteForm()
    if form.validate_on_submit():
        # Query DB for matching record (we'll grab the first record in case
        # there's more than one).
        to_delete = db.session.query(City).filter_by(city = form.city.data).first()

        # If record is found delete from DB table and commit changes
        if to_delete is not None:
            db.session.delete(to_delete)
            db.session.commit()

        form.city.data = ''
        # Redirect to the view_all route (view function)
        return redirect(url_for('view_cities'))
    return render_template('delete.html', form=form)
Exemplo n.º 21
0
def dconfirm(request):
    form = DeleteForm(request.POST)
    if not form.is_valid():
        return render(request, 'd_view.html', {'form': form})
    id = form.cleaned_data['id']
    object = Material.objects.all().filter(id=id)
    if len(object) == 0:
        return render(request, 'd_view.html', {
            'form': form,
            'message': '登録されていないIDです'
        })
    request.session['d_id'] = id
    return render(request, 'd_confirm.html', {
        'name': object[0].name,
        'best_before': object[0].best_before
    })
Exemplo n.º 22
0
def delete_snippet(snippet_uuid):
    """Route lets the owner of a snippet delete
    the snippet"""
    snippet = get_snippet_by_uuid(snippet_uuid)

    if current_user != snippet.user:
        message = "You are not authorized to edit this snippet."
        return render_template('errorpages/401.html', message=message), 401

    form = DeleteForm()

    if form.validate_on_submit():
        db.session.delete(snippet)
        db.session.commit()
        return redirect(
            url_for('user.snippets', username=current_user.username))
    return render_template('snippets/delete.html', form=form, snippet=snippet)
Exemplo n.º 23
0
Arquivo: views.py Projeto: OQJ/myblog
def delete_post():
    form = DeleteForm()
    id = form.id.data
    post = Post.query.get_or_404(id)
    db.session.delete(post)
    db.session.commit()
    flash('删除成功', 'success')
    return redirect(url_for('index'))
Exemplo n.º 24
0
def delete_tolisten(id):
    form = DeleteForm()
    todelete = ToListen.query.get(id)
    title, artist = todelete.title, todelete.artist
    if request.method == 'POST':
        flash(f'Deleted {title} by {artist} from albums to listen')
        ToListen.query.filter(ToListen.id == id).delete()
        db.session.commit()
        return redirect(url_for('tolisten'))
    return render_template('delete.html', form=form, todelete=todelete)
Exemplo n.º 25
0
def deleteGame(game_id):
    ''' This route function lets the owner of a game post delete the game'''

    if 'credentials' not in login_session:
        return "Must be logged in to delete a game."
    # Throw 404 if game_id in URL not in DB
    try:
        game = db.session.query(Game).filter_by(id=game_id).one()
    except:
        abort(404)
    # Check if user is owner of the game
    if login_session['user_id'] != game.user_id:
        return "You do not have permission to delete this game."

    form = DeleteForm()
    if form.validate_on_submit():
        db.session.delete(game)
        db.session.commit()
        return redirect(url_for('home'))

    return render_template('deleteGame.html', game=game, form=form)
Exemplo n.º 26
0
def delete_myuser(myuser):
    form = DeleteForm()
    if form.validate_on_submit() and current_user.permissions == 'admin':
        u = User.query.filter_by(username=myuser).first()
        c = Coisa.query.filter_by(user_id=u.id)
        db.session.delete(u)
        c.delete()
        db.session.commit()
        flash('Usuário excluido com sucesso.')
        return redirect(url_for('index'))
    elif form.validate_on_submit() and current_user.permissions != 'admin':
        user_id = int(current_user.id)
        u = User.query.filter_by(id=user_id).first()
        db.session.delete(u)
        db.session.commit()
        flash('Usuário excluido com sucesso.')
        return redirect(url_for('logout'))
    return render_template('delete_myuser.html',
                           title='Excluir perfil',
                           form=form,
                           user=myuser)
Exemplo n.º 27
0
def deleteGame(game_id):
    ''' This route function lets the owner of a game post delete the game'''

    if 'credentials' not in login_session:
        return "Must be logged in to delete a game."
    # Throw 404 if game_id in URL not in DB
    try:
        game = db.session.query(Game).filter_by(id=game_id).one()
    except:
        abort(404)
    # Check if user is owner of the game
    if login_session['user_id'] != game.user_id:
        return "You do not have permission to delete this game."

    form = DeleteForm()
    if form.validate_on_submit():
        db.session.delete(game)
        db.session.commit()
        return redirect(url_for('home'))

    return render_template('deleteGame.html', game=game, form=form)
Exemplo n.º 28
0
def delete_record():
    # Verifying that user is an admin
    if is_admin():
        form = DeleteForm()
        if form.validate_on_submit():
            # Query DB for matching record (we'll grab the first record in case
            # there's more than one).
            to_delete = db.session.query(City).filter_by(
                city=form.city.data).first()

            # If record is found delete from DB table and commit changes
            if to_delete is not None:
                db.session.delete(to_delete)
                db.session.commit()

            form.city.data = ''
            # Redirect to the view_all route (view function)
            return redirect(url_for('view'))
        return render_template('delete.html', form=form)
    # Tell non-admin user they're not authorized to access route.
    else:
        return render_template('unauthorized.html')
Exemplo n.º 29
0
def movie():
    page = request.args.get('page', default=1, type=int)
    movies = Movie.query\
        .options(joinedload('actors'), joinedload('genres'), joinedload('languages'))\
        .order_by(Movie.title.asc())\
        .paginate(page, 4, False)
    form = MovieForm()
    add_actor = SelectionForm(obj=Actor)
    add_actor.select.choices = [
        (a.id, a.name) for a in Actor.query.order_by(Actor.name.asc())
    ]
    add_genre = SelectionForm(obj=Genre)
    add_genre.select.choices = [
        (g.id, g.name) for g in Genre.query.order_by(Genre.name.asc())
    ]
    add_language = SelectionForm(obj=Language)
    add_language.select.choices = [
        (l.id, l.name) for l in Language.query.order_by(Language.name.asc())
    ]
    delete_movie_form = DeleteSelectionForm(obj=Movie)
    delete_movie_form.select.choices = [(m.id, f'{m.title}, {m.year}')
                                        for m in movies.items]
    select_director_form = SelectSelectionForm(obj=Actor)
    select_director_form.select.choices = add_actor.select.choices
    if form.validate_on_submit():
        m = Movie(title=form.title.data,
                  year=form.year.data,
                  synopsis=form.synopsis.data)
        db.session.add(m)
        db.session.commit()
        flash('Movie added to db')
        return redirect(url_for('admin.movie'))
    links = construct_page_links('admin.movie', movies)
    return render_template('admin_movie.html',
                           title='admin.movie',
                           movies=movies.items,
                           add_form=form,
                           add_actor=add_actor,
                           add_genre=add_genre,
                           next_page=links[0],
                           prev_page=links[1],
                           first_page=links[2],
                           last_page=links[3],
                           add_language=add_language,
                           current_page=movies.page,
                           total_pages=movies.pages,
                           del_form=DeleteForm(),
                           del_movie_form=delete_movie_form,
                           sel_director_form=select_director_form)
Exemplo n.º 30
0
def delete():
    form = DeleteForm()
    imgs = get_imgs_name(app.config['UPLOADED_PHOTOS_DEST'])

    if request.method == 'POST':
        if form.validate_on_submit():
            short_name = form.name.data
            full_name = ''
            for f_name in imgs:
                if f_name.split('@')[0] == short_name:
                    full_name = f_name
            f_path = os.path.join(app.config['UPLOADED_PHOTOS_DEST'],
                                  full_name)
            ret = os.system(f"rm {f_path}")
            if ret:
                flash("Something gone worry...Havn't deleted...")
            else:
                flash(f"you have f*****g delete the {short_name}.")
        return redirect('delete')
    else:
        return render_template('delete.html',
                               title='Delete',
                               form=form,
                               images=imgs)
Exemplo n.º 31
0
def index():
    users = User.query.all()
    register_form = RegistrationForm()
    delete_form = DeleteForm()

    if register_form.validate_on_submit():
        username = register_form.username.data
        email = register_form.email.data
        password = register_form.password.data
        new_user = User(username=username,
                        email=email,
                        password_hash=User.set_password(password))
        db.session.add(new_user)
        db.session.commit()
        flash('You register new user: "******".'.format(username))
        return redirect(url_for('index'))

    elif delete_form.validate_on_submit():
        user = User.query.filter_by(
            username=delete_form.name_del_user.data).first()
        if user is None:
            flash('Invalid username or password')
            redirect(url_for('index'))
        elif user.username == 'admin':
            flash("You can't delete the admin page!")
            redirect(url_for('index'))
        else:
            db.session.delete(user)
            db.session.commit()
            flash('You delete user: "******".'.format(user.username))
            return redirect(url_for('index'))
    return render_template('index.html',
                           title='User Page',
                           users=users,
                           form1=register_form,
                           form2=delete_form)