Skip to content

Commit

Permalink
Merge pull request #7 from hivesolutions/dev_acaldas
Browse files Browse the repository at this point in the history
new documentation structure
  • Loading branch information
tsilva committed Jan 19, 2016
2 parents 7158e26 + 781fe1b commit 7e12714
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 77 deletions.
93 changes: 93 additions & 0 deletions doc/models.md
@@ -0,0 +1,93 @@
# 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 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.
* 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`` <em>keyword</em> set to ``True`` are only shown in the model edit view.
Immutable attributes can only be set at creation time.

## 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
)
```

79 changes: 2 additions & 77 deletions readme.md
Expand Up @@ -24,83 +24,8 @@ 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.


## 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
)
```
## Learn more
* [Models](doc/models.md) - admin interface for the app's models

## License

Expand Down

0 comments on commit 7e12714

Please sign in to comment.