forked from cfpb/django-nudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
59 lines (40 loc) · 1.77 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from django.db import models
from reversion.models import Version
from exceptions import *
class Setting(models.Model):
local_address = models.CharField(max_length=255, null=True, blank=True)
local_key = models.CharField(max_length=255, null=True, blank=True)
remote_address = models.CharField(max_length=255, null=True, blank=True)
remote_key = models.CharField(max_length=255, null=True, blank=True)
class Batch(models.Model):
title = models.TextField(max_length=255)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
pushed = models.DateTimeField(null=True, blank=True)
def __unicode__(self):
return u'%s' % self.title
def is_valid(self, test_only=True):
for batchitem in self.batchitem_set.all():
valid=True
other_batches=batchitem.version.batchitem_set.exclude(batch=self)
if other_batches.count() > 0:
if test_only:
valid=False
else:
raise BatchValidationError
return valid
class Meta:
verbose_name_plural = "batches"
permissions = (
("push_batch", "Can push batches"),
)
class PushHistoryItem(models.Model):
batch=models.ForeignKey(Batch, on_delete=models.PROTECT)
created=models.DateTimeField(auto_now_add=True)
http_result=models.IntegerField(blank=True, null=True)
class BatchItem(models.Model):
object_id = models.IntegerField()
version = models.ForeignKey(Version)
batch = models.ForeignKey(Batch)
def __unicode__(self):
return u'%s' % self.version.object_repr