# Copyright (c) 2018 Red Hat, Inc.
#
# This file is part of ARA Records Ansible.
#
# ARA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ARA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ARA. If not, see .
from django.db import models
from django.utils import timezone
class Base(models.Model):
"""
Abstract base model part of every model
"""
class Meta:
abstract = True
id = models.BigAutoField(primary_key=True, editable=False)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Duration(Base):
"""
Abstract model for models with a concept of duration
"""
class Meta:
abstract = True
started = models.DateTimeField(default=timezone.now)
ended = models.DateTimeField(blank=True, null=True)
duration = models.DurationField(blank=True, null=True)
def save(self, *args, **kwargs):
# Compute duration based on available timestamps
if self.ended is not None:
self.duration = self.ended - self.started
return super(Duration, self).save(*args, **kwargs)
class Label(Base):
"""
A label is a generic container meant to group or correlate different
playbooks. It could be a single playbook run. It could be a "group" of
playbooks.
It could represent phases or dynamic logical grouping and tagging of
playbook runs.
You could have a label named "failures" and make it so failed playbooks
are added to this report, for example.
The main purpose of this is to make the labels customizable by the user.
"""
class Meta:
db_table = "labels"
name = models.CharField(max_length=255, unique=True)
def __str__(self):
return "