aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-17 16:40:12 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-17 16:40:12 +0000
commit13b99667fa35ee913c314d5ec0cdb51d5835a98a (patch)
tree61e49b8668b6d51523b5dd25e4ffd00bbeca27ec /pysite/base_route.py
parentsnekchek (diff)
Integrate websockets into the Flask webapp
Diffstat (limited to 'pysite/base_route.py')
-rw-r--r--pysite/base_route.py52
1 files changed, 0 insertions, 52 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
index 8e6648ee..36b7fef5 100644
--- a/pysite/base_route.py
+++ b/pysite/base_route.py
@@ -3,15 +3,10 @@ import os
import random
import string
-from _weakref import ref
-
from flask import Blueprint, jsonify, render_template
from flask.views import MethodView
-from rethinkdb.ast import Table
-
from pysite.constants import ErrorCodes
-from pysite.database import RethinkDB
class BaseView(MethodView):
@@ -124,53 +119,6 @@ class APIView(RouteView):
return response
-class DBViewMixin:
- """
- Mixin for views that make use of RethinkDB. It can automatically create a table with the specified primary
- key using the attributes set at class-level.
-
- This class is intended to be mixed in alongside one of the other view classes. For example:
-
- >>> class MyView(APIView, DBViewMixin):
- ... name = "my_view" # Flask internal name for this route
- ... path = "/my_view" # Actual URL path to reach this route
- ... table_name = "my_table" # Name of the table to create
- ... table_primary_key = "username" # Primary key to set for this table
-
- You may omit `table_primary_key` and it will be defaulted to RethinkDB's default column - "id".
- """
-
- table_name = "" # type: str
- table_primary_key = "id" # type: str
-
- @classmethod
- def setup(cls: "DBViewMixin", manager: "pysite.route_manager.RouteManager", blueprint: Blueprint):
- """
- Set up the view by creating the table specified by the class attributes - this will also deal with multiple
- inheritance by calling `super().setup()` as appropriate.
-
- :param manager: Instance of the current RouteManager (used to get a handle for the database object)
- :param blueprint: Current Flask blueprint
- """
-
- if hasattr(super(), "setup"):
- super().setup(manager, blueprint)
-
- if not cls.table_name:
- raise RuntimeError("Routes using DBViewMixin must define `table_name`")
-
- cls._db = ref(manager.db)
- manager.db.create_table(cls.table_name, primary_key=cls.table_primary_key)
-
- @property
- def table(self) -> Table:
- return self.db.query(self.table_name)
-
- @property
- def db(self) -> RethinkDB:
- return self._db()
-
-
class ErrorView(BaseView):
"""
Error view, shown for a specific HTTP status code, as defined in the class attributes.