Removed in-model functions for corp updates, switch to tasks. Cleaned up and improved API tasks

This commit is contained in:
2010-12-02 12:57:49 +00:00
parent 4e9dd81ea9
commit 20f4465d68
5 changed files with 241 additions and 95 deletions

View File

@@ -133,33 +133,6 @@ class EVEPlayerCharacterRole(EVEAPIModel):
verbose_name = 'Player Role'
verbose_name_plural = 'Player Roles'
class EVEPlayerAlliance(EVEAPIModel):
"""
Represents a player-controlled alliance. Updated from the alliance
EVE XML API puller at intervals.
"""
name = models.CharField(max_length=255, blank=True, null=False)
ticker = models.CharField(max_length=15, blank=True, null=False)
#executor_character = models.ForeignKey(EVECharacter, blank=True, null=False)
member_count = models.IntegerField(blank=True, null=True)
date_founded = models.DateField(blank=True, null=True)
group = models.ForeignKey(Group, blank=True, null=True)
class Meta:
app_label = 'eve_api'
ordering = ['date_founded']
verbose_name = 'Player Alliance'
verbose_name_plural = 'Player Alliances'
def __unicode__(self):
if self.name:
return self.name
else:
return "(#%d)" % self.id
def __str__(self):
return self.__unicode__()
class EVEPlayerCorporation(EVEAPIModel):
"""
Represents a player-controlled corporation. Updated from a mixture of
@@ -170,8 +143,7 @@ class EVEPlayerCorporation(EVEAPIModel):
description = models.TextField(blank=True, null=True)
url = models.URLField(verify_exists=False, blank=True, null=True)
ceo_character = models.ForeignKey(EVEPlayerCharacter, blank=True, null=True)
#home_station = models.ForeignKey(EVEStation, blank=True, null=False)
alliance = models.ForeignKey(EVEPlayerAlliance, blank=True, null=True)
alliance = models.ForeignKey('eve_api.EVEPlayerAlliance', blank=True, null=True)
alliance_join_date = models.DateField(blank=True, null=True)
tax_rate = models.FloatField(blank=True, null=True)
member_count = models.IntegerField(blank=True, null=True)
@@ -199,51 +171,31 @@ class EVEPlayerCorporation(EVEAPIModel):
return self.name
else:
return "Corp #%d" % self.id
def query_and_update_corp(self):
"""
Takes an EVEPlayerCorporation object and updates it from the
EVE API service.
"""
# Pull XML from the EVE API via eve_proxy.
dom = EVEPlayerCorporation.objects.api_corp_sheet_xml(self.id)
# Tuples of pairings of tag names and the attribute on the Corporation
# object to set the data to.
tag_mappings = (
('corporationName', 'name'),
('ticker', 'ticker'),
('url', 'url'),
('description', 'description'),
('memberCount', 'member_count'),
('graphicID', 'logo_graphic_id'),
('shape1', 'logo_shape1'),
('shape2', 'logo_shape2'),
('shape3', 'logo_shape3'),
('color1', 'logo_color1'),
('color2', 'logo_color2'),
('color3', 'logo_color3'),
)
# Iterate through the tag mappings, setting the values of the tag names
# (first member of the tuple) to the attribute named in the second member
# of the tuple on the EVEPlayerCorporation object.
for tag_map in tag_mappings:
try:
setattr(self, tag_map[1],
dom.getElementsByTagName(tag_map[0])[0].firstChild.nodeValue)
except AttributeError:
# This tag has no value, skip it.
continue
except IndexError:
# Something weird has happened
continue
class EVEPlayerAlliance(EVEAPIModel):
"""
Represents a player-controlled alliance. Updated from the alliance
EVE XML API puller at intervals.
"""
name = models.CharField(max_length=255, blank=True, null=False)
ticker = models.CharField(max_length=15, blank=True, null=False)
executor = models.ForeignKey(EVEPlayerCorporation, blank=True, null=True)
member_count = models.IntegerField(blank=True, null=True)
date_founded = models.DateField(blank=True, null=True)
group = models.ForeignKey(Group, blank=True, null=True)
from eve_api.tasks import import_eve_character
class Meta:
app_label = 'eve_api'
ordering = ['date_founded']
verbose_name = 'Player Alliance'
verbose_name_plural = 'Player Alliances'
ceoid = dom.getElementsByTagName('ceoID')[0].firstChild.nodeValue
self.ceo_character = import_eve_character(ceoid)
def __unicode__(self):
if self.name:
return self.name
else:
return "(#%d)" % self.id
def __str__(self):
return self.__unicode__()
self.api_last_updated = datetime.utcnow()
self.save()