def login(): form = LoginForm() if form.validate_on_submit(): session.clear() tid = form.USER.data permission = Users().permission(tid) session['user_id'] = tid session['permission'] = permission # The logging handler will be set when needed, see the start module # (<flask_app.__init__>, method <logger>): session['logger'] = None # Set the school-year to the latest one: session['year'] = Paths.getYears()[0] session.permanent = True # Delete old session files sdir = current_app.config['SESSION_FILE_DIR'] now = time.time() for f in os.listdir(sdir): ff = os.path.join(sdir, f) delta = (now - os.path.getmtime(ff)) / 86400 if delta > 2: os.remove(ff) if session.get('user_id'): return redirect(url_for('index')) return render_template(os.path.join(_BPNAME, 'login.html'), form=form)
def index(): class YearForm(FlaskForm): YEAR = SelectField("Schuljahr", coerce=int) schoolyear = session['year'] form = YearForm() form.YEAR.choices = [(y, y) for y in Paths.getYears()] if form.validate_on_submit(): # POST y = form.YEAR.data if y != schoolyear: schoolyear = y session['year'] = y flash("Schuljahr auf %d gesetzt." % y) # GET form.YEAR.default = schoolyear return render_template(os.path.join(_BPNAME, 'index.html'), form=form, heading=_HEADING)