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_contentpageid(): error = None form = contentpage_idform.ContentpageidForm() instance = SysInfo() author = g.user if (request.method == 'POST' and author is not None and request.form['save']): if form.validate_on_submit(): # we assign record time to this form element # as unicode string to be consistent with other form elements here form.content_date.data = unicode(instance.altertime()) conn = engine.connect() stmt = update(Content).where(Content.id == form.id.data).values( id=form.id.data, content_title=form.content_title.data, content_author=form.content_author.data, content_category=form.content_category.data, content_date=form.content_date.data, content_text=form.content_text.data) try: conn.execute(stmt) flash("Content is changed", 'info') except exc.IntegrityError: flash("Content with same name is exist", 'error') return redirect(url_for('show_contentpageid', id=form.id.data)) else: flash("Content is not changed", 'error') return redirect(url_for('show_contentpageid')) return render_template('adminboard/editpage_id_content.html', form=form, error=error)
class Backup: def __init__(self): self.backup_path = app.config['BACKUP_PATH'] self.mysql_export_path = "{}/{}.sql".format(self.backup_path, app.config['DBNAME']) self.site_path = os.path.split(self.backup_path) self.site_parent_path = app.root_path.strip('application') self.instance = SysInfo() self.file_output = "{}-{}.tar.gz".format( app.config['DBNAME'], str(self.instance.altertime())) def db_backup(self): if (os.path.isdir(self.backup_path) and os.access(self.backup_path, os.W_OK) and os.path.isdir(self.site_parent_path)): command = 'mysqldump --opt -h {} -u {} -p{} {} > {}'.format( app.config['DBHOST'], app.config['DBUSERNAME'], app.config['DBPASSWORD'], app.config['DBNAME'], self.mysql_export_path) os.system(command) with tarfile.open( "{}{}".format(self.backup_path, self.file_output), "w:gz") as tar: tar.add(self.site_parent_path) return "Backup is created: {}".format(self.file_output) else: msg = "No correct data for export the database or destination/site parent path isn't exist.\n" \ "Backup Path: {}\n" \ "Backup Path Access: {}\n" \ "Please, contact to administrator \n".format(self.backup_path, os.access(self.backup_path, os.W_OK)) return msg
def show_dashboard_filenamanager(): browser = FileBrowser() per_page = 9 pages = request.args.get('page', type=int, default=1) paginator = Paginator() form = dashboard_filesform.DashboardFilesForm() servername = socket.gethostname() approot = os.path.split(app.root_path) users = g.user instance = SysInfo() freespace = instance.diskspace() ltime = instance.systime() atime = instance.altertime() f = None get_relpath = None if session['login'] != 'admin': flash("You don't have administrator privilegies!", 'error') return redirect(url_for('show_dashboard')) if not users and pages is None: abort(404) else: if exists("{}/static/get_path.tmp".format(app.root_path)) is False: get_relpath = "/static/images/" elif exists("{}/static/get_path.tmp".format(app.root_path)): with open("{}/static/get_path.tmp".format(app.root_path), 'r') as f: get_relpath = f.read() limit = per_page if get_relpath == '': get_relpath = "/static/images/" files = browser.show_files(get_relpath) offset = ((pages - 1) * per_page) if pages == 0 or pages == 1: f = files[:limit] elif len(files) - offset > offset: f = files[offset:-offset] elif len(files) - offset < offset: f = files[offset:] pagination = paginator.paginate(files, pages, per_page) return render_template('adminboard/adminboard_filemanager.html', servername=servername, approot=approot[-2], freespace=freespace, users=users, ltime=ltime, atime=atime, files=f, get_relpath=get_relpath, form=form, pagination=pagination)
def show_categorypageid(id): form = categorypage_idform.CategorypageidForm() editpage_output_loop = sql.session.query(Categories).filter_by( id=id).first() instance = SysInfo() atime = instance.altertime() author = g.user if (editpage_output_loop and atime and author is not None): return render_template('adminboard/editpage_id_category.html', editpage_output_loop=editpage_output_loop, form=form) else: return redirect(url_for('show_login'))
def show_editpage_category(): form = categorypageform.CategorypageAddForm() editpage_output_loop = Categories.query.filter_by( category_author='admin').first() instance = SysInfo() atime = instance.altertime() author = g.user if (editpage_output_loop and atime and author is not None): return render_template('adminboard/editpage_category.html', author=author, atime=atime, editpage_output_loop=editpage_output_loop, form=form) else: return redirect(url_for('show_login'))
def show_userspageid(id): form = userspage_idform.UsersidForm() editpage_output_loop = Users.query.filter_by(id=id).first() categories_loop = Categories.query.all() instance = SysInfo() atime = instance.altertime() author = g.user if (editpage_output_loop and categories_loop and atime and author is not None): return render_template('adminboard/editpage_id_users.html', atime=atime, editpage_output_loop=editpage_output_loop, form=form) else: return redirect(url_for('show_login'))
def show_dashboard(): if not current_user.is_authenticated: return current_app.login_manager.unauthorized() else: servername = socket.gethostname() approot = os.path.split(app.root_path) users = g.user instance = SysInfo() freespace = instance.diskspace() ltime = instance.systime() atime = instance.altertime() flash('Welcome, ' + users, 'info') return render_template('adminboard/adminboard.html', servername=servername, approot=approot[-2], freespace=freespace, users=users, ltime=ltime, atime=atime)