Skip to content

Commit

Permalink
Merge pull request #74 from WHOIGit/develop
Browse files Browse the repository at this point in the history
Bug fixes for v1.3.0, update to v1.3.1
  • Loading branch information
ethanandrews authored May 18, 2020
2 parents 33ade27 + f6e0dc5 commit 4f3acc8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
15 changes: 8 additions & 7 deletions roundabout/inventory/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ def __init__(self, *args, **kwargs):
options_dict = field.choice_field_options
options_list = [('', '- select one -')]

for option in options_dict['options']:
value = option['value']
label = value
if option['label']:
label = option['label']
form_option = (value, label)
options_list.append(form_option)
if options_dict:
for option in options_dict['options']:
value = option['value']
label = value
if option['label']:
label = option['label']
form_option = (value, label)
options_list.append(form_option)

FIELD_CHOICES = (options_list)
self.fields['udffield_' + str(field.id)] = forms.ChoiceField(label=str(field.field_name), required=False,
Expand Down
22 changes: 22 additions & 0 deletions roundabout/userdefinedfields/migrations/0005_auto_20200517_1814.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.2.10 on 2020-05-17 18:14

from django.apps import apps
from django.db import migrations

FieldValue = apps.get_model('userdefinedfields', 'FieldValue')

def remove_nulls(apps, schema_editor):
for fv in FieldValue.objects.all():
if fv.field_value is None:
fv.field_value = ''
fv.save()

class Migration(migrations.Migration):

dependencies = [
('userdefinedfields', '0004_auto_20200421_0056'),
]

operations = [
migrations.RunPython(remove_nulls),
]
18 changes: 18 additions & 0 deletions roundabout/userdefinedfields/migrations/0006_auto_20200517_1822.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-05-17 18:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userdefinedfields', '0005_auto_20200517_1814'),
]

operations = [
migrations.AlterField(
model_name='fieldvalue',
name='field_value',
field=models.TextField(blank=True),
),
]
15 changes: 9 additions & 6 deletions roundabout/userdefinedfields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __str__(self):


class FieldValue(models.Model):
field_value = models.TextField(null=True, blank=True)
field_value = models.TextField(null=False, blank=True)
field = models.ForeignKey(Field, related_name='fieldvalues',
on_delete=models.CASCADE, null=False, blank=False)
inventory = models.ForeignKey('inventory.Inventory', related_name='fieldvalues',
Expand Down Expand Up @@ -82,11 +82,14 @@ def get_field_value(self):

# Check if field is ChoiceField, set the value to the label if available
if self.field.field_type == 'ChoiceField':
options_list= self.field.choice_field_options['options']
try:
options_list= self.field.choice_field_options['options']

for option in options_list:
if option['value'] == self.field_value and option['label']:
print(option['label'])
return option['label']
for option in options_list:
if option['value'] == self.field_value and option['label']:
print(option['label'])
return option['label']
except:
pass

return self.field_value

0 comments on commit 4f3acc8

Please sign in to comment.