diff --git a/project/boh_api/serializers.py b/project/boh_api/serializers.py index c8ddd7b8..b2c90ecf 100644 --- a/project/boh_api/serializers.py +++ b/project/boh_api/serializers.py @@ -9,18 +9,49 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() - fields = ('id', 'username', 'first_name', 'last_name', 'email', 'is_active', 'last_login') + fields = ['id', 'username', 'first_name', 'last_name', 'email', 'is_active', 'last_login'] read_only_fields = fields class TagSerializer(serializers.ModelSerializer): class Meta: model = models.Tag + fields = ['id', 'name', 'color', 'description'] + + +class PersonSerializer(serializers.ModelSerializer): + class Meta: + model = models.Person + fields = ['id', 'first_name', 'last_name', 'email', 'role', 'phone_work', 'phone_mobile', 'job_title'] class OrganizationSerializer(serializers.ModelSerializer): + people = PersonSerializer(many = True, read_only = True) + class Meta: model = models.Organization + fields = ['id', 'name', 'description', 'people'] + + +class ActivityTypeSerializer(serializers.ModelSerializer): + class Meta: + model = models.ActivityType + fields = ['id', 'name', 'documentation'] + + +class ActivitySerializer(serializers.ModelSerializer): + activity_type = ActivityTypeSerializer(read_only = True) + users = UserSerializer(many = True, read_only = True) + + class Meta: + model = models.Activity + fields = ['id', 'status', 'description', 'open_date', 'close_date', 'duration', 'activity_type', 'engagement', 'users'] + + +class DataElementSerializer(serializers.ModelSerializer): + class Meta: + model = models.DataElement + fields = ['id', 'name', 'description'] class ApplicationSerializer(serializers.ModelSerializer): @@ -35,13 +66,15 @@ def get_key(self, custom_field_value): return custom_field_value.custom_field.key threadfix_metrics = serializers.SerializerMethodField() - organization = OrganizationSerializer(read_only=True) - tags = TagSerializer(many=True, read_only=True) - custom_fields = ApplicationCustomFieldValueSerializer(source='applicationcustomfieldvalue_set', many=True, read_only=True) + organization = OrganizationSerializer(read_only = True) + tags = TagSerializer(many = True, read_only = True) + data_elements = DataElementSerializer(many = True, read_only = True) + custom_fields = ApplicationCustomFieldValueSerializer(source='applicationcustomfieldvalue_set', many = True, read_only = True) + people = PersonSerializer(many = True, read_only = True) class Meta: model = models.Application - fields = ['id', 'organization', 'name', 'description', 'business_criticality', 'platform', 'lifecycle', 'origin', 'user_records', 'revenue', 'external_audience', 'internet_accessible', 'threadfix_metrics', 'tags', 'custom_fields', 'people'] + fields = ['id', 'organization', 'name', 'description', 'business_criticality', 'platform', 'lifecycle', 'origin', 'user_records', 'revenue', 'external_audience', 'internet_accessible', 'threadfix_metrics', 'tags', 'data_elements', 'custom_fields', 'people'] def get_threadfix_metrics(self, application): try: @@ -59,21 +92,11 @@ def get_threadfix_metrics(self, application): return None -class PersonSerializer(serializers.ModelSerializer): - class Meta: - model = models.Person - - -class ActivitySerializer(serializers.ModelSerializer): - class Meta: - model = models.Activity - - class EngagementSerializer(serializers.ModelSerializer): + requestor = PersonSerializer(read_only = True) + class Meta: model = models.Engagement + fields = ['id', 'status', 'start_date', 'end_date', 'description', 'open_date', 'close_date', 'duration', 'requestor', 'application'] -class ActivityTypeSerializer(serializers.ModelSerializer): - class Meta: - model = models.ActivityType diff --git a/project/project/settings/base.py b/project/project/settings/base.py index 7ae60a0f..377bc97c 100644 --- a/project/project/settings/base.py +++ b/project/project/settings/base.py @@ -113,9 +113,7 @@ 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.TokenAuthentication', ), - 'DEFAULT_FILTER_BACKENDS': ( - 'rest_framework.filters.DjangoFilterBackend', - ), + 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), @@ -123,5 +121,6 @@ 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ), + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'PAGE_SIZE': 25, } diff --git a/requirements/base.txt b/requirements/base.txt index 12a3d971..1f69613d 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,9 +1,9 @@ Django==1.11.22 django-formtools==1.0 -djangorestframework==3.4.7 -django-filter==1.1.0 +djangorestframework==3.10.1 +django-filter==2.2.0 django-widget-tweaks==1.4.1 -Markdown==2.6.11 +Markdown==3.1.1 phonenumbers==8.9.10 Pygments==2.2.0 pytz==2018.5