Skip to content

Instantly share code, notes, and snippets.

@rogaha
Created April 16, 2014 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogaha/10923560 to your computer and use it in GitHub Desktop.
Save rogaha/10923560 to your computer and use it in GitHub Desktop.
EXCEPTION = -2
ERROR = -1
PENDING = 0
CLAIMED = 1
STARTED = 2
CLONED = 3
README = 4
DOCKERFILE = 5
BUILT = 6
BUNDLED = 7
UPLOADED = 8
PUSHED = 9
FINISHED = 10
BUILD_STATUS = (
(EXCEPTION, "Error"),
(ERROR, "Error"),
(PENDING, "Pending"),
(CLAIMED, "Building"),
(STARTED, "Building"),
(CLONED, "Building"),
(README, "Building"),
(DOCKERFILE, "Building"),
(BUILT, "Building"),
(BUNDLED, "Building"),
(UPLOADED, "Pushing"),
(PUSHED, "Pushing"),
(FINISHED, "Finished")
)
build = models.ForeignKey(Build)
highland_build_code = models.CharField(max_length=50, blank=True, null=True)
source_build_url = models.CharField(max_length=200, blank=True, null=True)
status = models.IntegerField(choices=BUILD_STATUS, default=PENDING)
created_date = models.DateTimeField(default=timezone.now)
last_updated = models.DateTimeField(auto_now=True)
@rogaha
Copy link
Author

rogaha commented Apr 16, 2014

@property
def grouped_status(self):
    """
    Converts the status values into the following groups:
    (-2,-1) -> Error
    (0)     -> Pending
    (1-7)   -> Building
    (8-9)   -> Pushing
    (10)    -> Finished
    """
    if self.status == 0:
        return "Pending"
    elif -2 <= self.status <= -1:
        return "Error"
    elif 0 < self.status < 8:
        return "Pending"
    elif 8 <= self.status <= 9:
        return "Building"
    elif self.status == 10:
        return "Finished"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment