Allows one location to have multiple owners.

doc_update
Joey Hines 2019-01-31 14:07:25 -06:00
parent 46f787198f
commit f333a9ebac
5 changed files with 50 additions and 13 deletions

View File

@ -95,7 +95,9 @@ def add_location(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None, loc_t
if name is None:
name = "{}'s {}".format(player.name, loc_type.__name__)
location = loc_type.objects.create(owner=player, name=name, x_coord=x_pos, z_coord=z_pos)
location = loc_type.objects.create(name=name, x_coord=x_pos, z_coord=z_pos)
location.owner.add(player)
location.save()
return location.json

View File

@ -30,7 +30,8 @@ def run_command(request, command, req_type):
raise CommandNotFound
except Exception as e:
response = {"error": e.__class__.__name__, "error_message": str(e)}
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
if settings["DEBUG"]:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
return JsonResponse(response, safe=False)
@ -77,7 +78,7 @@ class SettingsAPI(View):
if check_token(request.GET, commands_perm=True):
response = {
"BOT_PREFIX": getattr(settings, 'GEOFFREY_BOT_PREFIX', '?'),
"ERROR_USERS": getattr(settings, 'GEOFFREY__BOT_ERROR_USERS', []),
"ERROR_USERS": getattr(settings, 'GEOFFREY_BOT_ERROR_USERS', []),
"MOD_RANKS": getattr(settings, 'GEOFFREY_BOT_MOD_RANK', []),
"STATUS": getattr(settings, 'GEOFFREY_BOT_STATUS', 'sed')
}

View File

@ -0,0 +1,21 @@
# Generated by Django 2.1.2 on 2019-01-31 18:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('GeoffreyApp', '0005_auto_20190113_2255'),
]
operations = [
migrations.RemoveField(
model_name='location',
name='owner',
),
migrations.AddField(
model_name='location',
name='owner',
field=models.ManyToManyField(to='GeoffreyApp.Player'),
),
]

View File

@ -85,7 +85,7 @@ class Location(models.Model):
dimension = models.CharField(max_length=1, choices=DIMENSIONS)
owner = models.ForeignKey(Player, related_name='owner_player', on_delete=models.CASCADE)
owner = models.ManyToManyField(Player)
'''
Owner of Location
'''
@ -103,6 +103,14 @@ class Location(models.Model):
return tunnel
@property
def get_owners(self):
owner_list = []
for owner in self.owner.all():
owner_list.append(owner.json)
return owner_list
@property
def json(self):
return {"type": self.__class__.__name__,
@ -110,7 +118,7 @@ class Location(models.Model):
"x_coord": self.x_coord,
"z_coord": self.z_coord,
"dimension": self.dimension,
"owner": self.owner.json,
"owner": self.get_owners,
"location": self.location,
"tunnel": None if self.tunnel is None else self.tunnel.tunnel_str
}

View File

@ -24,10 +24,11 @@ class CommandsAPITestCase(TestCase):
Tunnel.objects.all().delete()
def populate(self):
self.base = Base.objects.create(owner=self.player, name="test", x_coord=0, z_coord=0, dimension="O")
self.shop = Shop.objects.create(owner=self.player, name="test shop", x_coord=500, z_coord=500,
self.base = Base.objects.create(name="test", x_coord=0, z_coord=0, dimension="O")
self.base.owner.add(self.player)
self.shop = Shop.objects.create(name="test shop", x_coord=500, z_coord=500,
dimension="O")
self.shop.owner.add(self.player)
self.item = ItemListing.objects.create(shop=self.shop, price=1, amount=5, item_name="sed")
self.tunnel = Tunnel.objects.create(tunnel_number="42", tunnel_direction="S", location=self.base)
@ -46,7 +47,7 @@ class CommandsAPITestCase(TestCase):
base = Base.objects.filter(name__icontains=USERNAME).all().first()
self.assertEqual(base.owner.name, "ZeroHD")
self.assertEqual(base.owner.all()[0].name, "ZeroHD")
self.assertRaises(EntryNameNotUniqueError, add_base, x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
@ -55,10 +56,12 @@ class CommandsAPITestCase(TestCase):
shop = Shop.objects.filter(name__icontains=USERNAME).all().first()
self.assertEqual(shop.owner.name, "ZeroHD")
self.assertEqual(shop.owner.all()[0].name, "ZeroHD")
def test_add_tunnel(self):
base = Base.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
base = Base.objects.create(name="Test", x_coord=0, z_coord=0)
base.owner.add(self.player)
add_tunnel(tunnel_direction="N", tunnel_number=500, discord_uuid=DISCORD_UUID)
qbase = Base.objects.filter(tunnel_location__tunnel_direction="N").all().first()
@ -66,7 +69,8 @@ class CommandsAPITestCase(TestCase):
self.assertEqual(base.id, qbase.id)
def test_add_item(self):
shop = Shop.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
shop = Shop.objects.create(name="Test", x_coord=0, z_coord=0)
shop.owner.add(self.player)
add_item(item_name="sed", quantity=5, diamond_price=5, discord_uuid=DISCORD_UUID)
item = ItemListing.objects.filter(shop_id=shop.id).all().first()
@ -74,7 +78,8 @@ class CommandsAPITestCase(TestCase):
self.assertEqual(item.item_name, "sed")
def test_edit_post(self):
shop = Shop.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
shop = Shop.objects.create(name="Test", x_coord=0, z_coord=0)
shop.owner.add(self.player)
edit_pos(x=500, z=500, loc_name="Test", discord_uuid=DISCORD_UUID)