def updateInformation(): form = AdminForm() if form.validate_on_submit(): course_code = form.course_code.data course_code = form.course_code.data start_time = form.start_time.data end_time = form.end_time.data start_date = form.start_date.data end_date = form.end_date.data location = form.location.data student_array = [] student_details = form.student_details.data # filename = secure_filename(student_details.filename) contents = student_details.read() # contents = contents.decode() contents_stripped = contents.rstrip("\r\n") contents_split = contents_stripped.split("\r\n") first_row = True for content in contents_split: if first_row == True: first_row = False else: data = content.split(",") new_name = data[0] new_email = data[1] if not db.session.query(db.exists().where( Student.email == new_email)).scalar(): new_student = Student(email=new_email, name=new_name) db.session.add(new_student) student_array.append(new_student) if db.session.query(Location).filter( Location.venue == location).first() == True: new_location = db.session.query(Location).filter( Location.venue == location).first() else: new_location = Location(venue=location) db.session.add(new_location) db.session.commit() new_course = Course(course_code=course_code, start_time=start_time, end_time=end_time, start_date=start_date, end_date=end_date, location_id=new_location.id, students=student_array) db.session.add(new_course) db.session.commit() flash('Course information has been updated!') return redirect(url_for('updateInformation')) return render_template('updateinformation.html', title='Admin', form=form)
def admininfo(): form = AdminForm() admininfo = Admin.query.first() if form.validate_on_submit(): admininfo.username = form.username.data admininfo.password = admininfo.set_password(form.password.data) db.session.commit() flash('修改管理员成功') return redirect(url_for('.index')) form.username.data = admininfo.username return render_template('admin/admininfo.html',form=form)
def admin(): if(current_user.get_admin()): return(redirect(url_for("index", title = "Home"))) form = AdminForm() if(form.validate_on_submit()): if(ADMIN_PIN == form.pin.data): current_user.set_admin(True) flash("Congratulations you are now an admin", "success") return(redirect(url_for("index"))) flash("PIN incorrect", "errors") return(render_template("admin.html", form = form, title = "Admin"))
def admin(): form = AdminForm() if form.validate_on_submit(): data = view_database(form.admin_id.data) if data: return render_template("all_visitors.html", title="All Visitors", data=data) else: flash("Wrong admin ID") return redirect(url_for("index")) return render_template("admin.html", title="Admin", form=form)
def admin(): if current_user.is_authenticated: return redirect(url_for('db_admin')) form = AdminForm() if form.validate_on_submit(): user = Admin.query.filter_by(username=form.username.data).first() if not user or user.check_password(form.password.data): flash('Invalid username or password !') return redirect(url_for('admin')) login_user(user) return redirect(url_for('db_admin')) return render_template('admin.html', form=form)
def login(): if current_user.is_authenticated: redirect(url_for('admin')) form = AdminForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() print(admin) if user is None or not user.check_password(form.password.data): flash('Invalid email or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) return redirect(url_for('admin', next=request.url)) return render_template('login.html', title='Login', form=form)
def admin(): form = AdminForm() staging_raw = StagingData.query.order_by(text('-id')).first() production_raw = ProductionData.query.order_by(text('-id')).first() staging = "{}" if staging_raw is None else staging_raw.data production = "{}" if production_raw is None else production_raw.data default = type('', (object, ), {'data': staging}) form = AdminForm(obj=default) if form.validate_on_submit(): if form.submit_new.data: new_data = form.data.data try: json.loads(new_data) except JSONDecodeError as ex: flash('Invalid JSON. data not staged. ' + str(ex)) return render_template('admin.html', title='Admin', form=form, staging=staging, production=production) else: staging_json = str(form.data.data) db.session.add(StagingData(data=staging_json)) flash('Staging updated') if form.promote.data: try: json.loads(staging) except JSONDecodeError as ex: flash( 'Invalid JSON in staging. Data not moved to production. ' + str(ex)) return render_template('admin.html', title='Admin', form=form, staging=staging, production=production) else: db.session.add(ProductionData(data=staging)) flash('Production updated') if form.copy_prod_to_new.data: flash('Copied production to new (no data changes)') db.session.commit() return redirect(url_for('admin')) return render_template('admin.html', title='Admin', form=form, staging=staging, production=production)
def admin(): if current_user.isAdmin is not True: return redirect(url_for('index')) else: all_designs = Designs.query.all() admin_form = AdminForm() admin_form.update_choices() designer_form = DesignerForm() designer_form.update_choices() approve = Approve() reject = Reject() if admin_form.admin_submit.data and admin_form.validate(): user = User.query.filter_by( username=admin_form.username.data).first() if user is not None: user.set_admin() db.session.commit() flash("User appointed as admin", 'success') return redirect(url_for('admin')) else: flash("User does not exist", 'danger') return redirect(url_for('admin')) if designer_form.designer_submit.data and designer_form.validate(): user = User.query.filter_by( username=designer_form.username.data).first() if user is not None: user.set_designer() db.session.commit() flash("User approved as designer.", "success") return redirect(url_for('admin')) else: flash("User does not exist.", "danger") if approve.approve_submit.data and approve.validate(): design = Designs.query.filter_by(id=int(approve.id.data)).first() design.set_approve() db.session.commit() return redirect(url_for('admin')) if reject.reject_submit.data and reject.validate(): design = Designs.query.filter_by(id=int(reject.id.data)).first() design.set_reject() db.session.commit() return redirect(url_for('admin')) return render_template('admin.html', title='Admin - Designer Concept', admin_form=admin_form, designer_form=designer_form, designs=all_designs, approve=approve, reject=reject)
def admin_welcome(): form = AdminForm() if form.validate_on_submit(): admin = Administrator() admin.username = form.username.data admin.first_name = form.first_name.data admin.last_name = form.last_name.data admin.email = form.email.data admin.set_password(form.password.data) admin.site_title = form.site_title.data admin.site_logo_image = form.site_logo_image.data admin.site_logo_text = form.site_logo_text.data admin.jumbotron_image = form.jumbotron_image.data admin.site_dominant_color = form.site_dominant_color.data admin.site_accent_color = form.site_accent_color.data admin.site_background_color = form.site_background_color.data admin.facebook = form.facebook.data admin.twitter = form.twitter.data admin.instagram = form.instagram.data admin.soundcloud = form.soundcloud.data admin.youtube = form.youtube.data admin.spotify = form.spotify.data admin.twitter_consumer_key = form.twitter_consumer_key.data admin.twitter_consumer_key_secret = form.twitter_consumer_key_secret.data admin.twitter_access_token = form.twitter_access_token.data admin.twitter_access_token_secret = form.twitter_access_token_secret.data db.session.add(admin) user = User() user.username = admin.username user.first_name = admin.first_name user.last_name = admin.last_name user.email = admin.email user.pass_hash = admin.pass_hash db.session.add(user) db.session.commit() message = Markup( '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dimiss="alert">×</button> Administrative settings saved. User {} has been created.</div>' .format(user.username)) flash(message) return redirect(url_for('login')) return render_template('admin/welcome.html', form=form)
def addAdmin(): if 'identity' in session and session['identity']!=3: flash('小火汁,你的思想很危险!','danger') return redirect(url_for('.a')) form = AdminForm() if form.validate_on_submit(): other = Admin.query.filter_by(name=form.name.data).all() if other: flash(f'已存在该管理员!') else: admin = Admin(name=form.name.data, pwd=form.password.data, province=form.province.data, system=form.right.data, auth=1) db.session.add(admin) db.session.commit() flash(f'成功新增管理员 {form.name.data}!', 'success') return redirect(url_for('.homeAdmin')) return render_template('addAdmin.html', title='addAdmin', form=form)
def admin(): form = AdminForm() try: admin = db.session.query(Admin).filter(Admin.id==1).one() form.login.data = admin.login except: form.login.data = 'admin' if form.validate_on_submit(): try: admin = db.session.query(Admin).filter(Admin.id==1).one() admin.login = form.login.data admin.set_password(form.password.data) db.session.commit() except: admin = Admin(login=form.login.data) admin.set_password(form.password.data) db.session.add(admin) db.session.commit() flash("Учетная запись администратора изменена") return redirect(url_for("index")) return render_template("admin.html", form=form)
def create1(request): if request.method == "POST": form = AdminForm(request.POST) form.save() redirect('/admintabel') form = AdminForm() return render(request, 'create1.html', {'form': form})
def admin(): users_list = [] def get_users(): for u in User.query.all(): if u.id != current_user.id: users_list.append(u) return users_list context = { 'form': AdminForm(), 'users': get_users(), } form = AdminForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None: new_user = User(email=form.email.data) new_user.set_password(form.email.data) db.session.add(new_user) db.session.commit() flash("Added new user") return redirect(url_for('admin')) return render_template('admin.html', **context)
def update1(request, adminid): admin = Admin.objects.get(id=adminid) form = AdminForm(request.POST, instance=admin) form.save() return redirect('/')