forked from extern/django-helpdesk
Allow selection of all items on custom "list" fields. Fixes GH-23.
This commit is contained in:
parent
c9e68a05a7
commit
b42026ec33
@ -8,6 +8,7 @@ forms.py - Definitions of newforms-based forms for creating and maintaining
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from StringIO import StringIO
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
@ -119,10 +120,7 @@ class TicketForm(forms.Form):
|
||||
instanceargs['max_digits'] = field.max_length
|
||||
elif field.data_type == 'list':
|
||||
fieldclass = forms.ChoiceField
|
||||
choices = []
|
||||
for line in field.list_values.split("\n"):
|
||||
choices.append((line, line))
|
||||
instanceargs['choices'] = choices
|
||||
instanceargs['choices'] = field.choices_as_array
|
||||
elif field.data_type == 'boolean':
|
||||
fieldclass = forms.BooleanField
|
||||
elif field.data_type == 'date':
|
||||
|
@ -1169,6 +1169,14 @@ class CustomField(models.Model):
|
||||
null=True,
|
||||
)
|
||||
|
||||
def _choices_as_array(self):
|
||||
from StringIO import StringIO
|
||||
valuebuffer = StringIO(self.list_values)
|
||||
choices = [[item.strip(), item.strip()] for item in valuebuffer.readlines()]
|
||||
valuebuffer.close()
|
||||
return choices
|
||||
choices_as_array = property(_choices_as_array)
|
||||
|
||||
required = models.BooleanField(
|
||||
_('Required?'),
|
||||
help_text=_('Does the user have to enter a value for this field?'),
|
||||
|
Loading…
Reference in New Issue
Block a user