diff --git a/arches/app/datatypes/datatypes.py b/arches/app/datatypes/datatypes.py index dadeec7a812..04213df1067 100644 --- a/arches/app/datatypes/datatypes.py +++ b/arches/app/datatypes/datatypes.py @@ -992,8 +992,8 @@ def get_map_layer(self, node=None, preview=False): return None elif node.config is None: return None - count = models.TileModel.objects.filter(nodegroup_id=node.nodegroup_id, data__has_key=str(node.nodeid)).count() - if not preview and (count < 1 or not node.config["layerActivated"]): + tile_exists = models.TileModel.objects.filter(nodegroup_id=node.nodegroup_id, data__has_key=str(node.nodeid)).exists() + if not preview and (not tile_exists or not node.config["layerActivated"]): return None source_name = "resources-%s" % node.nodeid @@ -1593,7 +1593,7 @@ def post_tile_save(self, tile, nodeid, request): file_model = models.File() file_model.path = file_data file_model.tile = tile - if models.TileModel.objects.filter(pk=tile.tileid).count() > 0: + if models.TileModel.objects.filter(pk=tile.tileid).exists(): original_storage = file_model.path.storage # Prevents Django's file storage API from overwriting files uploaded directly from client re #9321 if file_data.name in [x.name for x in request.FILES.getlist("file-list_" + nodeid + "_preloaded", [])]: diff --git a/arches/app/models/concept.py b/arches/app/models/concept.py index bf386175054..069fa586b30 100644 --- a/arches/app/models/concept.py +++ b/arches/app/models/concept.py @@ -329,7 +329,7 @@ def delete(self, delete_self=False): for relation in conceptrelations: relation.delete() - if models.Relation.objects.filter(relations_filter).count() == 0: + if not models.Relation.objects.filter(relations_filter).exists(): # we've removed all parent concepts so now this concept needs to be promoted to a Concept Scheme concept = models.Concept.objects.get(pk=self.id) concept.nodetype_id = "ConceptScheme" diff --git a/arches/app/models/tile.py b/arches/app/models/tile.py index a9b25872faf..afc04ef34f6 100644 --- a/arches/app/models/tile.py +++ b/arches/app/models/tile.py @@ -242,7 +242,7 @@ def check_for_constraint_violation(self): return card = models.CardModel.objects.get(nodegroup=self.nodegroup) constraints = models.ConstraintModel.objects.filter(card=card) - if constraints.count() > 0: + if constraints.exists(): for constraint in constraints: if constraint.uniquetoallinstances is True: tiles = models.TileModel.objects.filter(nodegroup=self.nodegroup) diff --git a/arches/app/utils/data_management/resources/formats/archesfile.py b/arches/app/utils/data_management/resources/formats/archesfile.py index 246ba58185b..0337fc7baba 100644 --- a/arches/app/utils/data_management/resources/formats/archesfile.py +++ b/arches/app/utils/data_management/resources/formats/archesfile.py @@ -147,7 +147,7 @@ def import_business_data_without_mapping(self, business_data, reporter, overwrit errors = [] for resource in business_data["resources"]: if resource["resourceinstance"] is not None: - if GraphModel.objects.filter(graphid=str(resource["resourceinstance"]["graph_id"])).count() > 0: + if GraphModel.objects.filter(graphid=str(resource["resourceinstance"]["graph_id"])).exists(): resourceinstanceid = uuid.UUID(str(resource["resourceinstance"]["resourceinstanceid"])) defaults = { "graph_id": uuid.UUID(str(resource["resourceinstance"]["graph_id"])), diff --git a/arches/app/utils/data_management/resources/formats/csvfile.py b/arches/app/utils/data_management/resources/formats/csvfile.py index ef5094a5a30..c744b40a889 100644 --- a/arches/app/utils/data_management/resources/formats/csvfile.py +++ b/arches/app/utils/data_management/resources/formats/csvfile.py @@ -464,8 +464,8 @@ def scan_for_new_languages(self, business_data=None): match = column_regex.match(column) if match is not None: new_language_candidate = match.groups()[0] - existing_language_count = Language.objects.filter(code=new_language_candidate).count() - if existing_language_count == 0: + language_exists = Language.objects.filter(code=new_language_candidate).exists() + if not language_exists: new_languages.append(new_language_candidate) return new_languages diff --git a/arches/app/utils/forms.py b/arches/app/utils/forms.py index f13b890cca3..4c7ba4c94d2 100644 --- a/arches/app/utils/forms.py +++ b/arches/app/utils/forms.py @@ -56,7 +56,7 @@ class Meta: def clean(self): cleaned_data = super(ArchesUserCreationForm, self).clean() if "email" in cleaned_data: - if User.objects.filter(email=cleaned_data["email"]).count() > 0: + if User.objects.filter(email=cleaned_data["email"]).exists(): self.add_error( "email", forms.ValidationError( @@ -97,7 +97,7 @@ def save(self): user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] user.email = self.cleaned_data["email"] - if models.UserProfile.objects.filter(user=user).count() == 0: + if not models.UserProfile.objects.filter(user=user).exists(): models.UserProfile.objects.create(user=user) user.userprofile.phone = self.cleaned_data["phone"] user.userprofile.save() diff --git a/arches/app/views/tile.py b/arches/app/views/tile.py index 1bae6946f52..f1efd6d3b56 100644 --- a/arches/app/views/tile.py +++ b/arches/app/views/tile.py @@ -143,8 +143,8 @@ def post(self, request): try: tile.save(request=request, transaction_id=transaction_id) except TileValidationError as e: - resource_tiles = models.TileModel.objects.filter(resourceinstance=tile.resourceinstance) - if resource_tiles.count() == 0: + resource_tiles_exist = models.TileModel.objects.filter(resourceinstance=tile.resourceinstance).exists() + if not resource_tiles_exist: Resource.objects.get(pk=tile.resourceinstance_id).delete(request.user) title = _("Unable to save. Please verify your input is valid") return self.handle_save_error(e, tile_id, title=title)