Skip to content

Commit

Permalink
fix to support crispy_forms field render new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zts0813 committed Apr 4, 2016
1 parent bf511e5 commit dfd454f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions xadmin/plugins/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.template import loader
from django.template.loader import render_to_string
from django.contrib.auth import get_permission_codename
from crispy_forms.utils import TEMPLATE_PACK

from xadmin.layout import FormHelper, Layout, flatatt, Container, Column, Field, Fieldset
from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, ModelFormAdminView, DetailAdminView, filter_hook
Expand All @@ -21,7 +23,7 @@ def __init__(self, admin_view, *args, **kwargs):
if admin_view.style == 'table':
self.template = "xadmin/layout/field_value_td.html"

def render(self, form, form_style, context):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
html = ''
detail = form.detail
for field in self.fields:
Expand All @@ -34,10 +36,10 @@ def render(self, form, form_style, context):

class DeleteField(Field):

def render(self, form, form_style, context):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
if form.instance.pk:
self.attrs['type'] = 'hidden'
return super(DeleteField, self).render(form, form_style, context)
return super(DeleteField, self).render(form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs)
else:
return ""

Expand Down Expand Up @@ -329,10 +331,9 @@ def __init__(self, formset, allow_blank=False, **kwargs):
self.flat_attrs = flatatt(kwargs)
self.extra_attrs = formset.style.get_attrs()

def render(self, form, form_style, context):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
return render_to_string(
self.template, dict({'formset': self, 'prefix': self.formset.prefix, 'inline_style': self.inline_style}, **self.extra_attrs),
context=context)
self.template, dict({'formset': self, 'prefix': self.formset.prefix, 'inline_style': self.inline_style}, **self.extra_attrs))


class Inline(Fieldset):
Expand All @@ -342,7 +343,7 @@ def __init__(self, rel_model):
self.fields = []
super(Inline,self).__init__(legend="")

def render(self, form, form_style, context):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
return ""


Expand Down

0 comments on commit dfd454f

Please sign in to comment.