# Path: foosball/games/utils.py
# def random_colour():
#     """Generate random colour.
# 
#     Thanks: http://stackoverflow.com/a/14019260/1489738
#     """
#     r = lambda: random.randint(0, 255)
#     return '#%02X%02X%02X' % (r(), r(), r())


from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel
from foosball.games.utils import random_colour
from foosball.users.models import User
    )
    total_played = models.PositiveIntegerField(
        verbose_name=_("total played"),
        help_text=_("Total games played in"),
        default=0
    )
    singles_played = models.PositiveIntegerField(
        verbose_name=_("singles played"),
        help_text=_("Total games played as a single player team"),
        default=0
    )
    doubles_played = models.PositiveIntegerField(
        verbose_name=_("doubles played"),
        help_text=_("Total games played in a two player team"),
        default=0
    )
    colour = models.CharField(
        verbose_name=_("colour code"),
        help_text=_("Player colour as a hex colour code"),
        max_length=7, null=True
    )

    def __str__(self):
        return "Player %s" % self.user.name if self.user.name else self.user.username

    def save(self, *args, **kwargs):
        """
        Init some data for the player.
        """
        if not self.pk or not self.colour:

# Path: foosball/games/utils.py
# def random_colour():
#     """Generate random colour.
# 
#     Thanks: http://stackoverflow.com/a/14019260/1489738
#     """
#     r = lambda: random.randint(0, 255)
#     return '#%02X%02X%02X' % (r(), r(), r())


# Path: foosball/games/models.py
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel
from foosball.games.utils import random_colour
from foosball.users.models import User

    )
    total_played = models.PositiveIntegerField(
        verbose_name=_("total played"),
        help_text=_("Total games played in"),
        default=0
    )
    singles_played = models.PositiveIntegerField(
        verbose_name=_("singles played"),
        help_text=_("Total games played as a single player team"),
        default=0
    )
    doubles_played = models.PositiveIntegerField(
        verbose_name=_("doubles played"),
        help_text=_("Total games played in a two player team"),
        default=0
    )
    colour = models.CharField(
        verbose_name=_("colour code"),
        help_text=_("Player colour as a hex colour code"),
        max_length=7, null=True
    )

    def __str__(self):
        return "Player %s" % self.user.name if self.user.name else self.user.username

    def save(self, *args, **kwargs):
        """
        Init some data for the player.
        """
        if not self.pk or not self.colour:

            self.colour = random_colour()