def create_library(cursor, row): _row = sqlite3.Row(cursor, row) library = Library() library.id = _row["id"] library.title = _row["title"] library.address = _row["address"] # Note: You are adding a blank books list to the library object # This list will be populated later (see below) library.books = [] book = Book() book.id = _row["book_id"] book.title = _row["book_title"] book.author = _row["author"] book.isbn = _row["isbn"] book.year_published = _row["year_published"] # Return a tuple containing the library and the # book built from the data in the current row of # the data set return ( library, book, )
def library_list(request): with sqlite3.connect(Connection.db_path) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" select l.libraryId, l.library_name, l.library_address, from libraryapp_library l """) all_libraries = [] dataset = db_cursor.fetchall() for row in dataset: library = Library() library.id = row["id"] library.name = row["name"] library.address = row["address"] all_libraries.append(lib) template_name = 'library/list.html' context = {'all_libraries': all_libraries} return render(request, template_name, context)
def book_details(request, book_id): if request.method == 'GET': book = get_book(book_id) template_name = 'books/detail.html' return render(request, template_name, {'book': book}) elif request.method == 'POST': form_data = request.POST # Check if this POST is for editing a book if ("actual_method" in form_data and form_data["actual_method"] == "PUT"): book = Book.objects.get(pk=book_id) book.title = form_data['title'] book.author = form_data['author'] book.ISBN_num = form_data['ISBN_num'] book.year_published = form_data['year_published'] library = Library() library.id = form_data['location'] book.location = library book.save() return redirect(reverse('libraryapp:books')) # Check if this POST is for deleting a book if ("actual_method" in form_data and form_data["actual_method"] == "DELETE"): book = Book.objects.get(pk=book_id) book.delete() return redirect(reverse('libraryapp:books'))
def library_list(request): if request.method == 'GET': with sqlite3.connect(Connection.db_path) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" select li.id, li.title, li.address from libraryapp_library li """) all_libraries = [] dataset = db_cursor.fetchall() for row in dataset: library = Library() library.id = row['id'] library.title = row['title'] library.address = row['address'] all_libraries.append(library) template = 'libraries/list.html' context = {'all_libraries': all_libraries} return render(request, template, context)
def book_list(request): if request.method == 'GET': all_books = Book.objects.all() template = 'books/list.html' context = {'all_books': all_books} return render(request, template, context) elif request.method == 'POST': form_data = request.POST new_book = Book() new_book.title = form_data['title'] new_book.author = form_data['author'] new_book.ISBN_num = form_data['ISBN_num'] new_book.year_published = form_data['year_published'] librarian = Librarian() librarian.id = request.user.librarian.id new_book.librarian = librarian library = Library() library.id = form_data['location'] new_book.location = library new_book.save() return redirect(reverse('libraryapp:books'))
def library_list(request): with sqlite3.connect(Connection.db_path) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" SELECT l.id, l.title, l.address FROM libraryapp_library l; """) all_libraries = [] dataset = db_cursor.fetchall() for row in dataset: lib = Library() lib.id = row["id"] lib.title = row["title"] lib.address = row["address"] all_libraries.append(lib) template_name = 'libraries/list.html' context = {'all_libraries': all_libraries} return render(request, template_name, context)
def library_list(request): if request.method == 'GET': with sqlite3.connect(Connection.db_path) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" select l.id, l.title, l.address from libraryapp_library l """) all_libraries = [] dataset = db_cursor.fetchall() for row in dataset: lib = Library() lib.id = row["id"] lib.title = row["title"] lib.address = row["address"] all_libraries.append(lib) template_name = 'libraries/list.html' context = { 'all_libraries': all_libraries } return render(request, template_name, context) elif request.method == 'POST': form_data = request.POST with sqlite3.connect(Connection.db_path) as conn: db_cursor = conn.cursor() db_cursor.execute(""" INSERT INTO libraryapp_library ( title, address ) VALUES (?, ?) """, (form_data['title'], form_data['address'])) return redirect(reverse('libraryapp:libraries'))
def create_librarian(cursor, row): _row = sqlite3.Row(cursor, row) librarian = Librarian() librarian.id = _row["librarian_id"] librarian.first_name = _row["first_name"] librarian.last_name = _row["last_name"] librarian.location = _row["location_id"] librarian.username = _row["username"] library = Library() library.id = _row["library_id"] library.title = _row["library_name"] library.address = _row["library_address"] librarian.library = library return librarian
def create_library(cursor, row): _row = sqlite3.Row(cursor, row) library = Library() library.id = _row["id"] library.name = _row["name"] library.address = _row["address"] library.books = [] book = Book() book.id = _row["book_id"] book.title = _row["book_title"] book.author = _row["author"] book.publisher = _row["publisher"] book.year_published = _row["year_published"] book.isbn = _row["isbn"] return ( library, book, )
def create_library(cursor, row): _row = sqlite3.Row(cursor, row) library = Library() library.id = _row["id"] library.title = _row["title"] library.address = _row["address"] library.books = [] book = Book() book.id = _row["book_id"] book.title = _row["book_title"] book.author = _row["author"] book.isbn = _row["isbn"] book.year_published = _row["year_published"] # Return a tuple containing the library and the # book built from the data in the current row of # the data set return (library, book)
def create_library(cursor, row): _row = sqlite3.Row(cursor, row) library = Library() library.id = _row["id"] library.title = _row["title"] library.address = _row["address"] library.books = [] book = Book() book.id = _row["id"] book.title = _row["book_title"] book.author = _row["author"] book.isbn_number = _row["isbn_number"] book.year = _row["year"] return ( library, book, )
def get_libraries(): with sqlite3.connect(Connection.db_path) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" SELECT id, title, address FROM libraryapp_library """) all_libraries = [] dataset = db_cursor.fetchall() for row in dataset: library = Library() library.id = row['id'] library.title = row['title'] library.address = row['address'] all_libraries.append(library) return all_libraries
def create_book(cursor, row): _row = sqlite3.Row(cursor, row) book = Book() book.id = _row["book_id"] book.author = _row["author"] book.isbn_number = _row["isbn_number"] book.title = _row["title"] book.year_published = _row["year_published"] librarian = Librarian() librarian.id = _row["librarian_id"] librarian.first_name = _row["first_name"] librarian.last_name = _row["last_name"] library = Library() library.id = _row["library_id"] library.title = _row["library_name"] book.librarian = librarian book.location = library return book
def create_book(cursor, row): _row = sqlite3.Row(cursor, row) book = Book() book.id = _row["book_id"] book.Author = _row["Author"] book.ISBNNumber = _row["ISBNNumber"] book.bookTitle = _row["bookTitle"] book.YearPublished = _row["YearPublished"] librarian = Librarian() librarian.id = _row["librarian_id"] librarian.first_name = _row["first_name"] librarian.last_name = _row["last_name"] library = Library() library.id = _row["library_id"] library.title = _row["library_name"] book.librarian = librarian book.location = library return book
def create_book(cursor, row): _row = sqlite3.Row(cursor, row) book = Book() book.id = _row['book_id'] book.author = _row['author'] book.isbn = _row['isbn'] book.title = _row['title'] book.year_published = _row['year_published'] librarian = Librarian() librarian.id = _row['librarian_id'] librarian.first_name = _row['first_name'] librarian.last_name = _row['last_name'] library = Library() library.id = _row['library_id'] library.title = _row['library_name'] book.librarian = librarian book.location = library return book