Browse Source

Fix files according to flake8

pull/1349/head
Hironsan 4 years ago
parent
commit
dbb4f63036
7 changed files with 9 additions and 11 deletions
  1. 8
      backend/api/filters.py
  2. 5
      backend/api/serializers.py
  3. 1
      backend/api/views/role.py
  4. 2
      backend/api/views/statistics.py
  5. 1
      backend/api/views/upload/__init__.py
  6. 2
      backend/api/views/upload/examples.py
  7. 1
      backend/api/views/user.py

8
backend/api/filters.py

@ -11,9 +11,11 @@ class DocumentFilter(FilterSet):
speech2text_annotations__isnull = BooleanFilter(field_name='speech2text_annotations', method='filter_annotations')
def filter_annotations(self, queryset, field_name, value):
queryset = queryset.annotate(num_annotations=
Count(field_name, filter=
Q(**{ f"{field_name}__user": self.request.user}) | Q(project__collaborative_annotation=True)))
queryset = queryset.annotate(num_annotations=Count(
expression=field_name,
filter=Q(**{f"{field_name}__user": self.request.user}) | Q(project__collaborative_annotation=True)
)
)
should_have_annotations = not value
if should_have_annotations:

5
backend/api/serializers.py

@ -132,7 +132,8 @@ class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type',
'updated_at', 'randomize_document_order', 'collaborative_annotation', 'single_class_classification', 'tags')
'updated_at', 'randomize_document_order', 'collaborative_annotation', 'single_class_classification',
'tags')
read_only_fields = ('updated_at', 'users', 'current_users_role', 'tags')
@ -191,7 +192,6 @@ class ProjectFilteredPrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField):
class DocumentAnnotationSerializer(serializers.ModelSerializer):
# label = ProjectFilteredPrimaryKeyRelatedField(queryset=Label.objects.all())
label = serializers.PrimaryKeyRelatedField(queryset=Label.objects.all())
document = serializers.PrimaryKeyRelatedField(queryset=Document.objects.all())
@ -202,7 +202,6 @@ class DocumentAnnotationSerializer(serializers.ModelSerializer):
class SequenceAnnotationSerializer(serializers.ModelSerializer):
#label = ProjectFilteredPrimaryKeyRelatedField(queryset=Label.objects.all())
label = serializers.PrimaryKeyRelatedField(queryset=Label.objects.all())
document = serializers.PrimaryKeyRelatedField(queryset=Document.objects.all())

1
backend/api/views/role.py

@ -59,4 +59,3 @@ class RoleMappingDetail(generics.RetrieveUpdateAPIView):
super().perform_update(serializer)
except IntegrityError:
raise RoleAlreadyAssignedException

2
backend/api/views/statistics.py

@ -37,7 +37,7 @@ class StatisticsAPI(APIView):
@staticmethod
def _get_user_completion_data(annotation_class, annotation_filter):
all_annotation_objects = annotation_class.objects.filter(annotation_filter)
all_annotation_objects = annotation_class.objects.filter(annotation_filter)
set_user_data = collections.defaultdict(set)
for ind_obj in all_annotation_objects.values('user__username', 'document__id'):
set_user_data[ind_obj['user__username']].add(ind_obj['document__id'])

1
backend/api/views/upload/__init__.py

@ -1 +0,0 @@

2
backend/api/views/upload/examples.py

@ -61,7 +61,7 @@ Text_JSONL = """
"""
Offset_JSONL = """
{"column_data": "EU rejects German call to boycott British lamb.", "column_label": [ [0, 2, "ORG"], [11, 17, "MISC"], ... ]}
{"column_data": "EU rejects German call to boycott British lamb.", "column_label": [ [0, 2, "ORG"], ... ]}
{"column_data": "Peter Blackburn", "column_label": [ [0, 15, "PERSON"] ]}
{"column_data": "President Obama", "column_label": [ [10, 15, "PERSON"] ]}
"""

1
backend/api/views/user.py

@ -24,4 +24,3 @@ class Users(generics.ListAPIView):
pagination_class = None
filter_backends = (DjangoFilterBackend, filters.SearchFilter)
search_fields = ('username',)
Loading…
Cancel
Save