funkybob / django-sniplates

Template snippet libraries for Django
MIT License
57 stars 18 forks source link

Value of None in formfield incorrect #19

Closed sergei-maertens closed 9 years ago

sergei-maertens commented 9 years ago

There's an error in the value checking for form_field. Value is a callable and needs to be called. I'll provide a test and PR with fix later this week.

I'm on mobile now, sorry for the short report - merely a heads up and reminder for me.

funkybob commented 9 years ago

Please see if PR20 fixes this.

sergei-maertens commented 9 years ago

It doesn't, I'll poke around a bit

Traceback:

Environment:

Request Method: GET
Request URL: http://localhost:8000/brouwersdag/sign-up/

Django Version: 1.8.2
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'admin_tools',
 'admin_tools.theming',
 'admin_tools.menu',
 'admin_tools.dashboard',
 'django.contrib.admin',
 'compressor',
 'sniplates',
 'sessionprofile',
 'rest_framework',
 'django_extensions',
 'rosetta',
 'precise_bbcode',
 'brouwers.users',
 'brouwers.albums',
 'brouwers.awards',
 'brouwers.banning',
 'brouwers.builds',
 'brouwers.brouwersdag',
 'brouwers.forum_tools',
 'brouwers.general',
 'brouwers.groupbuilds',
 'brouwers.kitreviews',
 'brouwers.migration',
 'brouwers.online_users',
 'brouwers.secret_santa',
 'brouwers.shirts',
 'brouwers.utils')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'sessionprofile.middleware.SessionProfileMiddleware',
 'brouwers.albums.middleware.UploadifyMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'brouwers.banning.middleware.BanningMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Template error:
In template /home/bbt/coding/modelbrouwers/brouwers/src/brouwers/brouwersdag/templates/brouwersdag/model_signup.html, error at line 25
   value

   15 :                 {% trans "If you want to display multiple models, just fill in the form again for each extra model." %}

   16 :             </p>

   17 : 

   18 :             {% load_widgets form='horizontal.form' %}

   19 :             <form action="." method="post" class="form-horizontal" role="form">

   20 :                 {% csrf_token %}

   21 : 

   22 :                 {% widget 'form:non_field_errors' %}

   23 : 

   24 :                 {% for field in form %}

   25 :                      {% form_field field placeholder=field.label label_grid='col-sm-3' field_grid='col-sm-8' %} 

   26 :                 {% endfor %}

   27 :                 <div class="form-group">

   28 :                     <div class="col-sm-offset-3 col-sm-9">

   29 :                         <button type="submit" class="btn btn-primary">{% block submit_button %}{% trans "Add model" %}{% endblock %}</button>

   30 :                     </div>

   31 :                 </div>

   32 :             </form>

   33 :         </div>

   34 : 

   35 :         <div class="col-sm-4">

Traceback:
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  164.                 response = response.render()
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/response.py" in render
  158.             self.content = self.rendered_content
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  135.         content = template.render(context, self._request)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/backends/django.py" in render
  74.         return self.template.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  209.                     return self._render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  217.                             nodelist.append(node.render(context))
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django/template/base.py" in render
  1195.                     return func(*resolved_args, **resolved_kwargs)
File "/home/bbt/coding/.virtualenvs/brouwers-1.8/lib/python2.7/site-packages/django_sniplates-0.3.0-py2.7.egg/sniplates/templatetags/sniplates.py" in form_field
  317.         value = force_text(field_data['value']())

Exception Type: KeyError at /brouwersdag/sign-up/
Exception Value: 'value'
sergei-maertens commented 9 years ago

Follow up, I just wrote a test and your code seems to be allright, the key error might be on my end.

funkybob commented 9 years ago

Is this still an issue, or can I close it [and the PR] now?

sergei-maertens commented 9 years ago

I think the only relevant bit is the PR itself, the issue was on my end I think. Iirc the PR just extends the test suite a bit more with an edge case.