Skip to content

Commit

Permalink
detail view for inline formset
Browse files Browse the repository at this point in the history
  • Loading branch information
asifpy committed Apr 10, 2016
1 parent 0b19016 commit 05b9d18
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 15 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include LICENSE.txt
include README.md
recursive-include crudbuilder/templates *
recursive-include crudbuilder/static *
recursive-include crudbuilder/templatetags *
recursive-include docs *
7 changes: 7 additions & 0 deletions crudbuilder/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def get_actual_signal(self):
return signals['instance'][view]


class BaseDetailViewMixin(CrudBuilderMixin):
def get_context_data(self, **kwargs):
context = super(BaseDetailViewMixin, self).get_context_data(**kwargs)
context['inlineformset'] = self.inlineformset
return context


class CreateUpdateViewMixin(CrudBuilderMixin):
"""Common form_valid() method for both Create and Update views"""

Expand Down
29 changes: 29 additions & 0 deletions crudbuilder/templates/inline/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,34 @@ <h3>{{object}}</h3>
{% endfor %}
</tbody>
</table>

<hr/>

<h3>{{inlineformset.fk.related_query_name|title}}</h3>

<table class="table table-bordered">
<thead>
<tr>
{% for field in inlineformset.form.base_fields.keys %}
{% if inlineformset.fk.name != field %}
<th>{{field}}</th>
{% endif %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for object in object|inline_objects:inlineformset.fk %}
<tr>
{% for field in inlineformset.form.base_fields.keys %}
{% if inlineformset.fk.name != field %}
<td>{{object|get_value:field}}</td>
{% endif %}
{% endfor %}
<tr>
{% endfor %}
</tbody>
</table>


</div>
{% endblock %}
2 changes: 1 addition & 1 deletion crudbuilder/templates/instance/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ <h3>{{object}}</h3>
{% endfor %}
</tbody>
</table>
</div>s
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions crudbuilder/templatetags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def input_with_class(value, arg):
return value


@register.filter(is_safe=True)
def inline_objects(object, inline_fk):
inline_model = inline_fk.model
related_filter = inline_fk.get_forward_related_filter(object)
return inline_model.objects.filter(**related_filter)


@register.inclusion_tag('widgets/tables/pagination.html')
def bootstrap_pagination(page, **kwargs):
pagination_kwargs = kwargs.copy()
Expand Down
6 changes: 4 additions & 2 deletions crudbuilder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
CrudBuilderMixin,
BaseListViewMixin,
CreateUpdateViewMixin,
InlineFormsetViewMixin
InlineFormsetViewMixin,
BaseDetailViewMixin
)
from crudbuilder.abstract import BaseBuilder
from crudbuilder.tables import TableBuilder
Expand Down Expand Up @@ -134,10 +135,11 @@ def generate_detail_view(self):
template_name=self.get_template('detail'),
login_required=self.check_login_required,
permissions=self.view_permission('detail'),
inlineformset=self.inlineformset,
permission_required=self.check_permission_required,
)

detail_class = type(name, (CrudBuilderMixin, DetailView), detail_args)
detail_class = type(name, (BaseDetailViewMixin, DetailView), detail_args)
self.classes[name] = detail_class
return detail_class

Expand Down
40 changes: 29 additions & 11 deletions docs/source/templates.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Templates
=========

By default django-crudbuilder uses its own plain html CRUD templates. You can view these templates in `template folder of crudbuilder`_ on Github.
By default django-crudbuilder uses Bootstrap3 style for its CRUD templates. You can view these templates in `template folder of crudbuilder`_ on Github.


Use your own HTML templates for crudbuilder
Expand All @@ -10,16 +10,34 @@ Use your own HTML templates for crudbuilder
You can use your own templates for the crudbuilder in following two ways:

5 common templates for all models CRUD
########################################

You can create your own 5 common HTML templates for CRUD in templates/crudbuilder, then crudbuilder will use your defined templates.::
templates/crudbuilder
object_list.html
object_create.html
object_update.html
object_delete.html
object_detail.html
--------------------------------------

You can create your own 5 common HTML templates for CRUD in templates/crudbuilder, then crudbuilder will use your defined templates.


Model
#####

For single object crud.::

templates/crudbuilder/instance
list.html
create.html
update.html
delete.html
detail.html

Inline Formset
##############

For inline formset.::

templates/crudbuilder/inline
list.html
create.html
update.html
delete.html
detail.html


Custom templates for specific model:
Expand Down
2 changes: 1 addition & 1 deletion example/example/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ class PersonEmployment(Audit):
Person,
blank=True,
null=True,
related_name='employments')
)
medical_allowance = models.BooleanField(default=False)

0 comments on commit 05b9d18

Please sign in to comment.