def show_dashboard_inner(): per_page = 9 paginator = Paginator() form = dashboard_itemsform.DashboardItemsForm() servername = socket.gethostname() approot = os.path.split(app.root_path) users = g.user instance = SysInfo() freespace = instance.diskspace() ltime = instance.systime() atime = instance.altertime() pages = request.args.get('page', type=int, default=1) if not users and pages == None: abort(404) else: contents_loop = sql.session.query(Content).limit( (per_page)).offset( (pages - 1) * per_page).all() pagination = paginator.paginate_queries(Content, pages, per_page) return render_template('adminboard/adminboard_inner.html', servername=servername, approot=approot[-2], freespace=freespace, users=users, ltime=ltime, atime=atime, contents_loop=contents_loop, form=form, pagination=pagination )
def update_dashboard_inner(): form = dashboard_itemsform.DashboardItemsForm() form_next = dashboard_searchform.DashboardSearchForm() author = g.user conn = engine.connect() if request.method == 'POST': if form.rename.data and form.validate_on_submit(): checkboxes = request.form.getlist('item_chb') # form.delid.data is the unicode list thing which # we convert to integer using regexp delid = int(re.search("\d+", str(form.delid.data)).group()) if author is not None: articles = Content.query.all() n = None for x in checkboxes: # x is the unicode list thing which # we convert to integer using regexp x = int(re.search("\d+", str(x)).group()) for art_id in articles: if art_id.id == x: n = art_id.id if x == n and x != delid: stmt = update(Content).where(Content.id == x).values( id=delid) try: conn.execute(stmt) conn.close() flash( "Item {} is changed to {}".format( x, form.delid.data), 'info') except exc.IntegrityError: flash("Item {} is exists".format(delid), 'error') elif x == delid: flash("Item {} is exists".format(delid), 'error') else: flash( "Item {} is not changed to {}".format( x, form.delid.data), 'error') else: return redirect(url_for('show_login')) return redirect(url_for('show_dashboard_inner')) elif form.rename.data is True and form.validate_on_submit() is False: flash("No item selected", 'error') return redirect(url_for('show_dashboard_inner')) elif form.delete.data and form.validate_on_submit(): checkboxes = request.form.getlist('item_chb') if author is not None: articles = Content.query.all() n = None for x in checkboxes: # x is the unicode list thing which # we convert to integer using regexp x = int(re.search("\d+", str(x)).group()) for art_id in articles: if art_id.id == x: n = art_id.id if x == n: stmt = delete(Content).where(Content.id == x) conn.execute(stmt) conn.close() flash("Item {} is deleted!".format(x), 'info') elif x == n: flash("Item {} is exists".format(x), 'error') else: flash("Item {} is not deleted!".format(x), 'error') else: return redirect(url_for('show_login')) return redirect(url_for('show_dashboard_inner')) elif form.delete.data is True and form.validate_on_submit() is False: flash("No item selected", 'error') return redirect(url_for('show_dashboard_inner')) elif form_next.validate_on_submit(): data = [] data_array = sql.session.query(Content).filter( Content.content_title.match(form_next.query.data)).all() if data_array: for x in data_array: data = x return jsonify(id=str(data.id), title=data.content_title, author=data.content_author, category=data.content_category, date=data.content_date, published=data.published) else: return redirect(url_for('show_dashboard_inner')) return render_template('adminboard/adminboard_inner.html', form=form)