usage
Usage
To use django-unpoly in a project
| MIDDLEWARE = [
...
'django_unpoly.middleware.UpMiddleware',
...
]
|
The target is determined automatically if the model uses the UpModelIdMixin
and updated
if the successful form submission returns html containing up-id
. Form errors will update
the current open modal dialog.
Python
| from django_unpoly.up import UpViewMixin
from django.views.generic import UpdateView
class MyUnpolyModelView(UpModelViewMixin, UpdateView):
autosubmit = True
form_class = MyFormClass
template_name = 'django_unpoly/form.up.html'
model = MyModel
|
The X-Up-Target-Header can be set manually to change the HTML defined target.
| class MyUnpolyModelView(UpModelViewMixin, UpdateView):
def form_valid(self, form):
if xyz:
self.up_target = '#main'
|
HTML
| <div up-id="{{object.up_id}}">
<a up-layer="new" href="{% url 'myformurl' object.id %}">
MyModal
</a>
</div>
|
A redirect may be used to update the target on successful form submissions.
| <div up-id="{{object.up_id}}">
<a up-layer="new" href="{% url 'myformurl' object.id %}?redirect="currentpage">
MyModal
</a>
</div>
|
In your main layout include the following js-file.
| <script src="{% static 'django_unpoly/up_djdt.js' %}"></script>
|
django-concurrency
The current version of the model has to be added to the unpoly form url. Before the form is rendered the
version will be checked for changes. The version
field should also be added to the form to prevent
concurrent changes to the model.
| <a up-modal="new" href="{% url 'myurl' model.id %}?version={{ model.version }}">
MyModal
</a>
|
| from django_unpoly.up import UpModelViewMixin, UpDjangoConcurrencyMixin
from django.views.generic import UpdateView
class MyUnpolyModelView(UpDjangoConcurrencyMixin, UpModelViewMixin, UpdateView):
autosubmit = True
form_class = MyFormClass
template_name = 'django_unpoly/form.unpoly.html'
model = MyModel
|