Anton Shestakov <av6@dwimlabs.net>, Thu, 16 Jun 2016 07:31:39 +0800
viewer: use new get_duration() method to format time taken by a check
candolint/models.py
Permissions: -rw-r--r--
database = pw.SqliteDatabase(None, journal_mode='WAL') class BaseModel(pw.Model): def create_or_get(cls, **kwargs): with cls._meta.database.atomic(): return cls.create(**kwargs), True except pw.IntegrityError: # a variation on https://github.com/coleifer/peewee/pull/681 for field_names, unique in cls._meta.indexes: compound_unique.update(field_names) for field_name, value in kwargs.items(): field = getattr(cls, field_name) if field.unique or field.primary_key or field_name in compound_unique: query.append(field == value) return cls.get(*query), False class Project(BaseModel): url = pw.CharField(unique=True) user = pw.CharField(null=True) (('domain', 'user', 'name'), True), def get_url(self, request=None): base = '{}://{}'.format(request.protocol, request.host) return base + self.get_url() user = self.user if self.user is not None else '-' return '/{}/{}/{}'.format(self.domain, user, self.name) date = pw.DateTimeField() project = pw.ForeignKeyField(Project, related_name='changes') (('rev', 'node', 'project'), True), ordinal = pw.IntegerField() errors = pw.IntegerField() warnings = pw.IntegerField() success = pw.BooleanField() started = pw.DateTimeField() finished = pw.DateTimeField() project = pw.ForeignKeyField(Project, related_name='checks') change = pw.ForeignKeyField(Change, related_name='checks') order_by = ('-finished', '-ordinal') (('ordinal', 'project'), True), def get_url(self, request=None): return '{}/{}'.format(self.project.get_url(request), self.ordinal) d = self.finished - self.started minutes, seconds = divmod(int(d.total_seconds()), 60) return '{} min {} sec'.format(minutes, seconds) return '{} sec'.format(seconds)