Paul
unread,May 7, 2012, 2:32:57 PM5/7/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I have a sort of solution (but don't like it). I subclassed the crispy-
tag to change the input's into span's/uneditable's. This is done using
re's which is the part i don't like, it will only work as long as the
raw html is compatible with the re's....
I know a better solution is to create custom templates for the field
for example but i'm missing complete and working examples to do that;
anyone advise?
Paul
class CrispyUneditable(UniFormNode):
'''subclass the crispy tag to modify the tags output: each input
field shall be uneditable using bootstraps uneditable styling'''
def render(self, context):
import re
value = super(CrispyUneditable, self).render(context)
return re.sub(
r'<input (.*?) value="([^"]*?)" class="([^"]*)" (.*?)>',
r'<span class="\3 uneditable-input">\2</span>', value)
# {% crispy-uneditable %} tag
@register.tag(name="crispy-uneditable")
def do_crispy_uneditable_form(parser, token):
token = token.split_contents()
form = token.pop(1)
try:
helper = token.pop(1)
except IndexError:
helper = None
return CrispyUneditable(form, helper)