From 773623005ef39e7990490502d258f0210bc264a9 Mon Sep 17 00:00:00 2001 From: billyrrr Date: Sun, 1 Sep 2019 12:58:31 -0700 Subject: [PATCH] Update dev docs --- README.md | 26 +++++++++++++------------- __init__.py | 5 +++-- examples/view_example.py | 14 +++++--------- quickstart.md | 21 +++++++++------------ src/__init__.py | 2 +- src/factory.py | 4 ++++ 6 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 src/factory.py diff --git a/README.md b/README.md index b71bd2b..3b45cfd 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ CTX.firebase_app ```python +from flask_boiler.factory import ClsFactory +from flask_boiler import schema, fields + + # Creates a schema for serializing and deserializing to firestore database class TestObjectSchema(schema.Schema): @@ -63,23 +67,19 @@ class TestObjectSchema(schema.Schema): int_b = fields.Raw(load_from="intB", dump_to="intB") -# Declares the object -class TestObject(PrimaryObject): - - _schema_cls = TestObjectSchema - - def __init__(self, doc_id=None): - super().__init__(doc_id=doc_id) - - # Initializes default values of your instance variables - self.int_a = 0 - self.int_b = 0 +# Declares the object +TestObject = ClsFactory.create( + name="TestObject", + schema=TestObjectSchema, + # Either MyDomainModelBase (specify cls._collection_id) + # or SubclassOfViewModel + # TODO: ADD MORE DOCS + base=PrimaryObject +) # Creates an object with default values with reference: "TestObject/testObjId1" # (but not saved to database) obj = TestObject.create(doc_id="testObjId1") -assert obj.doc_id == "testObjId1" -assert obj.collection_name == "TestObject" # Assigns value to the newly created object obj.int_a = 1 diff --git a/__init__.py b/__init__.py index 89d01fb..09d625d 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,6 @@ from src import config, context, auth, fields, schema, serializable, \ - firestore_object, domain_model, view_model, view + firestore_object, domain_model, view_model, view, factory __all__ = ["config", "context", "auth", "fields", "schema", "serializable", - "firestore_object", "domain_model", "view_model", "view"] + "firestore_object", "domain_model", "view_model", "view", + "factory"] diff --git a/examples/view_example.py b/examples/view_example.py index 9965d8f..8d635a3 100644 --- a/examples/view_example.py +++ b/examples/view_example.py @@ -18,6 +18,11 @@ from src.context import Context as CTX if __name__ == "__main__": + """ + Go to http://127.0.0.1:5000/apidocs/ for the auto-generated + documentations. + """ + config = Config( app_name="gravitate-dive-testing", debug=True, @@ -44,15 +49,6 @@ class Palette(Schema): description = "A list of colors (may be filtered by palette)" - # class PaletteView(GenericView): - - # def __new__(cls, *args, **kwargs): - # instance = super().__new__(cls, - # view_model_cls=PaletteViewModel, - # description="A list of colors (may be filtered by palette)" - # ) - # return instance - # Create palette document in firestore vm = PaletteViewModel.create( CTX.db.collection("palettes").document("palette_id_a") diff --git a/quickstart.md b/quickstart.md index 5735e1f..bd21b6b 100644 --- a/quickstart.md +++ b/quickstart.md @@ -133,16 +133,15 @@ default value. ```python # Declares the object -class TestObject(DomainModel): - - _schema_cls = TestObjectSchema - - def __init__(self, doc_id=None): - super().__init__(doc_id=doc_id) - - # Initializes default values of your instance variables - self.int_a = 0 - self.int_b = 0 +# Declares the object +TestObject = ClsFactory.create( + name="TestObject", + schema=TestObjectSchema, + # Either MyDomainModelBase (specify cls._collection_id) + # or SubclassOfViewModel + # TODO: ADD MORE DOCS + base=PrimaryObject +) ``` @@ -152,8 +151,6 @@ Now, you can create the object and assign values to it # Creates an object with default values with reference: "TestObject/testObjId1" # (but not saved to database) obj = TestObject.create(doc_id="testObjId1") -assert obj.doc_id == "testObjId1" -assert obj.collection_name == "TestObject" # Assigns value to the newly created object obj.int_a = 1 diff --git a/src/__init__.py b/src/__init__.py index 654b214..d927baa 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,3 +1,3 @@ # from src.context import Context as CTX from . import config, context, auth, fields, schema, serializable, \ - firestore_object, domain_model, view_model + firestore_object, domain_model, view_model, factory diff --git a/src/factory.py b/src/factory.py new file mode 100644 index 0000000..83a3413 --- /dev/null +++ b/src/factory.py @@ -0,0 +1,4 @@ +from .firestore_object import FirestoreObjectClsFactory + + +ClsFactory = FirestoreObjectClsFactory