dnmgmt/rrequests/models.py

57 lines
1.7 KiB
Python
Raw Normal View History

2018-01-17 00:23:00 +01:00
# This file is part of dnmgmt, a number resource management system
# Licensed under GNU General Public License v3 or later
# Written by Sebastian Lohff (seba@someserver.de)
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):
2019-05-30 22:10:55 +02:00
STATE_OPEN = "OPEN"
STATE_RESOLVED = "RESOLVED"
STATE_REJECTED = "REJECTED"
STATES = (
(STATE_OPEN, 'Open'),
(STATE_RESOLVED, 'Resolved'),
(STATE_REJECTED, 'Rejected'),
)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
# request goes to mnt?
subject = models.CharField(max_length=200)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
status = models.CharField(max_length=16, choices=STATES)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
applicant = models.ForeignKey(Maintainer)
provider = models.ForeignKey(Maintainer, related_name='requestfrom_set')
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
requestResources = models.TextField()
grantedResources = models.TextField()
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
created = models.DateTimeField(auto_now_add=True)
lastAction = models.DateTimeField(auto_now_add=True)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
def get_absolute_url(self):
return reverse("rrequests:show", args=(self.pk,))
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
def __str__(self):
return "(%s -> %s) [%s] %s" % (self.applicant, self.provider, self.status, self.subject)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
def getLastActionBy(self):
msgs = self.requestmessage_set.order_by("-created")
2019-05-30 22:10:55 +02:00
if msgs.count() > 0:
return msgs[0].creator
else:
return None
2017-03-14 20:18:57 +01:00
class RequestMessage(models.Model):
2019-05-30 22:10:55 +02:00
request = models.ForeignKey(Request)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
statusChanged = models.CharField(max_length=16, choices=Request.STATES, default=None, null=True, blank=True)
2017-03-14 20:18:57 +01:00
2019-05-30 22:10:55 +02:00
creator = models.ForeignKey(Maintainer)
message = models.TextField()
created = models.DateTimeField(auto_now_add=True)