Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

purges count method in favor of exists #9703

Merged
merged 1 commit into from
Jul 4, 2023
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
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