def purge(): current_app.logger.info('backup %s' % current_app.config["SQLALCHEMY_DATABASE_URI"][10:]) now = datetime.datetime.now().strftime("%Y%m%d%H%M%S") copyfile(current_app.config["SQLALCHEMY_DATABASE_URI"][10:], current_app.config["SQLALCHEMY_DATABASE_URI"][10:] + '.' + now) notes = Note.all() for note in notes: note.remove() books = Book.all() for book in books: book.remove() return redirect('/up')
def addhistory(path=''): year = Book.all(sortby=Book.id)[0].year year_path = os.path.join(path, year) if os.path.isdir(year_path) is True: logging.info('delete %s' % year_path) rmtree(year_path) current_app.logger.info('create %s' % year_path) os.mkdir(year_path) current_app.logger.info('backup %s' % current_app.config["SQLALCHEMY_DATABASE_URI"][10:]) copyfile(current_app.config["SQLALCHEMY_DATABASE_URI"][10:], os.path.join(year_path, 'jlat.db')) current_app.logger.info('write index for %s' % year) with open(os.path.join(year_path, "index.html"), "w") as index: index.write(render_template('archive_index.html', year=year)) current_app.logger.info('write reviews for %s' % year) with open(os.path.join(year_path, "reviews.html"), "w") as review: review.write(render_template('archive_reviews.html', year=year, books=Book.all(sortby=Book.idext))) current_app.logger.info('write synth for %s' % year) with open(os.path.join(year_path, "synth.html"), "w") as synth: synth.write(render_template('archive_synth.html', year=year, books=Book.all(sortby=Book.idext), users=User.all(sortby=User.name))) for book in Book.all(): book.remove() return redirect('/history')
def add(): try: opened = ParamRegister.getValue('opened') if opened != 'on': flash("Le concours n'est pas ouvert", 'warning') raise ValueError('is not opened') if int(request.form['factorone']) * int( request.form['factortwo']) != int(request.form['captcha']): flash("Il y a une erreur dans votre multiplication", 'warning') raise ValueError('captcha') if len(request.form['email']) == 0: flash('Vous devez ajouter votre email', 'warning') raise ValueError('no email') if 'file' not in request.files: flash('Vous devez ajouter votre fichier', 'warning') raise ValueError('no file') file = request.files['file'] if file.filename == '': flash('Vous devez ajouter votre fichier', 'warning') raise ValueError('no file') if file and allowed_file(file.filename) is False: flash('Votre fichier n\'a pas le bon format', 'warning') raise ValueError('no file') title = request.form['title'] author = request.form['lastname'] + ' ' + request.form['firstname'] year = ParamRegister.getValue('year') email = ';'.join(request.form['email'].strip().split(' ')) phone = request.form['phone'] nationality = request.form['nationality'] address = request.form['address'] trad_lastname = request.form['trad_lastname'] trad_firstname = request.form['trad_firstname'] trad_email = request.form['trad_email'] trad_phone = request.form['trad_phone'] trad_nationality = request.form['trad_nationality'] trad_address = request.form['trad_address'] description = request.form['description'] file = request.files['file'] if file: filename = secure_filename(file.filename) pathfile = os.path.join( current_app.config['BOOK_FOLDER'], datetime.datetime.now().strftime('%Y%m%d%H%M%S') + unidecode.unidecode(filename)) file.save(pathfile) fileurl = '/uploads' + pathfile.split('/uploads')[1] books = Book.all(sortby=Book.idext) if len(books) == 0: idext = '0001' else: idext = '{:0>4}'.format(str(int(books[-1].idext) + 1)) book = Book(title=title, author=author, year=year, email=email, phone=phone, nationality=nationality, address=address, fileurl=fileurl, trad_lastname=trad_lastname, trad_firstname=trad_firstname, trad_email=trad_email, trad_phone=trad_phone, trad_nationality=trad_nationality, trad_address=trad_address, description=description, idext=idext) book.save() send_mail(book) flash('Votre inscription est validée, vous allez recevoir un mail', 'info') return redirect(request.url) except Exception as err: current_app.logger.error(err) flash('Votre inscription n\'est pas validée', 'error') return redirect(request.url)
def wizardnoteview(): return render_template("wizardnote.html", users=User.all(sortby=User.name), books=Book.all(sortby=Book.idext), notation=NOTATION)
def new(): return render_template('note.html', note=Note(), users=User.all(sortby=User.name), books=Book.all(sortby=Book.title), notation=NOTATION)
def view(id): try: note = Note.get(id=id) if note is not None: return render_template('note.html', note=note, users=User.all(sortby=User.name), books=Book.all(sortby=Book.title), notation=NOTATION) else: raise('note not found') except: flash('Not found note', 'warning') return redirect(url_for('notes'))
def view(): return render_template('synth.html', books=Book.all(sortby=Book.idext), users=User.all(sortby=User.name))
def list(): return render_template("books.html", books=Book.all(sortby=Book.idext))