Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new documentation structure #7

Merged
merged 3 commits into from Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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