From 47373db2c957d4c3ab2294cec1637a96326c9b59 Mon Sep 17 00:00:00 2001 From: Afonso Caldas Date: Mon, 18 Jan 2016 18:38:05 +0000 Subject: [PATCH 1/3] new doc structure --- doc/models.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 79 ++------------------------------------------------- 2 files changed, 82 insertions(+), 76 deletions(-) create mode 100644 doc/models.md diff --git a/doc/models.md b/doc/models.md new file mode 100644 index 00000000..1360aafb --- /dev/null +++ b/doc/models.md @@ -0,0 +1,79 @@ +# Models + +Models that inherit from ``appier_extras.admin.Base`` are automatically added to the admin interface. +You can find more information about Appier models [here](http://appier.hive.pt/doc/models.md). + +## Model Operations + +To add an operation accessible from the the admin interface be executed on a model, add this to the model definition: + +```python +class Cat: + + @classmethod + @appier.operation(name = "Meow") + def meow(cls): + cats = cls.find() + for cat in cats: cat._meow() +``` + +To make the same operation be associated with a single instance, just to apply to an instance method instead: + +```python + @appier.operation(name = "Meow") + def meow(self): + self._meow() +``` + +An operation can receive parameters that will be sent to the handler method: + +```python + @appier.operation( + name = "Meow", + parameters = ( + ("Number of meows", "number_meows", int), + ) + ) + def meow(self, number_meows = 5): + for x in range(number_meows): self._meow() +``` + +## Model Links + +To add a link from the model list page in the admin interface to anywhere else, add this to the model definition: + +```python +class Cat + + @classmethod + @appier.link(name = "Export Cats (CSV)") + def export_csv(cls): + return appier.get_app().url_for("cat.list_csv") +``` + +In the same way, if the link is just for a particular instance, just use an instance method: + +```python + @appier.link(name = "Export Cat (CSV)") + def export_csv(self): + return self.get_app().url_for("cat.show_csv") +``` + +Links can receive parameters as well: + +```python + @classmethod + @appier.link( + name = "Export Cats (CSV)", + parameters = ( + ("Start record", "start_record", int), + ("Number of records", "number_records", int) + ) + ) + def export_csv(cls, start_record = 0, number_records = 10): + return appier.get_app().url_for( + "cat.list_csv", + start_record = start_record, + number_records = number_records + ) +``` \ No newline at end of file diff --git a/readme.md b/readme.md index d1faa2c9..ec6173d7 100644 --- a/readme.md +++ b/readme.md @@ -24,83 +24,10 @@ HelloApp().serve() After running the previous examples, go to [http://localhost:8080/admin](http://localhost:8080/admin) and login with root/root. -Models that inherit from ``appier_extras.admin.Base`` are automatically added to the admin interface. +## Learn more - -## Model Operations - -To add an operation accessible from the the admin interface be executed on a model, add this to the model definition: - -```python -class Cat: - - @classmethod - @appier.operation(name = "Meow") - def meow(cls): - cats = cls.find() - for cat in cats: cat._meow() -``` - -To make the same operation be associated with a single instance, just to apply to an instance method instead: - -```python - @appier.operation(name = "Meow") - def meow(self): - self._meow() -``` - -An operation can receive parameters that will be sent to the handler method: - -```python - @appier.operation( - name = "Meow", - parameters = ( - ("Number of meows", "number_meows", int), - ) - ) - def meow(self, number_meows = 5): - for x in range(number_meows): self._meow() -``` - -## Model Links - -To add a link from the model list page in the admin interface to anywhere else, add this to the model definition: - -```python -class Cat - - @classmethod - @appier.link(name = "Export Cats (CSV)") - def export_csv(cls): - return appier.get_app().url_for("cat.list_csv") -``` - -In the same way, if the link is just for a particular instance, just use an instance method: - -```python - @appier.link(name = "Export Cat (CSV)") - def export_csv(self): - return self.get_app().url_for("cat.show_csv") -``` - -Links can receive parameters as well: - -```python - @classmethod - @appier.link( - name = "Export Cats (CSV)", - parameters = ( - ("Start record", "start_record", int), - ("Number of records", "number_records", int) - ) - ) - def export_csv(cls, start_record = 0, number_records = 10): - return appier.get_app().url_for( - "cat.list_csv", - start_record = start_record, - number_records = number_records - ) -``` +### Basic +* [Models](doc/models.md) - admin interface for the app's models ## License From 702924fdfdffcf86d5aba4329c1398c258171483 Mon Sep 17 00:00:00 2001 From: Afonso Caldas Date: Mon, 18 Jan 2016 19:03:28 +0000 Subject: [PATCH 2/3] model attributes added to docs --- doc/models.md | 16 +++++++++++++++- readme.md | 2 -- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/models.md b/doc/models.md index 1360aafb..732b9a36 100644 --- a/doc/models.md +++ b/doc/models.md @@ -1,8 +1,21 @@ # Models Models that inherit from ``appier_extras.admin.Base`` are automatically added to the admin interface. + You can find more information about Appier models [here](http://appier.hive.pt/doc/models.md). +## Model Attributes + +The admin interface has support for the attribute types provided by Appier: +* A text field is presented for attributes of type ``str``, ``unicode``, ``int`` and ``float`` +* ``bool``attributes are set with a toggle switch. +* Attributes of type ``list`` or ``dict`` can be edited in JSON format. +* If the attribute is an ``appier.File`` object then a file upload input is shown. +* For an ``appier.reference`` attribute its text field has support for autocomplete. + +Attributes with the ``private`` keyword set to ``True`` are only shown in the model edit view. +Immutable attributes cannot be edited. + ## Model Operations To add an operation accessible from the the admin interface be executed on a model, add this to the model definition: @@ -76,4 +89,5 @@ Links can receive parameters as well: start_record = start_record, number_records = number_records ) -``` \ No newline at end of file +``` + diff --git a/readme.md b/readme.md index ec6173d7..7bf98a30 100644 --- a/readme.md +++ b/readme.md @@ -25,8 +25,6 @@ After running the previous examples, go to [http://localhost:8080/admin](http:// and login with root/root. ## Learn more - -### Basic * [Models](doc/models.md) - admin interface for the app's models ## License From 781fe1becdd48f51174472d20c1f47839675954a Mon Sep 17 00:00:00 2001 From: Afonso Caldas Date: Mon, 18 Jan 2016 19:10:34 +0000 Subject: [PATCH 3/3] documentation fix --- doc/models.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/models.md b/doc/models.md index 732b9a36..c04cd99d 100644 --- a/doc/models.md +++ b/doc/models.md @@ -7,14 +7,14 @@ You can find more information about Appier models [here](http://appier.hive.pt/d ## Model Attributes The admin interface has support for the attribute types provided by Appier: -* A text field is presented for attributes of type ``str``, ``unicode``, ``int`` and ``float`` +* A text field is used for attributes of type ``str``, ``unicode``, ``int`` and ``float`` * ``bool``attributes are set with a toggle switch. * Attributes of type ``list`` or ``dict`` can be edited in JSON format. -* If the attribute is an ``appier.File`` object then a file upload input is shown. -* For an ``appier.reference`` attribute its text field has support for autocomplete. +* A file upload input is shown for ``appier.File`` attributes. +* An ``appier.reference`` attribute has a text field with support for autocomplete. Attributes with the ``private`` keyword set to ``True`` are only shown in the model edit view. -Immutable attributes cannot be edited. +Immutable attributes can only be set at creation time. ## Model Operations