Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choices frontend #252

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions report_builder/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Meta:
model = FilterField
fields = ('id', 'path', 'path_verbose', 'field', 'field_verbose',
'field_type', 'filter_type', 'filter_value', 'filter_value2',
'exclude', 'position', 'report')
read_only_fields = ('id', 'field_type')
'exclude', 'position', 'report', 'choices')
read_only_fields = ('id', 'field_type', 'choices')


class UserSerializer(serializers.ModelSerializer):
Expand Down
6 changes: 3 additions & 3 deletions report_builder/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def post(self, request):
'field_type': new_field.get_internal_type(),
'is_default': True if defaults is None or
new_field.name in defaults else False,
'field_choices': new_field.choices,
'choices': list(new_field.choices),
'can_filter': True if filters is None or
new_field.name in filters else False,
'path': field_data['path'],
Expand All @@ -214,7 +214,7 @@ def post(self, request):
'field': field,
'field_verbose': field,
'field_type': 'Property',
'field_choices': None,
'choices': None,
'can_filter': True if filters is None or
field in filters else False,
'path': field_data['path'],
Expand All @@ -234,7 +234,7 @@ def post(self, request):
'field': field.name,
'field_verbose': field.name,
'field_type': 'Custom Field',
'field_choices': getattr(field, 'choices', None),
'choices': getattr(field, 'choices', None),
'can_filter': True if filters is None or
field.name in filters else False,
'path': field_data['path'],
Expand Down
2 changes: 1 addition & 1 deletion report_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def get_choices(self, model, field_name):
except:
model_field = None
if model_field and model_field.choices:
return model_field.choices
return list(model_field.choices)

def filter_property(self, value):
""" Determine if passed value should be filtered or not """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<div ng-switch-when="BooleanField">
<md-checkbox ng-model="field.filter_value">
</div>
<input ng-switch-default type="text" ng-model="field.filter_value"></input>
<input ng-if="!field.choices" ng-switch-default type="text" ng-model="field.filter_value"></input>
<select ng-if="!!field.choices" ng-model="field.filter_value" ng-options="choice[0] as choice[1] for choice in field.choices"></select>
<div ng-if="field.filter_type == 'range'" flex="" ng-switch="field.field_type">
<input ng-switch-when="DateField" pikaday="pikaday" format="YYYY-MM-DD" ng-model="field.filter_value2"></input>
<input ng-switch-default type="text" ng-model="field.filter_value2"></input>
Expand Down
2 changes: 1 addition & 1 deletion report_builder/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_report_builder_choices(self):
'/report_builder/api/fields/',
{"model": ct.id, "path": "", "path_verbose": "", "field": ""})
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'field_choices')
self.assertContains(response, 'choices')
self.assertContains(response, '[["CH","CHECK"],["MA","CHECKMATE"]]')

def test_report_builder_can_filter(self):
Expand Down
19 changes: 19 additions & 0 deletions report_builder_demo/demo_models/migrations/0010_bar_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('demo_models', '0009_auto_20151209_2136'),
]

operations = [
migrations.AddField(
model_name='bar',
name='status',
field=models.PositiveIntegerField(default=0, choices=[(0, b'Pending'), (1, b'Approved'), (2, b'Rejected')]),
),
]
8 changes: 8 additions & 0 deletions report_builder_demo/demo_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils.functional import cached_property

from djmoney.models.fields import MoneyField
from model_utils import Choices


class Foo(models.Model):
Expand All @@ -28,13 +29,20 @@ class Bar(models.Model):
(CHECK, 'CHECK'),
(MATE, 'CHECKMATE'),
)
STATUS_CHOICES = Choices(
(0, "Pending"),
(1, "Approved"),
(2, "Rejected"),
)

check_mate_status = models.CharField(
max_length=2,
choices=CHESS_CHOICES,
default=CHECK
)

status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=0)

@property
def i_want_char_field(self):
return 'lol no'
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ celery[redis]
flake8
django-money==0.9.1
djangorestframework==3.4.3
python-dateutil==2.6.0
openpyxl==2.4.1
django-model-utils==2.6