move Git repository kontor-docker to directory bottle-docker

This commit is contained in:
Thomas Peetz
2025-03-29 19:05:31 +01:00
parent 45971518ee
commit a5cdf8867a
29 changed files with 1681 additions and 0 deletions
+193
View File
@@ -0,0 +1,193 @@
# -*- coding:utf-8 -*-
import pymongo
import comics.publisherDAO
import comics.artistDAO
import comics.comicDAO
import bottle
import cgi
__author__ = 'tpeetz'
class Plugin:
def __init__(self, app, database, sessions):
self.app = app
self.db = database
self.sessions = sessions
self.publishers = publisherDAO.PublisherDAO(database)
self.artists = artistDAO.ArtistDAO(database)
self.comics = comicDAO.ComicDAO(database)
self.routing()
def routing(self):
self.app.route('/comics/', 'GET', self.comic_index)
self.app.route('/comics/comic', 'GET', self.comic_list)
self.app.route('/comics/comic/<id>', 'GET', self.comic_details)
self.app.route('/comics/comic/create', 'GET', self.get_comic_create)
self.app.route('/comics/comic/create', 'POST', self.post_create_comic)
self.app.route('/comics/publisher', 'GET', self.publisher_list)
self.app.route('/comics/publisher/<id>', 'GET', self.publisher_details)
self.app.route('/comics/publisher/create', 'GET', self.get_publisher_create)
self.app.route('/comics/publisher/create', 'POST', self.post_create_publisher)
self.app.route('/comics/artist', 'GET', self.artist_list)
self.app.route('/comics/artist/<id>', 'GET', self.artist_details)
self.app.route('/comics/artist/create', 'GET', self.get_artist_create)
self.app.route('/comics/artist/create', 'POST', self.post_create_artist)
self.app.route('/comics/storyarc', 'GET', self.storyarc_list)
self.app.route('/comics/storyarc/<id>', 'GET', self.storyarc_details)
self.app.route('/comics/storyarc/create', 'GET', self.get_storyarc_create)
self.app.route('/comics/storyarc/create', 'POST', self.post_create_storyarc)
def comic_index(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template('comic_index', dict(username=username))
def comic_list(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
l = self.comics.get_comics()
return bottle.template('comic_list', dict(comics=l, username=username))
def comic_details(self, id):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
comic = self.comics.get_comic(id)
errors = ""
if comic == None:
errors = "Entry not found"
return bottle.template('comic_template', dict(title=comic['title'],
id=comic['_id'],
current_order=comic['current_order'],
completed=comic['completed'],
errors="",
username=username))
def get_comic_create(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template("comic_template", dict(title="",
id='newentry',
current_order=False,
completed=False,
errors="",
username=username))
def post_create_comic(self):
comic_id = bottle.request.forms.get("id")
comic_title = bottle.request.forms.get("title")
comic_order = bottle.request.forms.get("current_order")
comic_completed = bottle.request.forms.get("completed")
if comic_id == "newentry":
self.comics.insert_entry(comic_title, None, comic_order, comic_completed)
else:
self.comics.update_entry(comic_id, comic_title, None, comic_order, comic_completed)
bottle.redirect("/comics/comic")
def publisher_list(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
l = self.publishers.get_publishers()
return bottle.template('publisher_list', dict(publishers=l, username=username))
def publisher_details(self, id):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
publisher = self.publishers.get_publisher(id)
errors = ""
if publisher == None:
errors= "Entry not found"
return bottle.template('publisher_template', dict(name=publisher['name'], id=publisher['_id'], errors="", username=username))
def get_publisher_create(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template("publisher_template", dict(name="", id='newentry', errors="", username=username))
def post_create_publisher(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
publisher_id = bottle.request.forms.get("id")
publisher_name = bottle.request.forms.get("name")
if publisher_id == "newentry":
self.publishers.insert_entry(publisher_name)
else:
self.publishers.update_entry(publisher_id, publisher_name)
bottle.redirect("/comics/publisher")
def artist_list(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
l = self.artists.get_artists()
return bottle.template('artist_list', dict(artists=l, username=username))
def artist_details(self, id):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
artist = self.artists.get_artist(id)
errors = ""
if artist == None:
errors= "Entry not found"
return bottle.template('artist_template', dict(name=artist['name'], id=artist['_id'], errors="", username=username))
def get_artist_create(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template("artist_template", dict(name="", id='newentry', errors="", username=username))
def post_create_artist(self):
artist_id = bottle.request.forms.get("id")
artist_name = bottle.request.forms.get("name")
if artist_id == "newentry":
self.artists.insert_entry(artist_name)
else:
self.artists.update_entry(artist_id, artist_name)
bottle.redirect("/comics/artist")
def storyarc_list(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
l = self.storyarcs.get_storyarcs()
return bottle.template('storyarc_list', dict(storyarcs=l, username=username))
def storyarc_details(self, id):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
storyarc = self.storyarcs.get_storyarc(id)
errors = ""
if storyarc == None:
errors = "Entry not found"
return bottle.template('storyarc_template', dict(title=storyarc['title'], id=storyarc['_id'], errors="", username=username))
def get_storyarc_create(self):
cookie = bottle.request.get_cookie("session")
username = self.sessions.get_username(cookie)
return bottle.template("storyarc_template", dict(title="", id='newentry', errors="", username=username))
def post_create_storyarc(self):
storyarc_id = bottle.request.forms.get("id")
storyarc_title = bottle.request.forms.get("title")
if storyarc_id == "newentry":
self.storyarcs.insert_entry(storyarc_title)
else:
self.storyarcs.update_entry(storyarc_id, storyarc_title)
bottle.redirect("/comics/storyarc")
+49
View File
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
import sys
class ArtistDAO:
# constructor for the class
def __init__(self, database):
self.db = database
self.artists = database.artists
def get_artists(self):
cursor = self.artists.find()
l = []
for artist in cursor:
l.append({'name':artist['name'], '_id':artist['_id']})
return l
def get_artist(self, artist_id):
artist = self.artists.find_one({"_id": ObjectId(artist_id)})
return artist
def insert_entry(self, artist_name):
print("inserting artist entry", artist_name)
artist = {"name": artist_name}
# now insert the post
try:
result = self.artists.insert_one(artist)
print("Matching artist: ", result.matched_count)
print("Modified artist: ", result.modified_count)
except:
print("Error inserting artist")
print("Unexpected error:", sys.exc_info())
def update_entry(self, artist_id, artist_name):
print("upserting artist entry", artist_name)
filter_doc = {"_id": ObjectId(artist_id)}
artist = { "$set": {"name": artist_name}}
# now insert the post
try:
result = self.artists.update_one(filter_doc, artist)
print("Modified artist: ", result.modified_count)
except:
print("Error inserting artist")
print("Unexpected error:", sys.exc_info())
+52
View File
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
import sys
class ComicDAO:
# constructor for the class
def __init__(self, database):
self.db = database
self.comics = database.comics
def get_comics(self):
cursor = self.comics.find()
l = []
for comic in cursor:
l.append({'title':comic['title'],
'_id':comic['_id'],
'current_order':comic['current_order'],
'completed':comic['completed']})
return l
def get_comic(self, comic_id):
comic = self.comics.find_one({"_id": ObjectId(comic_id)})
return comic
def insert_entry(self, comic_title, comic_publisher=None, comic_order=False, comic_completed=False):
print("inserting comic entry", comic_title)
comic = {"title": comic_title, "current_order": comic_order, "completed": comic_completed}
# now insert the comic
try:
result = self.comics.insert_one(comic)
print("Modified comic: ", result.modified_count)
except:
print("Error inserting comic")
print("Unexpected error:", sys.exc_info())
def update_entry(self, comic_id, comic_title, comic_publisher=None, comic_order=False, comic_completed=False):
print("upserting comic entry", comic_title)
filter_doc = {"_id": ObjectId(comic_id)}
comic = { "$set": {"title": comic_title, 'current_order': comic_order, 'completed': comic_completed}}
# now insert the post
try:
result = self.comics.update_one(filter_doc, comic)
print("Matching comic: ", result.matched_count)
print("Modified comic: ", result.modified_count)
except:
print("Error inserting comic")
print("Unexpected error:", sys.exc_info())
+121
View File
@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
from mongoengine import connect, Document
from mongoengine import StringField, BooleanField
from mongoengine import ListField, ReferenceField, GenericReferenceField
import pprint
class Publisher(Document):
name = StringField(required=True)
def __str__(self):
s = "Publisher(%s)" % self.name
return s
class Artist(Document):
name = StringField(required=True)
className = StringField()
def __str__(self):
s = "Artist(%s)" % self.name
return s
class Issue(Document):
number = StringField()
comic = GenericReferenceField()
is_read = BooleanField(default=False)
is_stock = BooleanField(default=False)
def __str__(self):
s = "Issue(%s # %s, %s)" % (self.comic.title, self.number, self.is_read)
return s
class StoryArc(Document):
name = StringField(required=True)
comic = GenericReferenceField()
issues = ListField(ReferenceField(Issue))
def __str__(self):
s = "StoryArc(%s, %s)" % (self.name, self.comic.title)
return s
class Volume(Document):
name = StringField(required=True)
comic = GenericReferenceField()
issues = ListField(ReferenceField(Issue))
def __str__(self):
s = "Volume(%s, %s, %s)" % (self.id, self.name, self.comic.title)
return s
class Comic(Document):
title = StringField(required=True)
publisher = ReferenceField(Publisher)
current_order = BooleanField()
completed = BooleanField()
issues = ListField(ReferenceField(Issue))
stories = ListField(ReferenceField(StoryArc))
def __str__(self):
if self.publisher is None:
s = "Comic(%s, %s, %s, %s)" % (self.title, self.publisher, self.current_order, self.completed)
return s
else:
s = "Comic(%s, %s, %s, %s)" % (
self.title, self.publisher.name, self.current_order, self.completed)
return s
class TradePaperback(Document):
comic = ReferenceField(Comic)
issue_start = StringField()
issue_end = StringField()
def __str__(self):
s = "TPB(%s)" % self.comic.title
return s
def get_publisher(name):
publisher = Publisher.objects(name=name)
if publisher.count() > 0:
return publisher[0]
else:
return None
def get_comic(title):
comic = Comic.objects(title=title)
if comic.count() > 0:
return comic[0]
else:
return None
def get_issue(title, number):
comic = get_comic(title)
issues = Issue.objects(number=number, comic=comic)
if issues.count() > 0:
return issues[0]
else:
return None
if __name__ == '__main__':
connect('comics')
for publisher in Publisher.objects:
pprint.pprint(publisher)
for artist in Artist.objects:
pprint.pprint(artist)
for comic in Comic.objects:
pprint.pprint(comic)
for issue in Issue.objects:
pprint.pprint(issue)
for story in StoryArc.objects:
pprint.pprint(story)
for tpb in TradePaperback.objects:
pprint.pprint(tpb)
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
import sys
class PublisherDAO:
# constructor for the class
def __init__(self, database):
self.db = database
self.publishers = database.publishers
def get_publishers(self):
cursor = self.publishers.find()
l = []
for publisher in cursor:
l.append({'name':publisher['name'], '_id':publisher['_id']})
return l
def get_publisher(self, publisher_id):
publisher = self.publishers.find_one({"_id": ObjectId(publisher_id)})
return publisher
def insert_entry(self, publisher_name):
print("inserting publisher entry", publisher_name)
publisher = {"name": publisher_name}
# now insert the post
try:
result = self.publishers.insert_one(publisher)
print("Matching publisher: ", result.matched_count)
print("Modified publisher: ", result.modified_count)
except:
print("Error inserting publisher")
print("Unexpected error:", sys.exc_info())
def update_entry(self, publisher_id, publisher_name):
print("upserting publisher entry", publisher_name)
filter_doc = {"_id": ObjectId(publisher_id)}
publisher = { "$set": {"name": publisher_name}}
# now insert the post
try:
result = self.publishers.update_one(filter_doc, publisher)
print("Modified publisher: ", result.modified_count)
except:
print("Error inserting publisher")
print("Unexpected error:", sys.exc_info())
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
import sys
class StoryArcDAO:
# constructor for the class
def __init__(self, database):
self.db = database
self.storyarcs = database.storyarcs
def get_storyarcs(self):
cursor = self.storyarcs.find()
l = []
for storyarc in cursor:
l.append({'title': storyarc['title'], '_id': storyarc['_id']})
return l
def get_storyarc(self, storyarc_id):
storyarc = self.storyarcs.find_one({"_id": ObjectId(storyarc_id)})
return storyarc
def insert_entry(self, storyarc_title):
print("inserting publisher entry", storyarc_title)
storyarc = {"name": storyarc_title}
# now insert the post
try:
result = self.storyarcs.insert_one(storyarc)
print("Matching storyarc: ", result.matched_count)
print("Modified storyarc: ", result.modified_count)
except:
print("Error inserting storyarc")
print("Unexpected error:", sys.exc_info())
def update_entry(self, storyarc_id, storyarc_title):
print("upserting storyarc entry", storyarc_title)
filter_doc = {"_id": ObjectId(storyarc_id)}
storyarc = {"$set": {"name": storyarc_title}}
# now insert the post
try:
result = self.storyarcs.update_one(filter_doc, storyarc)
print("Modified storyarc: ", result.modified_count)
except:
print("Error inserting storyarc")
print("Unexpected error:", sys.exc_info())