Fixed issue in add_location() and fixed tests

doc_update
Joey Hines 2019-02-03 09:01:06 -06:00
parent 39302bb136
commit 723124f26e
1 changed files with 5 additions and 6 deletions

View File

@ -84,13 +84,12 @@ def get_location(owner, name=None, loc_type=Location):
def add_location(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None, loc_type=Location):
player = get_player(discord_uuid, mc_uuid)
try:
get_location(player, name, loc_type=loc_type)
raise EntryNameNotUniqueError
except (Location.DoesNotExist, NoLocationsInDatabase, LocationLookUpError):
if name is None:
name = "{}'s {}".format(player.name, loc_type.__name__)
if name is None:
name = "{}'s {}".format(player.name, loc_type.__name__)
if Location.objects.filter(name__iexact=name).all().count() > 0:
raise EntryNameNotUniqueError
else:
location = loc_type.objects.create(name=name, x_coord=x_pos, z_coord=z_pos)
location.owner.add(player)
location.save()