# Path: competition/models.py
# class Competition(models.Model):
#     name = models.CharField('Name', max_length=255, unique=True)
#     slug = models.SlugField(unique=True)
#     url = models.URLField('Competition URL', blank=True)
#     start_time = models.DateTimeField(blank=True, null=True)
#     end_time = models.DateTimeField(blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     __str__ = __unicode__
# 
#     def get_absolute_url(self):
#         return reverse('view_ctf', kwargs={'ctf_slug': self.slug})
# 
# class Challenge(models.Model):
#     NOT_STARTED = 0
#     IN_PROGRESS = 1
#     SOLVED = 2
# 
#     PROGRESS_CHOICES = (
#         (NOT_STARTED, 'Not Started'),
#         (IN_PROGRESS, 'In Progress'),
#         (SOLVED, 'Solved')
#     )
# 
#     name = models.CharField('Name', max_length=255)
#     slug = models.SlugField()
#     progress = models.PositiveSmallIntegerField(choices=PROGRESS_CHOICES)
#     num_progress = models.FloatField('Progress %', default=0)
#     point_value = models.FloatField(default=0)
# 
#     competition = models.ForeignKey(Competition, related_name='challenges')
#     last_viewed = models.DateTimeField(auto_created=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     __str__ = __unicode__
# 
#     def get_absolute_url(self):
#         return reverse('view_challenge', kwargs={'ctf_slug': self.competition.slug, 'chall_slug': self.slug})
# 
#     def last_viewed_display(self):
#         if self.last_viewed == 0:
#             return 'Never'
#         else:
#             return self.last_viewed
# 
#     class Meta:
#         unique_together = ('name', 'competition')
#         ordering = ('progress',)
# 
# class ChallengeFile(models.Model):
#     file = models.FileField(upload_to='files/')
#     ctime = models.DateTimeField(auto_created=True)
#     mtime = models.DateTimeField(auto_now=True)
#     challenge = models.ForeignKey(Challenge, related_name='files')
# 
#     def __unicode__(self):
#         return self.file.name
# 
#     __str__ = __unicode__
# 
#     def filename(self):
#         return os.path.basename(self.file.name)


from django.contrib import admin
from competition.models import Competition, Challenge, ChallengeFile

# Register your models here.


class CompetitionAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name',)}

    class Meta:
        model = Competition


class ChallengeAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name',)}

    class Meta:
        model = Challenge


# Path: competition/models.py
# class Competition(models.Model):
#     name = models.CharField('Name', max_length=255, unique=True)
#     slug = models.SlugField(unique=True)
#     url = models.URLField('Competition URL', blank=True)
#     start_time = models.DateTimeField(blank=True, null=True)
#     end_time = models.DateTimeField(blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     __str__ = __unicode__
# 
#     def get_absolute_url(self):
#         return reverse('view_ctf', kwargs={'ctf_slug': self.slug})
# 
# class Challenge(models.Model):
#     NOT_STARTED = 0
#     IN_PROGRESS = 1
#     SOLVED = 2
# 
#     PROGRESS_CHOICES = (
#         (NOT_STARTED, 'Not Started'),
#         (IN_PROGRESS, 'In Progress'),
#         (SOLVED, 'Solved')
#     )
# 
#     name = models.CharField('Name', max_length=255)
#     slug = models.SlugField()
#     progress = models.PositiveSmallIntegerField(choices=PROGRESS_CHOICES)
#     num_progress = models.FloatField('Progress %', default=0)
#     point_value = models.FloatField(default=0)
# 
#     competition = models.ForeignKey(Competition, related_name='challenges')
#     last_viewed = models.DateTimeField(auto_created=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     __str__ = __unicode__
# 
#     def get_absolute_url(self):
#         return reverse('view_challenge', kwargs={'ctf_slug': self.competition.slug, 'chall_slug': self.slug})
# 
#     def last_viewed_display(self):
#         if self.last_viewed == 0:
#             return 'Never'
#         else:
#             return self.last_viewed
# 
#     class Meta:
#         unique_together = ('name', 'competition')
#         ordering = ('progress',)
# 
# class ChallengeFile(models.Model):
#     file = models.FileField(upload_to='files/')
#     ctime = models.DateTimeField(auto_created=True)
#     mtime = models.DateTimeField(auto_now=True)
#     challenge = models.ForeignKey(Challenge, related_name='files')
# 
#     def __unicode__(self):
#         return self.file.name
# 
#     __str__ = __unicode__
# 
#     def filename(self):
#         return os.path.basename(self.file.name)


# Path: competition/admin.py
from django.contrib import admin
from competition.models import Competition, Challenge, ChallengeFile


# Register your models here.


class CompetitionAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name',)}

    class Meta:
        model = Competition


class ChallengeAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('name',)}

    class Meta:
        model = Challenge


admin.site.register(Competition, CompetitionAdmin)