def list_librarians(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.location_id, l.user_id, u.first_name, u.last_name, u.email from libraryapp_librarian l join auth_user u on l.user_id = u.id """) all_librarians = [] dataset = db_cursor.fetchall() for row in dataset: lib = Librarian() lib.id = row["id"] lib.location_id = row["location_id"] lib.user_id = row["user_id"] lib.first_name = row["first_name"] lib.last_name = row["last_name"] lib.email = row["email"] all_librarians.append(lib) template_name = 'librarians/list.html' context = {'all_librarians': all_librarians} return render(request, template_name, context)
def librarian_list(request): with sqlite3.connect( "/Users/joeshep/workspace/python/C40_livecodes/django-library/library/db.sqlite3" ) as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" select l.id, u.first_name, u.last_name from libraryapp_librarian l join auth_user u on l.user_id = u.id """) all_librarians = [] dataset = db_cursor.fetchall() for row in dataset: lib = Librarian() lib.id = row["id"] lib.first_name = row["first_name"] lib.last_name = row["last_name"] all_librarians.append(lib) template_name = 'librarians/list.html' context = {'all_librarians': all_librarians} return render(request, template_name, context)
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 librarian_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.location_id, l.user_id, u.first_name, u.last_name, u.email from libraryapp_librarian l join auth_user u on l.user_id = u.id """) all_librarians = [] dataset = db_cursor.fetchall() for row in dataset: lib = Librarian() lib.id = row["id"] lib.location_id = row["location_id"] lib.user_id = row["user_id"] lib.first_name = row["first_name"] lib.last_name = row["last_name"] lib.email = row["email"] all_librarians.append(lib) template_name = 'librarians/list.html' context = { 'all_librarians': all_librarians } return render(request, template_name, context) #ok, I can tell that the librarians needs to GET the details of WHAT the LOCATION is called. # if I can pull in, perhaps in a join table, the name of the library that each librarian is a memeber of, cool #I wonder if I also need to ask Steve whether we are going to build Librarians differently from how we build libraries and books
def librarian_details(request, librarian_id): if request.method == 'GET': dataset = get_librarian(librarian_id) librarian = Librarian() librarian.id = dataset["id"] librarian.location_id = dataset["location_id"] librarian.user_id = dataset["user_id"] librarian.first_name = dataset["first_name"] librarian.last_name = dataset["last_name"] librarian.email = dataset["email"] librarian.branch_name = dataset["name"] librarian.date_joined = dataset["date_joined"] template = 'librarians/detail.html' context = {'librarian': librarian} return render(request, template, context)
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