from django.db import models
from django.template.defaultfilters import slugify
from django.contrib.auth.models import User

REPOTYPES = (
    (0, 'git'),
    (1, 'hg'),
)

STATUSTYPES = (
    (0, 'PENDING'),
    (1, 'CLONED'),
    (2, 'PROCESSING'),
    (3, 'READY'),
    (255, 'ERROR')
)

class Repository(models.Model):
    user = models.ForeignKey(User, null=True, blank=True)
    name = models.CharField(max_length=255)
    origin = models.CharField(max_length=255)
    origin_type = models.IntegerField(choices=REPOTYPES)
    fs_path = models.CharField(max_length=255)
    status = models.IntegerField(choices=STATUSTYPES)

    def __unicode__(self):
        return self.name

    def get_name(self):
        username = '' if self.user is None else self.user.username
        return '/'.join([i for i in [username, self.name] if i])

    def get_absolute_url(self):
        return reverse('repo_detail', kwargs={
            'name':slugify(self.get_name()),
        })


from django.db import models
from django.template.defaultfilters import slugify
from django.contrib.auth.models import User

REPO_GIT = 0
REPO_HG = 1

REPOTYPES = (
    (REPO_GIT, 'git'),
    (REPO_HG, 'hg'),
)

STATUS_PENDING = 0
STATUS_CLONED = 1
STATUS_PROCESSING = 2
STATUS_READY = 3
STATUS_ERROR = 255

STATUSTYPES = (
    (STATUS_PENDING, 'PENDING'),
    (STATUS_CLONED, 'CLONED'),
    (STATUS_PROCESSING, 'PROCESSING'),
    (STATUS_READY, 'READY'),
    (STATUS_ERROR, 'ERROR')
)

class Repository(models.Model):
    user = models.ForeignKey(User, null=True, blank=True)
    name = models.CharField(max_length=255)
    origin = models.CharField(max_length=255)
    origin_type = models.IntegerField(choices=REPOTYPES)
    fs_path = models.CharField(max_length=255)
    status = models.IntegerField(choices=STATUSTYPES)

    def __unicode__(self):
        return self.name

    def get_name(self):
        username = '' if self.user is None else self.user.username
        return '/'.join([i for i in [username, self.name] if i])

    def get_absolute_url(self):
        return reverse('repo_detail', kwargs={
            'name':slugify(self.get_name()),
        })


add in nicer types