Exemple #1
0
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(cursor, row):
        instance = Librarian()

        smart_row = sqlite3.Row(cursor, row)
        for col in smart_row.keys():
            setattr(instance, col, smart_row[col])
        return instance
Exemple #3
0
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'))
Exemple #4
0
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 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
Exemple #6
0
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
Exemple #7
0
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)
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
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