2015-10-31 23:46:43 +03:00
|
|
|
from .models import Character, Faction, Ship
|
2015-09-30 09:40:40 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-30 09:40:40 +03:00
|
|
|
def initialize():
|
2015-10-11 00:53:46 +03:00
|
|
|
human = Character(
|
|
|
|
name='Human'
|
|
|
|
)
|
|
|
|
human.save()
|
|
|
|
|
|
|
|
droid = Character(
|
|
|
|
name='Droid'
|
|
|
|
)
|
|
|
|
droid.save()
|
|
|
|
|
2015-09-30 09:40:40 +03:00
|
|
|
rebels = Faction(
|
|
|
|
id='1',
|
|
|
|
name='Alliance to Restore the Republic',
|
2015-10-11 00:53:46 +03:00
|
|
|
hero=human
|
2015-09-30 09:40:40 +03:00
|
|
|
)
|
|
|
|
rebels.save()
|
|
|
|
|
|
|
|
empire = Faction(
|
|
|
|
id='2',
|
|
|
|
name='Galactic Empire',
|
2015-10-11 00:53:46 +03:00
|
|
|
hero=droid
|
2015-09-30 09:40:40 +03:00
|
|
|
)
|
|
|
|
empire.save()
|
|
|
|
|
|
|
|
xwing = Ship(
|
|
|
|
id='1',
|
|
|
|
name='X-Wing',
|
|
|
|
faction=rebels,
|
|
|
|
)
|
|
|
|
xwing.save()
|
|
|
|
|
|
|
|
ywing = Ship(
|
|
|
|
id='2',
|
|
|
|
name='Y-Wing',
|
|
|
|
faction=rebels,
|
|
|
|
)
|
|
|
|
ywing.save()
|
|
|
|
|
|
|
|
awing = Ship(
|
|
|
|
id='3',
|
|
|
|
name='A-Wing',
|
|
|
|
faction=rebels,
|
|
|
|
)
|
|
|
|
awing.save()
|
|
|
|
|
|
|
|
# Yeah, technically it's Corellian. But it flew in the service of the rebels,
|
|
|
|
# so for the purposes of this demo it's a rebel ship.
|
|
|
|
falcon = Ship(
|
|
|
|
id='4',
|
|
|
|
name='Millenium Falcon',
|
|
|
|
faction=rebels,
|
|
|
|
)
|
|
|
|
falcon.save()
|
|
|
|
|
|
|
|
homeOne = Ship(
|
|
|
|
id='5',
|
|
|
|
name='Home One',
|
|
|
|
faction=rebels,
|
|
|
|
)
|
|
|
|
homeOne.save()
|
|
|
|
|
|
|
|
tieFighter = Ship(
|
|
|
|
id='6',
|
|
|
|
name='TIE Fighter',
|
|
|
|
faction=empire,
|
|
|
|
)
|
|
|
|
tieFighter.save()
|
|
|
|
|
|
|
|
tieInterceptor = Ship(
|
|
|
|
id='7',
|
|
|
|
name='TIE Interceptor',
|
|
|
|
faction=empire,
|
|
|
|
)
|
|
|
|
tieInterceptor.save()
|
|
|
|
|
|
|
|
executor = Ship(
|
|
|
|
id='8',
|
|
|
|
name='Executor',
|
|
|
|
faction=empire,
|
|
|
|
)
|
|
|
|
executor.save()
|
|
|
|
|
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def create_ship(ship_name, faction_id):
|
|
|
|
new_ship = Ship(
|
|
|
|
name=ship_name,
|
|
|
|
faction_id=faction_id
|
2015-09-30 09:40:40 +03:00
|
|
|
)
|
2015-10-30 10:36:31 +03:00
|
|
|
new_ship.save()
|
|
|
|
return new_ship
|
2015-09-30 09:40:40 +03:00
|
|
|
|
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def get_ship(_id):
|
2015-09-30 09:40:40 +03:00
|
|
|
return Ship.objects.get(id=_id)
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def get_ships():
|
2015-10-01 11:54:52 +03:00
|
|
|
return Ship.objects.all()
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def get_faction(_id):
|
2015-09-30 09:40:40 +03:00
|
|
|
return Faction.objects.get(id=_id)
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def get_rebels():
|
|
|
|
return get_faction(1)
|
2015-09-30 09:40:40 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-10-30 10:36:31 +03:00
|
|
|
def get_empire():
|
|
|
|
return get_faction(2)
|