Skip to content

Commit

Permalink
Add description to property builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Mar 8, 2020
1 parent fa10acf commit a256ed1
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions examples/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

from labthings.server.quick import create_app
from labthings.server.view import View
from labthings.server.decorators import ThingProperty, PropertySchema, use_args
from labthings.server.decorators import ThingProperty, PropertySchema, use_args, Doc

from labthings.server.types import value_to_field, data_dict_to_schema

from components.pdf_component import PdfComponent


def gen_property(property_object, property_name, name: str = None, readonly=False):
def gen_property(
property_object, property_name, name: str = None, readonly=False, description=None
):

# Create a class name
if not name:
Expand Down Expand Up @@ -57,6 +59,11 @@ def _put(self, args):
generated_class = PropertySchema(property_schema)(generated_class)
generated_class = ThingProperty(generated_class)

if description:
generated_class = Doc(description=description, summary=description)(
generated_class
)

return generated_class


Expand All @@ -74,8 +81,18 @@ def _put(self, args):
labthing.add_component(my_component, "org.labthings.example.mycomponent")

# Add routes for the API views we created
labthing.add_view(gen_property(my_component, "magic_denoise"), "/denoise")
labthing.add_view(gen_property(my_component, "magic_dictionary"), "/dictionary")
labthing.add_view(
gen_property(my_component, "magic_denoise", description="A magic denoise property"),
"/denoise",
)
labthing.add_view(
gen_property(
my_component,
"magic_dictionary",
description="A big dictionary of little properties",
),
"/dictionary",
)

# Start the app
if __name__ == "__main__":
Expand Down

0 comments on commit a256ed1

Please sign in to comment.