def users_bulk_delete(): form = BulkDeleteForm() if form.validate_on_submit(): q = request.args.get('q', text('')) if q == '': q = text('') print(current_user.id) ids = User.get_bulk_action_ids(request.form.get('scope'), request.form.getlist('bulk_ids'), omit_ids=[current_user.id], query=q) from snakeeyes.blueprints.billing.tasks import delete_users delete_users.delay(ids) #delete_count = User.bulk_delete(ids) flash('{0} user(s) were scheduled to be deleted.'.format(len(ids)), 'success') else: flash('No users were deleted, something went wrong.', 'error') return redirect(url_for('admin.users'))
def coupon_bulk_delete(): form = BulkDeleteForm() if form.validate_on_submit(): ids = Coupon.get_bulk_action_ids(request.form.get('scope'), request.form.getlist('bulk_id'), query=request.args.get('q', '')) Coupon.bulk_delete(ids) flash('{0} coupon(s) will be deleted.'.format(len(ids)), 'succes') else: flash('No coupon were deleted, something went wrong', 'error') return redirect(url_for('admin.coupon'))
def coupons(page): search_form = SearchForm() bulk_form = BulkDeleteForm() sort_by = Coupon.sort_by(request.args.get('sort', 'created_on'), request.args.get('direction', 'desc')) #order_values = f'{sort_by[0], sort_by[1]}' order_values = '{0} {1}'.format(sort_by[0], sort_by[1]) #q = request.args.get('q', text('')) #if q == '': # q = text('') #print("@@ASDAS", q) paginated_coupons = Coupon.query \ .filter(Coupon.search(request.args.get('q', text(''))))\ .order_by(text(order_values))\ .paginate(page, 50, True) print("@@@@", paginated_coupons) print("$$$$$$$$$$$$$$$$",dir(request.endpoint)) return render_template('admin/coupon/index.html', form=search_form, bulk_form=bulk_form, coupons=paginated_coupons)
def users_bulk_delete(): form = BulkDeleteForm() if form.validate_on_submit(): ids = User.get_bulk_action_id(request.form.get('scope'), request.form.getlist('bulk_ids'), omit_id=[current_user.id], query=request.args.get('q', '')) delete_count = User.bulk_delete(ids) flash('{0} user(s) were scheduled to be deleted.'.format(delete_count), 'success') else: flash('No users were deleted, something went wrong.', 'error') return redirect(url_for('admin.users'))
def coupons_bulk_delete(): form = BulkDeleteForm() if form.validate_on_submit(): ids = Coupon.get_bulk_action_ids(request.form.get('scope'), request.form.getlist('bulk_ids'), query=request.args.get('q', None)) # Prevent circular imports. from snakeeyes.blueprints.billing.tasks import delete_coupons delete_coupons.delay(ids) flash('{0} coupons(s) were scheduled to be deleted.'.format(len(ids)), 'success') else: flash('No coupons were deleted, something went wrong.', 'error') return redirect(url_for('admin.coupons'))
def coupons_bulk_delete(): form = BulkDeleteForm() if form.validate_on_submit(): q = request.args.get('q', text('')) if q == '': q = text('') ids = Coupon.get_bulk_action_ids(request.form.get('scope'), request.form.getlist('bulk_ids'), query=q) from snakeeyes.blueprints.billing.tasks import delete_coupons delete_coupons.delay(ids) flash(f'{len(ids)} coupons were scheduled to be deleted.', 'success') else: flash('No coupons were deleted. Something went wrong.', 'error') return redirect(url_for('admin.coupons'))
def users(page): search_form = SearchForm() bulk_form = BulkDeleteForm() sort_by = User.sort_by(request.args.get('sort', 'created_on'), request.args.get('direction', 'desc')) order_values = '{0} {1}'.format(sort_by[0], sort_by[1]) paginated_users = User.query \ .filter(User.search(request.args.get('q', text('')))) \ .order_by(User.role.asc(), User.payment_id, text(order_values)) \ .paginate(page, 20, True) return render_template('admin/user/index.html', form=search_form, bulk_form=bulk_form, users=paginated_users)
def coupons(page): search_form = SearchForm() bulk_form = BulkDeleteForm() sort_by = Coupon.sort_by(request.args.get('sort', 'created_on'), request.args.get('direction', 'desc')) order_values = '{0} {1}'.format(sort_by[0], sort_by[1]) paginated_coupons = Coupon.query \ .filter(Coupon.search(request.args.get('q', text('')))) \ .order_by(text(order_values)) \ .paginate(page, 50, True) return render_template('admin/coupon/index.html', form=search_form, bulk_form=bulk_form, coupons=paginated_coupons)
def users(): """Fucntion to list all users in the database.""" form_search = SearchForm() bulk_form = BulkDeleteForm() sort_by = User.sort_by(request.args.get('sort', 'created_on'), request.args.get('direction', 'desc')) order_values = '{0} {1}'.format(sort_by[0], sort_by[1]) page = request.args.get('page', 1, type=int) paginated_users = User.query \ .filter(User.search(request.args.get('q', ''))) \ .order_by(User.role.asc(), text(order_values)) \ .paginate( page = page , per_page =current_app.config['FLASKY_POSTS_PER_PAGE'] , error_out = False ) return render_template('admin/user/index.html', form=form_search, users=paginated_users, bulk_form=bulk_form)