Skip to content

Commit

Permalink
Merge pull request #9703 from archesproject/9702-exists
Browse files Browse the repository at this point in the history
purges count method in favor of exists
  • Loading branch information
chiatt authored Jul 4, 2023
2 parents fdc9ad9 + bc68090 commit 5b13061
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions arches/app/datatypes/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", [])]:
Expand Down
2 changes: 1 addition & 1 deletion arches/app/models/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion arches/app/models/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"])),
Expand Down
4 changes: 2 additions & 2 deletions arches/app/utils/data_management/resources/formats/csvfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions arches/app/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions arches/app/views/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b13061

Please sign in to comment.