def history(): if (not current_user.is_authenticated): return redirect(url_for('login')) try: form = HistoryForm() if request.method == 'GET': service_records_cnt = UserServiceHistory.query.filter( UserServiceHistory.user_id == current_user.id).count() service_records = UserServiceHistory.query.with_entities(UserServiceHistory.id, User.username, UserServiceHistory.input_content, UserServiceHistory.date_posted).\ join(User, User.id == UserServiceHistory.user_id).\ filter(UserServiceHistory.user_id == current_user.id).\ order_by(UserServiceHistory.date_posted.asc()).all() return render_template('history.html', title='History', form=form, service_records_cnt=service_records_cnt, service_records=service_records) except: return redirect(url_for('home')) if form.validate_on_submit(): if current_user.username != 'admin': return redirect(url_for('history')) if form.username.data == '*': service_records_cnt = UserServiceHistory.query.count() service_records = UserServiceHistory.query.with_entities(UserServiceHistory.id, User.username, UserServiceHistory.input_content, UserServiceHistory.date_posted). \ join(User, User.id == UserServiceHistory.user_id). \ order_by(UserServiceHistory.date_posted.asc()).all() else: user = User.query.filter( User.username == form.username.data).first() if not user: flash('failure - invalid user entered - please try again!', 'danger') return redirect(url_for('history')) service_records_cnt = UserServiceHistory.query.filter( UserServiceHistory.user_id == user.id).count() service_records = UserServiceHistory.query.with_entities(UserServiceHistory.id, User.username, UserServiceHistory.input_content, UserServiceHistory.date_posted). \ join(User, User.id == UserServiceHistory.user_id). \ filter(UserServiceHistory.user_id == user.id). \ order_by(UserServiceHistory.date_posted.asc()).all() return render_template('history.html', title='History', form=form, service_records_cnt=service_records_cnt, service_records=service_records) return redirect(url_for('history'))
def history(): form = HistoryForm() queries = Qqquery.query.filter_by(user_id=current_user.id) if current_user.admin: queries = Qqquery.query.all() if form.validate_on_submit(): original = form.username.data user = User.query.filter_by(username=original).first() queries = Qqquery.query.filter_by(user_id=user.id) return render_template('history.html', title='History', form=form, queries=queries)
def new_history(): form = HistoryForm() if form.validate_on_submit(): history = History(title=form.title.data, info=form.info.data, author=current_user) db.session.add(history) db.session.commit() flash('Вы создали историю', 'success') return redirect(url_for('history', history_id=history.id)) return render_template('create_history.html', title='New History', form=form)
def issuing_bays(): # Initialized form for bays issuing form = HistoryForm() if request.method == 'POST' and form.validate_on_submit(): sap = SapNumber.query.filter_by( sap_number=request.form.get("sap_number")).all() for el in sap: sap_id = el.id History.create(sap_number=sap_id, dpn=request.form.get("dpn"), serial_number=request.form.get("serial_number"), status=StatusEnum.ok) flash("Бухта видана успішно!", 'success') #sweetify.success(request, 'You did it', text='Good job! Бухта видана успішно!', persistent='Hell yeah') return redirect(url_for('main.issuing_bays')) return render_template('history.html', form=form)
def history_query(): if not current_user.is_authenticated: return redirect(url_for('login')) if current_user.username != "admin": return redirect(url_for('history')) form = HistoryForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.uname.data).first() if user is None: flash('No such username') return redirect(url_for('history_query')) print("UserID:", user.id) posts = user.spellcheck_posts().all() posts_count = user.spellcheck_posts().count() return render_template("history.html", title='History Page', posts=posts, count=posts_count) return render_template('history.html', title='History', form=form)
def update_history(history_id): history = History.query.get_or_404(history_id) if history.author != current_user: abort(403) form = HistoryForm() if form.validate_on_submit(): history.title = form.title.data history.info = form.info.data db.session.commit() flash('Информация в истории обновлена', 'success') return redirect(url_for('history', history_id=history.id)) elif request.method == 'GET': form.title.data = history.title form.info.data = history.info return render_template('create_history.html', title='Изменить историю', form=form, legend='Update History')
def history(): """ route for authenticated users to review their question history """ q_list = [] user_exists = False user_id = None is_admin = False if admin_perm.can(): is_admin = True user_id = current_user.id user_exists = True q_list = User.query.get(current_user.id).questions else: user_exists = True user_id = current_user.id q_list = User.query.get(user_id).questions form = HistoryForm(request.form) if form.validate_on_submit(): user_id = form.userquery.data user_obj = User.query.filter_by(username=user_id).first() user_exists = user_obj is not None if user_exists: history_perm = SeeHistoryPermission(user_obj.id) if not history_perm.can(): abort(403) q_list = user_obj.questions elif is_admin: flash_errors(form) return render_template( "history/history.html", form=form, q_list=q_list, user_exists=user_exists, user_id=user_id, is_admin=is_admin, )
def history(): global lastServerName global lastServerHistory global serverList form = HistoryForm() if serverList == None: serverList = doyleStatusApp.doyleInfo.getServerList() form.serverName.choices = [(s,s) for s in serverList] newServerName = lastServerName if form.validate_on_submit(): newServerName = form.serverName.data if newServerName != lastServerName: lastServerHistory = doyleStatusApp.doyleInfo.getHistory(newServerName) lastServerName = newServerName return render_template("history.html", counts=doyleStatusApp.doyleInfo.getCounts(), serverName=lastServerName, status=lastServerHistory, form=form)
def loginhistory(user_clicked): if not current_user.is_authenticated: return redirect(url_for('login')) if not (current_user.username == 'admin'): return redirect(url_for('home')) try: form = HistoryForm() if request.method == 'GET': if not user_clicked: user_name = current_user.username else: user_name = user_clicked if user_name == '*': activity_records_cnt = UserLoginHistory.query.count() activity_records = UserLoginHistory.query.with_entities(UserLoginHistory.id, User.username, UserLoginHistory.time_login, UserLoginHistory.time_logout). \ join(User, User.id == UserLoginHistory.user_id). \ order_by(UserLoginHistory.id.asc()).all() else: user = User.query.filter( User.username == user_name).first() if not user: flash( 'failure - invalid user entered - please try again!', 'danger') return redirect(url_for('home')) activity_records_cnt = UserLoginHistory.query.filter( UserLoginHistory.user_id == user.id).count() activity_records = UserLoginHistory.query.with_entities(UserLoginHistory.id, User.username, UserLoginHistory.time_login, UserLoginHistory.time_logout). \ join(User, User.id == UserLoginHistory.user_id). \ filter(UserLoginHistory.user_id == user.id). \ order_by(UserLoginHistory.id.asc()).all() return render_template('activitylog.html', title='LoginHistory', form=form, activity_records_cnt=activity_records_cnt, activity_records=activity_records) if form.validate_on_submit(): if form.username.data == '*': activity_records_cnt = UserLoginHistory.query.count() activity_records = UserLoginHistory.query.with_entities(UserLoginHistory.id, User.username, UserLoginHistory.time_login, UserLoginHistory.time_logout). \ join(User, User.id == UserLoginHistory.user_id). \ order_by(UserLoginHistory.id.asc()).all() else: user = User.query.filter( User.username == form.username.data).first() if not user: flash('failure - invalid user entered - please try again!', 'danger') return redirect(url_for('home')) activity_records_cnt = UserLoginHistory.query.filter( UserLoginHistory.user_id == user.id).count() activity_records = UserLoginHistory.query.with_entities(UserLoginHistory.id, User.username, UserLoginHistory.time_login, UserLoginHistory.time_logout). \ join(User, User.id == UserLoginHistory.user_id). \ filter(UserLoginHistory.user_id == user.id). \ order_by(UserLoginHistory.id.asc()).all() return render_template('activitylog.html', title='LoginHistory', form=form, activity_records_cnt=activity_records_cnt, activity_records=activity_records) except: return redirect(url_for('home'))