コード例 #1
0
ファイル: main.py プロジェクト: IvanDimitrov2002/subd-project
def add_book():
    if request.method == 'GET':
        return render_template('add_book.html')

    elif request.method == 'POST':
        authors = [
            author.strip()
            for author in request.form['book_authors'].split(',')
        ]
        title = request.form['book_title']
        genre = request.form['book_genre']
        isbn = request.form['book_isbn']
        date = request.form['book_date']
        if authors is not None and title != '' and genre != '' and isbn != '' \
           and date != '':
            book = Book(None, isbn, genre, title, date)
            book.add_book(authors)
            return redirect(url_for('books'))

        elif title == "":
            return render_template('add_book.html', error='Title is reuqered!')

        elif genre == "":
            return render_template('add_book.html', error='Genre is reuqered!')

        elif isbn == "":
            return render_template('add_book.html', error='ISBN is reuqered!')

        elif date == "":
            return render_template('add_book.html', error='Date is reuqered!')

        elif authors is None:
            return render_template('add_book.html',
                                   error='''At least one
                                   author is requred!''')
コード例 #2
0
 def post(self, action):
     # Lets _try_ to add the book and all that.
     error = False
     binding = ''
     condition = ''
     google_id = self.request.get('google_id')
     try:
         binding = self.request.get('binding')
         condition = self.request.get('condition')
     except:
         pass
     comments = self.request.get('comments')
     # Quietly ignore errors for now
     try:
         price = float(self.request.get('price'))
     except:
         price = 0.0
     new_book = Book.add_book(google_id)
     if new_book is None:
         logging.debug('Error inserting book with google_id of ' +
                       google_id + '!')
         error = True
     else:
         email = self.session.get('email')
         user = User.get_user(email)
         print(action)
         logging.info(action)
         if action == 'sell':
             BookListing.sell_book(new_book, user['id'], price, binding,
                                   condition, comments)
         else:
             BookListing.request_book(new_book, user['id'], price, binding,
                                      condition, comments)
     return self.redirect('/')