Example #1
0
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
Example #2
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,
            u.username
        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"]
            lib.username = row["username"]

            all_librarians.append(lib)

    template_name = 'librarians/list.html'

    context = {'all_librarians': all_librarians}

    return render(request, template_name, context)