Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Geoffroy committed Jun 27, 2014
1 parent 35e113e commit a3d6eeb
Showing 1 changed file with 1 addition and 48 deletions.
49 changes: 1 addition & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
django-crucrudile [![Build Status](https://travis-ci.org/pstch/django-crucrudile.svg?branch=crucrudile)](https://travis-ci.org/pstch/django-crucrudile) [![Coverage Status](https://coveralls.io/repos/pstch/django-crucrudile/badge.png?branch=crucrudile)](https://coveralls.io/r/pstch/django-crucrudile?branch=crucrudile)
=================

`django-crucrudile` allows you to create "model mixins", that define possible actions for this model. Those model mixins allow the model to be able to generate its URL patterns by itself, so that they can be included in `urls.py` using just a call to the `get_url_patterns()` method of the model class.

**WARNING :** This project is still a WIP. The implementation of the concept is stable, and I already use it in my own projects, but it will still take some times before I can release a proper version (somewhen in April 2014).

**NOTE :** Development is done on the `develop` branch, and when needed, merged into the `master` branch, which is more stable. **Code on the `develop` branch may not work at all !** (Which doesn't mean that the code on the `master` branch will work..)
Expand All @@ -13,47 +11,7 @@ The documentation, available at [django-crucrudile.readthedocs.org](http://djang

## Example

Here, we create two **model mixins** : `Listable` and `Detailable`, and we set the url_args attribute of DetailView so that django-crucrudile knows that the URL should contain a named capture group for the ID of the object to view.

Then, we create a Django Model, in which we use `Listable` and `Detailable` as mixins.


```python
from django.db.models import Model
from django.generic.views import ListView, DetailView
from django_crucrudile.models.mixins import make_model_mixin

DetailView.url_args = ['(?P<pk>\d+)',]

Listable = make_model_mixin(ListView)
Detailable = make_model_mixin(DetailView)

class Book(Listable, Detailable, Model):
pass

>> Book.get_views()
[ListView, DetailView]

>> Book.get_url_name(ListView)
'book-list'

>> Book.get_list_url()
'/book/list'

>> Book.get_url_patterns()
[<RegexURLPattern book-list book/list>,
<RegexURLPattern book-detail book/detail/<pk>>]
```

The return value of `get_url_patterns()` can be used in `urls.py` (for example, in `patterns('', ..)`).

Here, `ListView` and `DetailView` can be standard generic views, or your own CBVs. As you can see, the only requirement is that, when a view needs an URL argument, it must be specified in the `url_args` attribute of the view class.

`make_model_mixin` automatically patches the given view with utility functions from `views.mixins.ModelActionMixin`, needed to have information about "what does the view do" (action name), and "what paths should point to it" (URLs specification). For more flexibility, it can be better to redefine the views, to subclass `views.mixins.ModelActionMixin`, and to override the needed methods (see documentation).

It is also possible to create the model mixins by yourself (`make_model_mixin` is just a convenience function to automatically create model mixins based on a view) (see documentation).

`django-crucrudile` also provides a convenience function, `auto_patterns_for_app`, that can generate the URL patterns for each Model in an application (using `ContentType` to find the models), and that can be used directly in `urls.py`.
TODO

## Tests

Expand All @@ -66,8 +24,3 @@ This is my first attempt at creating a (hopefully) useful Django application. If
## Contributing

If you feel like you want to contribute to this project, please fork/send patches/submit pull requests ! The documentation and tests really need some improvement. This was my first time writing serious test cases, and my testing code is particularly ugly :(

`django-crucrudile` only consists of 4 files, with 2 of them being just utility functions (`utils.py` and `urls.py`). The two other files are what really makes it working :

* `models/mixins.py` :: Model mixins (one base class) and on-the-run mixin creator (function)
* `views/mixins.py` :: View mixins (one base class)

0 comments on commit a3d6eeb

Please sign in to comment.