Skip to content

Commit

Permalink
bump v0.2.0-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Nov 28, 2015
1 parent 1bb8031 commit a07c8fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-----

* New: Proper docs
* Improvement: `FormHook.save()` returns a list of (form, save_result) instead of just the results
* Improvement: `FormHook.save()` returns a list of (form, result) instead of just the results

0.1.4
-----
Expand Down
39 changes: 19 additions & 20 deletions docs/formhook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ Adding a hook-point to the main app view::
# Example 1
def my_view(request):
if request.method == 'POST':
myform = MyForm(data=request.POST)
hook = formhooks.MyFormHook(data=request.POST)
form_hook = formhooks.MyFormHook(data=request.POST)

if all([myform.is_valid(), hook.is_valid()]): # Avoid short-circuit
myform.save()
hook.save()
if form_hook.is_valid():
form_hook.save()
redirect('/')
else:
myform = MyForm()
hook = formhooks.MyFormHook()
form_hook = formhooks.MyFormHook()

return response({'myform': myform, 'hook_form': hook}) #...
return response('my_view.html', {'form_hook': form_hook})


# Example 2
Expand All @@ -42,17 +39,17 @@ Adding a hook-point to the main app view::
# Hook listeners will receive the user and populate the
# initial data (or instance if a ModelForm is used) accordingly,
# or maybe even query the data base.
hook = formhooks.UserFormHook(user=request.user, data=request.POST)
user_form_hook = formhooks.UserFormHook(user=request.user, data=request.POST)

if all([user_form.is_valid(), hook.is_valid()]): # Avoid short-circuit
if all([user_form.is_valid(), user_form_hook.is_valid()]): # Avoid short-circuit
new_user = user_form.save()
hook.save(new_user=new_user) # They may receive extra parameter when saving
user_form_hook.save(new_user=new_user) # They may receive extra parameter when saving
redirect('/')
else:
user_form = MyForm(instance=request.user)
hook = formhooks.UserFormHook(user=request.user)
user_form_hook = formhooks.UserFormHook(user=request.user)

return response({'user_form': user_form, 'hook_form': hook}) #...
return response('user_profile_update.html', {'user_form': user_form, 'user_form_hook': user_form_hook})

Displaying the forms::

Expand All @@ -67,9 +64,8 @@ Displaying the forms::

<form action="." method="post">
{% csrf_token %}
{{ myform }}

{% for f in hook_form %}
{% for f in form_hook %}
{{ f }}
{% endfor %}

Expand All @@ -89,6 +85,13 @@ Creating a hook-listener in a third-party app:
from third_party_app.models import MyUserExtension


# Example 1
class MyRegularForm(forms.Form):
""""""
# ...


# Example 2
class MyUserExtensionForm(forms.ModelForm):

class Meta:
Expand All @@ -108,18 +111,14 @@ Creating a hook-listener in a third-party app:
self.instance.user = new_user
super(MyUserExtensionForm, self).save(*args, **kwargs)


class MyRegularForm(forms.Form):
""""""
# ...

Registering a hook-listener::

# third_party_app/apps.py

from django.apps import AppConfig


# Example
class MyAppConfig(AppConfig):

name = 'myapp'
Expand Down
2 changes: 1 addition & 1 deletion hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.4"
__version__ = "0.2.0-pre"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='django-hooks',
version='0.1.4',
version='0.2.0-pre',
description='A plugin system for django.',
author='Esteban Castro Borsani',
author_email='ecastroborsani@gmail.com',
Expand Down

0 comments on commit a07c8fe

Please sign in to comment.