本文整理汇总了Python中app.models.Event.completed方法的典型用法代码示例。如果您正苦于以下问题:Python Event.completed方法的具体用法?Python Event.completed怎么用?Python Event.completed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Event
的用法示例。
在下文中一共展示了Event.completed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_noargs
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import completed [as 别名]
def handle_noargs(self, **options):
cursor = connections['import'].cursor()
# Import players
cursor.execute('SELECT ID, Name FROM Player')
row = cursor.fetchone()
players = {}
while row:
try:
player = Player.objects.get(name=row[1])
except Player.DoesNotExist:
player = Player(name=row[1])
player.save()
players[row[0]] = player
row = cursor.fetchone()
cursor.execute('''
SELECT EventID, Event.Date, PlayerID, [1st], [2nd], [3rd], [4th]
FROM Result INNER JOIN Event on Event.ID = Result.EventID
WHERE EventID > 3
ORDER BY Event.Date ASC
''')
# Import events
event_id = 0
event = None
row = cursor.fetchone()
transaction.commit_unless_managed()
transaction.enter_transaction_management()
transaction.managed(True)
try:
while row:
if event_id != row[0]:
event = Event(event_date=row[1])
try:
event.save()
event_id = row[0]
event_points = 0
self.stdout.write("Importing event %s\n" % event)
except IntegrityError:
# Event already exists, skip it
self.stdout.write("Skipping event %s (already imported)\n" % row[0])
# Only process result if a saved event exists
if event.pk is not None:
result = EventResult(event=event, player=players[row[2]], firsts=row[3], seconds=row[4], thirds=row[5], fourths=row[6])
result.save()
event_points += result.points
if event.results.count() == 4:
if event_points != MAX_EVENT_POINTS:
# Discard invalid events
event.delete()
self.stdout.write("Discarding event %s[%s] (invalid number of points: %s)\n" % (event, event_id, event_points))
else:
# Complete event
event.completed = True
event.save()
row = cursor.fetchone()
except:
transaction.rollback()
transaction.leave_transaction_management()
self.stdout.write("Unexpected error importing events")
raise
return
transaction.commit()
transaction.leave_transaction_management()