class Project(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) name = models.TextField(db_index=True, unique=True) created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) def __str__(self): return self.name def get_absolute_url(self): return reverse('project-detail', kwargs={'name': self.name}) @cached_property def last_check(self): try: return self.checks.exclude(finished_at=None).latest('finished_at') except (Check.DoesNotExist, IndexError): return None def check(self, delay=True): from .tasks import run_check check = Check(project=self, public=False, requirements=[self.name], projects=[self.name]) check.full_clean() check.save() if delay: run_check.delay(check.pk) else: run_check(check.pk)
class Author(models.Model): name = models.CharField(max_length=75) uuid = models.UUIDField(null=True) books = models.ArrayField(of=BookField) data = models.JSONField(default=None) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)
class Check(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) unblocked = models.SmallIntegerField(default=0) created_at = models.DateTimeField(default=now) started_at = models.DateTimeField(null=True, blank=True) finished_at = models.DateTimeField(null=True, blank=True) requirements = models.ArrayField(models.TextField()) projects = models.ArrayField(models.CharField(max_length=255)) blockers = models.JSONField() public = models.BooleanField(default=True) runs = models.SmallIntegerField(default=0) project = models.ForeignKey(Project, related_name='checks', null=True, blank=True) class Meta: ordering = ('-finished_at',) def __str__(self): return str(self.id) def get_absolute_url(self): return reverse('check-detail', kwargs={'pk': str(self.pk)}) def clean(self): projects = OrderedDict() # using this since sets aren't ordered for requirement in self.requirements: url = urlparse(requirement) if url.scheme in ('http', 'https', 'file'): requirement = [sanitize_github_url(requirement, url)] try: for project in projects_from_requirements(requirement): projects[project] = None except: raise ValidationError("Couldn't check %s." % requirement) else: projects[requirement] = None self.projects = list(projects.keys()) for index, project_name in enumerate(self.projects): validators.RegexValidator(project_name_re, 'Project %s invalid' % project_name)(project_name)
class SourceInfo(models.Model): ''' Contains source information ''' id = models.AutoField(primary_key=True) contributor = models.CharField(max_length=200) license = models.CharField(max_length=200) date = models.DateTimeField(default=datetime.now) info = models.JSONField(type=dict, default={}) def __str__(self): return '%s under %s license' % (self.contributor, self.license)
class Task(models.Model): source = models.ForeignKey(Document) status = models.CharField(max_length=12, choices=[ (x,x) for x in ( 'completed', 'in progress', 'available', 'on hold') ]) task_group = models.ForeignKey('TaskGroup') date_completed = models.DateTimeField(null=True,blank=True) user = models.ForeignKey(User) data = models.JSONField(null=True,blank=True)
class Hobbit(models.Model): name = models.CharField(max_length=50) favorite_foods = models.ArrayField(models.CharField(max_length=100)) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)
class Elf(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) name = models.CharField(max_length=50) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)