From a5abdf6f6ad1c51a0aaea253560e742f690cb16d Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 29 Oct 2014 11:11:54 +0100 Subject: * moving find_driver to static Driver method --- f1elo/model.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'f1elo/model.py') diff --git a/f1elo/model.py b/f1elo/model.py index 7865198..96a9ef4 100644 --- a/f1elo/model.py +++ b/f1elo/model.py @@ -25,6 +25,16 @@ class Driver(Base): return ranks[-1] return None + @staticmethod + def fetch(name, country, session): + driver = session.query(Driver).filter(Driver.driver==name).first() + if not driver: + driver = Driver() + driver.driver = name + driver.country = country + session.add(driver) + return driver + driver_entry = Table('driver_entries', Base.metadata, Column('_driver', Integer, ForeignKey('drivers.id')), Column('_entry', Integer, ForeignKey('entries.id')), @@ -85,16 +95,5 @@ class Ranking(Base): def __repr__(self): return ("%s: %0.2f (%s)" % (self.driver.__repr__().decode('utf8'), self.ranking, self. rank_date)).encode('utf8') -def find_driver(name, country, session): - driver = session.query(Driver).filter(Driver.driver==name).first() - if driver: - return driver - else: - driver = Driver() - driver.driver = name - driver.country = country - session.add(driver) - return driver - __all__ = ['Driver', 'Entry', 'Ranking', 'Race', 'RaceType'] -- cgit v1.2.3