Skip to content

Commit

Permalink
Update dev docs
Browse files Browse the repository at this point in the history
  • Loading branch information
billyrrr committed Sep 1, 2019
1 parent b4ded3c commit 7736230
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 5 additions & 9 deletions examples/view_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
21 changes: 9 additions & 12 deletions quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .firestore_object import FirestoreObjectClsFactory


ClsFactory = FirestoreObjectClsFactory

0 comments on commit 7736230

Please sign in to comment.