Got all tests passing again

+Added json property to ItemListing
+Fixed a typo
+Updated Django the Geoffrey settings to have Geoffrey in front of them
doc_update
Joey Hines 2019-01-04 11:20:24 -06:00
parent 4aadb3b185
commit 00fe2d72ab
3 changed files with 30 additions and 16 deletions

View File

@ -78,14 +78,9 @@ def add_location(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None, loc_t
if name is None: if name is None:
name = "{}'s {}".format(player.name, loc_type.__name__) name = "{}'s {}".format(player.name, loc_type.__name__)
if loc_type == Base: location = loc_type.objects.create(owner=player, name=name, x_coord=x_pos, z_coord=z_pos)
location = Base.objects.create(owner=player, name=name, x_coord=x_pos, z_coord=z_pos)
elif loc_type == Shop:
location = Shop.objects.create(owner=player, name=name, x_coord=x_pos, z_coord=z_pos)
else:
raise DataBaseError
return location.json return location.json
@command("POST") @command("POST")
@ -305,7 +300,7 @@ def tunnel(player_name):
if len(tunnels) == 0: if len(tunnels) == 0:
raise LocationLookUpError raise LocationLookUpError
return objects_list_to_json(tunnel) return objects_list_to_json(tunnels)
@command("POST") @command("POST")
@ -328,7 +323,7 @@ def edit_pos(x, z, loc_name, discord_uuid=None, mc_uuid=None):
location.z_coord = z location.z_coord = z
location.save() location.save()
return location.jsone return location.json
@command("POST") @command("POST")

View File

@ -2,7 +2,7 @@ from django.conf import settings
from GeoffreyApp.errors import ExternalLookupFailed from GeoffreyApp.errors import ExternalLookupFailed
import requests import requests
base_url = getattr(settings, 'MCM_BASE_URL', 'localhost') base_url = getattr(settings, 'GEOFFREY_MCM_BASE_URL', 'localhost')
player_url = base_url + '/api/model/player/' player_url = base_url + '/api/model/player/'
@ -12,7 +12,7 @@ def add_dashes_to_uuid(uuid):
def get_token(): def get_token():
api_token = getattr(settings, 'MCM_API_TOKEN') api_token = getattr(settings, 'GEOFFREY_MCM_API_TOKEN')
if api_token is not None: if api_token is not None:
return api_token return api_token
else: else:

View File

@ -26,7 +26,10 @@ class Player(models.Model):
@property @property
def json(self): def json(self):
return {"Name": self.name, "MC UUID": self.mc_uuid, "Discord UUID": self.discord_uuid} return {"Name": self.name,
"MC UUID": self.mc_uuid,
"Discord UUID": self.discord_uuid
}
def __str__(self): def __str__(self):
return self.name return self.name
@ -49,8 +52,13 @@ class Location(models.Model):
@property @property
def json(self): def json(self):
return {"Type": self.__class__.__name__, "Name": self.name, "x_coord": self.x_coord, "z_coord": self.z_coord, return {"Type": self.__class__.__name__,
"dimension": self.dimension, "Owner": self.owner.json} "Name": self.name,
"x_coord": self.x_coord,
"z_coord": self.z_coord,
"dimension": self.dimension,
"Owner": self.owner.json
}
def __str__(self): def __str__(self):
return self.name return self.name
@ -80,6 +88,15 @@ class ItemListing(models.Model):
else: else:
return self.price/self.amount return self.price/self.amount
@property
def json(self):
return {"item_name": self.item_name,
"price": self.price,
"amount": self.amount,
"normalized_price": self.normalized_price,
"shop": self.shop.json,
}
def __str__(self): def __str__(self):
return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount) return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount)
@ -102,5 +119,7 @@ class Tunnel(models.Model):
@property @property
def json(self): def json(self):
return {"Location_name": self.location.name, "tunnel_direction": self.tunnel_direction, return {"Location_name": self.location.name,
"tunnel_number": self.tunnel_number} "tunnel_direction": self.tunnel_direction,
"tunnel_number": self.tunnel_number
}