dnmgmt/rrequests/models.py

53 lines
1.4 KiB
Python
Raw Normal View History

2017-03-14 20:18:57 +01:00
from django.db import models
from django.urls import reverse
from whoisdb.models import Maintainer
class Request(models.Model):
STATE_OPEN = "OPEN"
STATE_RESOLVED = "RESOLVED"
STATE_REJECTED = "REJECTED"
STATES = (
(STATE_OPEN, 'Open'),
(STATE_RESOLVED, 'Resolved'),
(STATE_REJECTED, 'Rejected'),
)
# request goes to mnt?
subject = models.CharField(max_length=200)
status = models.CharField(max_length=16, choices=STATES)
applicant = models.ForeignKey(Maintainer)
provider = models.ForeignKey(Maintainer, related_name='requestfrom_set')
requestResources = models.TextField()
grantedResources = models.TextField()
created = models.DateTimeField(auto_now_add=True)
lastAction = models.DateTimeField(auto_now_add=True)
def get_absolute_url(self):
return reverse("rrequests:show", args=(self.pk,))
def __str__(self):
2017-03-20 00:16:33 +01:00
return "(%s -> %s) [%s] %s" % (self.applicant, self.provider, self.status, self.subject)
2017-03-14 20:18:57 +01:00
def getLastActionBy(self):
msgs = self.requestmessage_set.order_by("-created")
if msgs.count() > 0:
return msgs[0].creator
else:
return None
2017-03-14 20:18:57 +01:00
class RequestMessage(models.Model):
request = models.ForeignKey(Request)
statusChanged = models.CharField(max_length=16, choices=Request.STATES, default=None, null=True, blank=True)
creator = models.ForeignKey(Maintainer)
message = models.TextField()
created = models.DateTimeField(auto_now_add=True)