import other kontor repos into directories

This commit is contained in:
Thomas Peetz
2025-01-09 19:28:50 +01:00
parent 8120c92b32
commit 9b329c0ac4
319 changed files with 17211 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
# -*- coding:utf-8 -*-
import pymongo
import bookDAO
import bottle
import cgi
__author__ = 'tpeetz'
class Plugin:
def __init__(self, app, database, sessions):
self.app = app
self.db = database
self.sessions = sessions
self.books = bookDAO.BookDAO(database)
self.routing()
def routing(self):
self.app.route('/library', 'GET', self.book_list)
self.app.route('/library/book', 'GET', self.book_list)
self.app.route('/library/book/<id>', 'GET', self.book_details)
self.app.route('/library/book/create', 'GET', self.get_book_create)
self.app.route('/library/book/create', 'POST', self.post_create_book)
def book_list(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
l = self.books.get_books()
return bottle.template('book_list', dict(books=l, username=username))
def book_details(self, id):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
book = self.books.get_book(id)
errors = ""
if book == None:
errors = "Entry not found"
return bottle.template('book_template', dict(title=book['title'],
id=book['_id'],
current_order=book['current_order'],
completed=book['completed'],
errors="",
username=username))
def get_book_create(self):
cookie = bottle.rddequest.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template("book_template", dict(title="",
id='newentry',
current_order=False,
completed=False,
errors="",
username=username))
def post_create_book(self):
book_id = bottle.request.forms.get("id")
book_title = bottle.request.forms.get("title")
book_order = bottle.request.forms.get("current_order")
book_completed = bottle.request.forms.get("completed")
if book_id == "newentry":
self.books.insert_entry(book_title, None, book_order, book_completed)
else:
self.comics.update_entry(book_id, book_title, None, book_order, book_completed)
bottle.redirect("/comics/comic")
+56
View File
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
import sys
class BookDAO:
# constructor for the class
def __init__(self, database):
self.db = database
self.books = database.books
def get_books(self):
cursor = self.books.find()
l = []
for book in cursor:
l.append(
{'title':book['title'],
'_id':book['_id'],
'publisher':book['publisher'],
'isbn':book['isbn'],
'author':book['author']}
)
return l
def get_book(self, book_id):
book = self.books.find_one({"_id": ObjectId(book_id)})
return book
def insert_entry(self, book_title):
print "inserting book entry", book_title
book = {"title": book_title}
# now insert the book
try:
result = self.books.insert_one(book)
print "Matching book: ", result.matched_count
print "Modified book: ", result.modified_count
except:
print "Error inserting book"
print "Unexpected error:", sys.exc_info()
def update_entry(self, book_id, book_title):
print "updating book entry", book_title
filter_doc = {"_id": ObjectId(book_id)}
book = { "$set": {"name": book_title}}
# now insert the book
try:
result = self.books.update_one(filter_doc, book)
print "Modified book: ", result.modified_count
except:
print "Error inserting book"
print "Unexpected error:", sys.exc_info()