Esempio n. 1
0
 def save_book(self, book):
     author, _ = self.get_or_create(Author,
         first_name = book.author_first_name,
         middle_name = book.author_middle_name,
         last_name = book.author_last_name,
     )
     genre, _ = self.get_or_create(Genre, name=book.genre)
     db_book = Book(path=book.path, title=book.title)
     db_book.author = author
     db_book.genre = genre
     self.session.add(db_book)
     self.session.commit()
     return db_book
Esempio n. 2
0
def delete(id):
    book = Book.get(id=id)
    if book is not None:
        title = book.title
        book.remove()
        flash('Book "%s" is deleted' % title,'error')
    return redirect(url_for('book.books'))
Esempio n. 3
0
def view(id):
    try:
        book = Book.get(id=id)
        if book is not None:
            return render_template('book.html', book=book)
        else:
            raise('book not found')
    except:
        flash('Not found book', 'warning')
        return redirect(url_for('books'))
Esempio n. 4
0
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')
Esempio n. 5
0
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')
Esempio n. 6
0
def update(id):
    book = Book.get(id=id)
    if book is not None:
        book.title = request.form['title']
        book.description = request.form['description']
        book.author = request.form['author']
        book.year = request.form['year']
        book.idext = request.form['idext']
        book.onrace = getBool.get(request.form.get('onrace','off'),False)
        book.email = request.form['email']
        book.phone = request.form['phone']
        book.nationality = request.form['nationality']
        book.address = request.form['address']
        book.trad_lastname = request.form['trad_lastname']
        book.trad_firstname = request.form['trad_firstname']
        book.trad_email = request.form['trad_email']
        book.trad_phone = request.form['trad_phone']
        book.trad_nationality = request.form['trad_nationality']
        book.trad_address = request.form['trad_address'] 
        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)
            book.fileurl = '/uploads' + pathfile.split('/uploads')[1]
    
        filep = request.files['filep']
        if filep:
            filename = secure_filename(filep.filename)
            pathfile = os.path.join(current_app.config['BOOK_FOLDER'], datetime.datetime.now().strftime('%Y%m%d%H%M%S') + unidecode.unidecode(filename))
            filep.save(pathfile)
            book.filepdf = '/uploads' + pathfile.split('/uploads')[1]
        
        fileu = request.files['fileu']
        if fileu:
            filename = secure_filename(fileu.filename)
            pathfile = os.path.join(current_app.config['BOOK_FOLDER'], datetime.datetime.now().strftime('%Y%m%d%H%M%S') + unidecode.unidecode(filename))
            fileu.save(pathfile)
            book.fileepub = '/uploads' + pathfile.split('/uploads')[1]
        book.save()
        flash('Book "%s" is saved' % book.title,'success')
        return redirect(url_for('book.view_book', id=book.id))
    else:
        flash('Book doesn\'t exist','error')
        return redirect(url_for('book.books'))
Esempio n. 7
0
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)
Esempio n. 8
0
def wizardnoteview():
    return render_template("wizardnote.html", users=User.all(sortby=User.name), books=Book.all(sortby=Book.idext), notation=NOTATION)
Esempio n. 9
0
def new():
    return render_template('note.html', note=Note(), users=User.all(sortby=User.name), books=Book.all(sortby=Book.title), notation=NOTATION)
Esempio n. 10
0
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'))
Esempio n. 11
0
def view():
    return render_template('synth.html',
                           books=Book.all(sortby=Book.idext),
                           users=User.all(sortby=User.name))
Esempio n. 12
0
def create():
    title = request.form['title']
    idext = request.form['idext']
    description = request.form['description']
    author = request.form['author']
    year = request.form['year']
    onrace = getBool.get(request.form.get('onrace','off'),False)
    email = request.form['email']
    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']

    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]
    
    filep = request.files['filep']
    if filep:
        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))
        filep.save(pathfile)
        filepdf = '/uploads' + pathfile.split('/uploads')[1]
    
    fileu = request.files['fileu']
    if fileu:
        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))
        fileu.save(pathfile)
        fileepub = '/uploads' + pathfile.split('/uploads')[1]

    book = Book(title=title, 
        description=description,
        author=author,
        year=year,
        idext=idext,
        onrace=onrace,
        email=email,
        phone=phone,
        nationality=nationality,
        address=address,
        fileurl=fileurl,
        filepdf=filepdf,
        fileepub=fileepub,
        trad_lastname=trad_lastname,
        trad_firstname=trad_firstname,
        trad_email=trad_email,
        trad_phone=trad_phone,
        trad_nationality=trad_nationality,
        trad_address=trad_address)
    book.save()
    flash('Book "%s" is created' % title, 'success')
    return redirect(url_for('book.view_book', id=book.id))
Esempio n. 13
0
def new():
    return render_template('book.html', book=Book(onrace=True))
Esempio n. 14
0
def list():
    return render_template("books.html", books=Book.all(sortby=Book.idext))