3
3
from collections import OrderedDict
5
from django.conf import settings
6
from django.core.exceptions import ValidationError
5
7
from django.db import models
6
8
from django.utils.encoding import python_2_unicode_compatible
7
from django.conf import settings
9
10
from jenkins.models import Artifact, Build
10
11
from credentials.models import SshKeyPair, SwiftCredential
49
50
default = models.BooleanField(default=False)
50
51
base_url = models.CharField(max_length=200, blank=True, default="")
55
Overrides the model validation after each field had been verified,
56
as this is the only place where we can run multi-field checks.
58
The downside of these validations is that if we eventually
59
create more network transports in the model we'll have to
60
manually add them to these checks, but I can't see a better
61
way to validate them at the moment directly in the model.
63
if ("local" not in self.transport
64
and self.ssh_credentials is None
65
and self.swift_credentials is None):
66
alert = ("Credentials are required if the selected "
67
"transport is not local.")
68
raise ValidationError(alert)
70
if "swift" in self.transport and self.swift_credentials is None:
71
alert = ("Missing set of Swift credentials, "
72
"please create/select one.")
73
raise ValidationError(alert)
75
if "ssh" in self.transport and self.ssh_credentials is None:
76
alert = ("Missing set of SSH credentials, "
77
"please create/select one.")
78
raise ValidationError(alert)
53
81
return "{name} default: {default}".format(name=self.name,
54
82
default=self.default)