Esempio n. 1
0
def add_book(request):
    response = {}
    try:
        book = Book(book_name=request.GET.get('book_name'))
        book.save()
        response['msg'] = 'success'
        response['error_num'] = 0
    except Exception, e:
        response['msg'] = str(e)
        response['error_num'] = 1
Esempio n. 2
0
def add_answer(request):
    response = {}
    try:
        book = Book(book_name=request.GET.get('book_name'))
        book.save()
        response['msg'] = 'success'
        response['error_num'] = 0
    except  Exception as e:
        response['msg'] = str(e)
        response['error_num'] = 1

    return JsonResponse(response)
Esempio n. 3
0
        def test_two(self):
            print "Inside test_two"
            # Add another author on the fly
            author = Author()
            author.first_name = 'Aldous'
            author.last_name = 'Huxley'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "Brave New World"
            book.published_date = datetime.datetime(1932, 5, 12)
            self.db.session.add(book)

            self.db.session.commit()
Esempio n. 4
0
        def test_one(self):
            print "Inside test_one"
            # Add another author on the fly
            author = Author()
            author.first_name = 'George'
            author.last_name = 'Orwell'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "1984"
            book.published_date = datetime.datetime(1949, 6, 8)
            self.db.session.add(book)

            self.db.session.commit()
        def test_two(self):
            print("Inside test_two")
            # Add another author on the fly
            author = Author()
            author.first_name = 'Aldous'
            author.last_name = 'Huxley'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "Brave New World"
            book.published_date = datetime.datetime(1932, 5, 12)
            self.db.session.add(book)

            self.db.session.commit()
        def test_one(self):
            print("Inside test_one")
            # Add another author on the fly
            author = Author()
            author.first_name = 'George'
            author.last_name = 'Orwell'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "1984"
            book.published_date = datetime.datetime(1949, 6, 8)
            self.db.session.add(book)

            self.db.session.commit()
Esempio n. 7
0
def addbook(request):
	if request.GET:
		book = Book()
		book.ISBN = request.GET['ISBN']
		book.Title = request.GET['Title']
		book.AuthorID = request.GET['AuthorID']
		book.Publisher = request.GET['Publisher']
		book.PublishDate = request.GET['PublishDate']
		book.Price = request.GET['Price']
		
		id = Author.objects.filter(AuthorID = book.AuthorID)
		if not id:
			return render_to_response('author_not_exist.html')
		else:
			book.save()
		return render_to_response('add_finish.html')
	else:
		return render_to_response('addbook.html')
Esempio n. 8
0
def add_book():
    form = BookForm()
    books = Book.query.all()
    if form.validate_on_submit():
        title = form.title.data
        author = form.author.data
        year = int(form.year.data)
        month = int(form.month.data)
        day = int(form.day.data)
        date_time = datetime.date(year, month, day)

        book = Book(title=title, author=author, publish_date=date_time)
        db.session.add(book)
        db.session.commit()
        return redirect(url_for('add_book'))

    return render_template('book.html',
                           title="Kitap Ekle",
                           form=form,
                           books=books)
Esempio n. 9
0
import json
from myapp.models import Author, Book
from bpmappers.djangomodel import ModelMapper


class AuthorMapper(ModelMapper):
    class Meta:
        model = Author


class BookMapper(ModelMapper):
    class Meta:
        model = Book


author = Author(name="tokibito", company="BeProud")
book = Book(title="Spam", price=500, author=author)
# マッピングとJSON変換
print("author:", json.dumps(AuthorMapper(author).as_dict(), indent=2))
print("book:", json.dumps(BookMapper(book).as_dict(), indent=2))
Esempio n. 10
0
def InsertBook(request, isbn, title, memo):
    Book(isbn=isbn, title=title, memo={'content': memo}).save()
    return render(request, 'myapp/mypage.html',
                  { 'welcome_text': 'Insert: ' + title })