def get_theme(): time_and_theme = table_to_datetime() print "start and theme: ", time_and_theme[0] start_and_theme = updateTimeTheme(time_and_theme[0], time_and_theme[1], current_time()) #new_time = start_and_theme[0] #new_theme = start_and_theme[1] app.config['START'] = start_and_theme[0] app.config['END'] = app.config['START'] + dt.timedelta(hours=2) app.config['THEME'] = start_and_theme[1] if app.config['START'].day != time_and_theme[0].day: new_time = app.config['START'] g.db.execute('delete from theme') command = 'insert into theme values(%d, %d, %d, %d, %d, "%s")' % (new_time.year, new_time.month, new_time.day, new_time.hour, new_time.minute, app.config['THEME']) g.db.execute(command) g.db.commit() return app.config['THEME']
def upload_file(): if not session.get('logged_in'): return redirect(url_for('home')) get_theme() late = not timeAllowed(app.config['START'], current_time()) if request.method == 'POST' and not late: file = request.files['file'] good_form = check_form(request.form, file) if good_form['good']: request.form = clean_form(request.form) originalfilename = secure_filename(file.filename) filename = g.db.execute('select max(id) from food') filename = str(filename.fetchall()[0][0] + 1) + "." + originalfilename.rsplit('.', 1)[1] g.db.execute('insert into food (user, title, description, location, theme, url) values (?,?,?,?,?,?)', [session.get('user'), request.form['title'], request.form['description'], request.form['location'], get_theme(), filename]) g.db.commit() file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return render_template('upload.html', submit=True, filename='images/' + filename, info=request.form) else: return render_template('upload.html', submit=True, error=good_form['error']) return render_template('upload.html', submit=False, late=late, start=app.config['START'])
def show_pics(): if not session.get('logged_in'): return redirect(url_for('home')) theme = get_theme() command = 'select id, user, title, description, location, url from food where theme = "' + theme + '"' cur = g.db.execute(command) entries = [dict(id=row[0], user=row[1],title=row[2],desc=row[3],loc=row[4], url=row[5]) for row in cur.fetchall()] return render_template('show_entries.html', entries=entries, theme=theme, s=app.config['START'], e=app.config['END'], c=current_time())