Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

feat(kernel): add active to project stats view #770

Merged
merged 2 commits into from
Jan 16, 2020
Merged
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
2 changes: 1 addition & 1 deletion aether-kernel/aether/kernel/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class ProjectStatsSerializer(DynamicFieldsMixin, DynamicFieldsModelSerializer):
class Meta:
model = models.Project
fields = (
'id', 'name', 'created',
'id', 'name', 'created', 'active',
'first_submission', 'last_submission',
'submissions_count', 'attachments_count', 'entities_count',
)
Expand Down
18 changes: 15 additions & 3 deletions aether-kernel/aether/kernel/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,24 @@ def test_project_stats_view_fields(self):

response = self.client.get(
url,
{'omit': 'first_submission,last_submission,submissions_count,entities_count'}
{'omit': 'created,first_submission,last_submission,submissions_count,entities_count'}
)
data = response.json()
self.assertIn('id', data)
self.assertIn('name', data)
self.assertIn('active', data)
self.assertNotIn('created', data)
self.assertNotIn('first_submission', data)
self.assertNotIn('last_submission', data)
self.assertNotIn('submissions_count', data)
self.assertNotIn('entities_count', data)

response = self.client.get(url, {'fields': 'entities_count'})
data = response.json()
self.assertNotIn('id', data)
self.assertNotIn('name', data)
self.assertNotIn('active', data)
self.assertNotIn('created', data)
self.assertNotIn('first_submission', data)
self.assertNotIn('last_submission', data)
self.assertNotIn('submissions_count', data)
Expand All @@ -264,10 +272,14 @@ def test_project_stats_view_fields(self):
response = self.client.get(
url,
{
'fields': 'entities_count,submissions_count',
'omit': 'submissions_count'
'fields': 'id,entities_count,submissions_count',
'omit': 'id,active,submissions_count'
})
data = response.json()
self.assertNotIn('id', data)
self.assertNotIn('name', data)
self.assertNotIn('active', data)
self.assertNotIn('created', data)
self.assertNotIn('first_submission', data)
self.assertNotIn('last_submission', data)
self.assertNotIn('submissions_count', data)
Expand Down
4 changes: 3 additions & 1 deletion aether-kernel/aether/kernel/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ class SubmissionStatsMixin(MtViewSetMixin):

submissions_field = 'submissions'
entities_fk = 'submission__mappingset'
fields_list = ('id', 'name', 'created',)

def get_queryset(self):
def _get_list_param(name):
Expand All @@ -690,7 +691,7 @@ def _is_included(field_name):
)

qs = super(SubmissionStatsMixin, self).get_queryset()
qs = qs.values('id', 'name', 'created')
qs = qs.values(*self.fields_list)

_fields = _get_list_param('fields')
_omit = _get_list_param('omit')
Expand Down Expand Up @@ -770,6 +771,7 @@ class ProjectStatsViewSet(SubmissionStatsMixin, viewsets.ReadOnlyModelViewSet):
serializer_class = serializers.ProjectStatsSerializer
filter_class = filters.ProjectFilter
entities_fk = 'project'
fields_list = ('id', 'name', 'created', 'active',)


class MappingSetStatsViewSet(SubmissionStatsMixin, viewsets.ReadOnlyModelViewSet):
Expand Down