Beispiel #1
0
class Handler:  # method/constructor overloading: a
    def __init__(self, collection_name):
        self.client = pymongo.MongoClient(config.get_mongo_config().get_url())
        self.collection_name = collection_name
        self.collection = self.client['filo'][collection_name]
        self.debug = Debug(f"DbHandler({collection_name})", enabled=False)

    def find_all(self):
        self.debug.print_v(f"Finding it all! col:{self.collection_name}")
        return self.collection.find({})

    def drop_all(self):
        self.debug.print_w(f"Dropping whole database!")
        return self.client.drop_database('filo')

    def drop_col(self):
        self.debug.print_w(f"Dropping col:{self.collection_name}")
        return self.collection.drop()

    def find_one(self, search_dict: dict):
        self.debug.print_v(
            f"Searching for dict ({search_dict}) in '{self.collection_name}'")
        return self.collection.find_one(search_dict)

    def insert_one(self, insert_dict: dict):
        self.debug.print_v(
            f"Inserting dict ({insert_dict}) in '{self.collection_name}'")
        return self.collection.insert_one(insert_dict)

    def update_one(self, query: dict, new_values: dict):
        self.debug.print_v(
            f"Updating dict ({query}) with '{new_values}' in '{self.collection_name}'"
        )
        return self.collection.update_one(query, new_values)

    def delete_one(self, delete_dict: dict):
        self.debug.print_v(
            f"Deleting dict ({delete_dict}) in '{self.collection_name}'")
        return self.collection.delete_one(delete_dict)
Beispiel #2
0
from filoViews.AdminView import AdminView

from filoLogic.UserLogic import UserLogic
from filoLogic.RestLogic import RestLogic

from filoModules.Database.Handler import Handler
from filoModules.Database.User import User as db_User
from filoModules.Database.Findlock import Findlock as db_Findlock
from filoModules.Models.GpsLocation import GpsLocation as m_GpsLocation
from filoModules.Models.Findlock import Findlock as m_Findlock
from filoModules.Models.Findlock import FindlockUpdateTypes as m_FindlockUpdateTypes
from filoModules.Debug import Debug
from werkzeug.exceptions import HTTPException

debug = Debug("app.py")
debug.print_v("=" * 16)
debug.print_v("= Filo Server")
debug.print_v("=" * 16)

app = Flask(__name__)
app_blueprints = [RestView, LandingView, AuthView, UserView, AdminView]
for b in app_blueprints:
    app.register_blueprint(b)

app.config.from_object(config.get_flask_conf_obj())
Session(app)

debug.reset_log()


@app.after_request