# Path: replayswithfriends/sc2match/models.py
# class Match(models.Model):
#     owner = models.ForeignKey(User)
#     created = models.DateTimeField(default=timezone.now, editable=False)
#     modified = models.DateTimeField(editable=False)
#     replay_file = models.FileField(upload_to=generate_filename, storage=storage_engine)
#     mapfield = models.ForeignKey(Map, null=True, editable=False)
#     duration = models.PositiveIntegerField(null=True, editable=False)
#     gateway = models.CharField(max_length=32, default="us")
#     processed = models.NullBooleanField(default=None)
#     process_error = models.TextField(blank=True, default='', editable=False)
#     match_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     matchhash = models.CharField(max_length=512, editable=False, blank=True, default='')
#     is_ladder = models.BooleanField(default=True)
#     game_played_on = models.DateTimeField(null=True, blank=True)
#     game_type = models.CharField(max_length=64, blank=True, default=True)
#     game_speed = models.CharField(max_length=64, blank=True, default=True)
#     events_json = models.TextField(editable=False, blank=True)
# 
#     objects = models.Manager()
#     share = ShareManager()
#     processing = ProcessedManager()
# 
#     def __init__(self, *args, **kwargs):
#         self._replay = None
#         super(Match, self).__init__(*args, **kwargs)
# 
#     def __unicode__(self):
#         if self.processed:
#             return "%s" % ", ".join(self.players.all().values_list('nick', flat=True).order_by("nick"))
#         else:
#             return "unprocessed match %s" % self.created
# 
#     def process_now(self):
#         from .tasks import parse_replay
#         parse_replay(self.id)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('match_detail', [self.id])
# 
#     @property
#     def replay(self):
#         if not self._replay:
#             self._replay = sc2reader.load_replay(self.replay_file.file, load_map=False)
#         return self._replay
# 
#     @property
#     def time_display(self):
#         if self.duration:
#             minutes = self.duration / 60
#             seconds = self.duration % 60
#             return '%d:%02d' % (minutes, seconds)
#         else:
#             return '-'
# 
#     def make_hash(self, block_size=2**8):
#         md5 = hashlib.md5()
#         while True:
#             data = self.replay_file.read(block_size)
#             if not data:
#                 break
#             md5.update(data)
#         data = self.replay_file.seek(0)
#         self.matchhash = md5.hexdigest()
# 
#     @property
#     def winners(self):
#         return self.players.filter(result=True)
# 
#     @property
#     def losers(self):
#         return self.players.filter(result=False)
# 
#     def save(self, *args, **kwargs):
#         self.modified = timezone.now()
#         if not self.matchhash:
#             self.make_hash()
#         super(Match, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ['-game_played_on', '-modified']
#         unique_together = ['owner', 'matchhash']


import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
from replayswithfriends.sc2match.models import Match
# -*- coding: utf-8 -*-

class Migration(DataMigration):

    def forwards(self, orm):
        "Write your forwards methods here."
        # add the hashes

# Path: replayswithfriends/sc2match/models.py
# class Match(models.Model):
#     owner = models.ForeignKey(User)
#     created = models.DateTimeField(default=timezone.now, editable=False)
#     modified = models.DateTimeField(editable=False)
#     replay_file = models.FileField(upload_to=generate_filename, storage=storage_engine)
#     mapfield = models.ForeignKey(Map, null=True, editable=False)
#     duration = models.PositiveIntegerField(null=True, editable=False)
#     gateway = models.CharField(max_length=32, default="us")
#     processed = models.NullBooleanField(default=None)
#     process_error = models.TextField(blank=True, default='', editable=False)
#     match_share = models.PositiveSmallIntegerField(choices=SHARE, default=SHARE.FRIENDS)
#     matchhash = models.CharField(max_length=512, editable=False, blank=True, default='')
#     is_ladder = models.BooleanField(default=True)
#     game_played_on = models.DateTimeField(null=True, blank=True)
#     game_type = models.CharField(max_length=64, blank=True, default=True)
#     game_speed = models.CharField(max_length=64, blank=True, default=True)
#     events_json = models.TextField(editable=False, blank=True)
# 
#     objects = models.Manager()
#     share = ShareManager()
#     processing = ProcessedManager()
# 
#     def __init__(self, *args, **kwargs):
#         self._replay = None
#         super(Match, self).__init__(*args, **kwargs)
# 
#     def __unicode__(self):
#         if self.processed:
#             return "%s" % ", ".join(self.players.all().values_list('nick', flat=True).order_by("nick"))
#         else:
#             return "unprocessed match %s" % self.created
# 
#     def process_now(self):
#         from .tasks import parse_replay
#         parse_replay(self.id)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('match_detail', [self.id])
# 
#     @property
#     def replay(self):
#         if not self._replay:
#             self._replay = sc2reader.load_replay(self.replay_file.file, load_map=False)
#         return self._replay
# 
#     @property
#     def time_display(self):
#         if self.duration:
#             minutes = self.duration / 60
#             seconds = self.duration % 60
#             return '%d:%02d' % (minutes, seconds)
#         else:
#             return '-'
# 
#     def make_hash(self, block_size=2**8):
#         md5 = hashlib.md5()
#         while True:
#             data = self.replay_file.read(block_size)
#             if not data:
#                 break
#             md5.update(data)
#         data = self.replay_file.seek(0)
#         self.matchhash = md5.hexdigest()
# 
#     @property
#     def winners(self):
#         return self.players.filter(result=True)
# 
#     @property
#     def losers(self):
#         return self.players.filter(result=False)
# 
#     def save(self, *args, **kwargs):
#         self.modified = timezone.now()
#         if not self.matchhash:
#             self.make_hash()
#         super(Match, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ['-game_played_on', '-modified']
#         unique_together = ['owner', 'matchhash']


# Path: replayswithfriends/sc2match/migrations/0004_addmatchhash.py
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
from replayswithfriends.sc2match.models import Match

# -*- coding: utf-8 -*-

class Migration(DataMigration):

    def forwards(self, orm):
        "Write your forwards methods here."
        # add the hashes

        if not Match.objects.exists():