Revision 39462ae0 snf-quotaholder-app/quotaholder_django/quotaholder_app/models.py
b/snf-quotaholder-app/quotaholder_django/quotaholder_app/models.py | ||
---|---|---|
34 | 34 |
|
35 | 35 |
from synnefo.lib.commissioning import CorruptedError |
36 | 36 |
|
37 |
from django.core import exceptions |
|
37 | 38 |
from django.db.models import (Model, BigIntegerField, CharField, |
39 |
IntegerField, SubfieldBase, |
|
38 | 40 |
ForeignKey, AutoField, DecimalField) |
39 | 41 |
from django.db import transaction |
40 | 42 |
from .managers import ForUpdateManager |
41 | 43 |
|
44 |
class IntDecimalField(IntegerField): |
|
45 |
|
|
46 |
__metaclass__ = SubfieldBase |
|
47 |
|
|
48 |
def __init__(self, max_digits=None, **kwargs): |
|
49 |
self.max_digits, self.decimal_places = max_digits, 0 |
|
50 |
IntegerField.__init__(self, **kwargs) |
|
51 |
|
|
52 |
def get_internal_type(self): |
|
53 |
return "DecimalField" |
|
54 |
|
|
55 |
def to_python(self, value): |
|
56 |
if value is None: |
|
57 |
return value |
|
58 |
try: |
|
59 |
return long(value) |
|
60 |
except (ValueError, TypeError): |
|
61 |
raise exceptions.ValidationError(self.error_messages['invalid']) |
|
62 |
|
|
42 | 63 |
DECIMAL_DIGITS = 38 |
43 |
QH_MAX_INT = 10**32 |
|
44 | 64 |
|
45 |
def decimalField(**kwargs):
|
|
46 |
return DecimalField(max_digits=DECIMAL_DIGITS, decimal_places=0, **kwargs)
|
|
65 |
def intDecimalField(**kwargs):
|
|
66 |
return IntDecimalField(max_digits=DECIMAL_DIGITS, **kwargs)
|
|
47 | 67 |
|
48 | 68 |
class Holder(Model): |
49 | 69 |
|
... | ... | |
65 | 85 |
class Policy(Model): |
66 | 86 |
|
67 | 87 |
policy = CharField(max_length=4096, primary_key=True) |
68 |
quantity = decimalField()
|
|
69 |
capacity = decimalField()
|
|
70 |
import_limit = decimalField()
|
|
71 |
export_limit = decimalField()
|
|
88 |
quantity = intDecimalField()
|
|
89 |
capacity = intDecimalField()
|
|
90 |
import_limit = intDecimalField()
|
|
91 |
export_limit = intDecimalField()
|
|
72 | 92 |
|
73 | 93 |
objects = ForUpdateManager() |
74 | 94 |
|
... | ... | |
80 | 100 |
policy = ForeignKey(Policy, to_field='policy') |
81 | 101 |
flags = BigIntegerField(null=False, default=0) |
82 | 102 |
|
83 |
imported = decimalField(default=0)
|
|
84 |
importing = decimalField(default=0)
|
|
85 |
exported = decimalField(default=0)
|
|
86 |
exporting = decimalField(default=0)
|
|
87 |
returned = decimalField(default=0)
|
|
88 |
returning = decimalField(default=0)
|
|
89 |
released = decimalField(default=0)
|
|
90 |
releasing = decimalField(default=0)
|
|
103 |
imported = intDecimalField(default=0)
|
|
104 |
importing = intDecimalField(default=0)
|
|
105 |
exported = intDecimalField(default=0)
|
|
106 |
exporting = intDecimalField(default=0)
|
|
107 |
returned = intDecimalField(default=0)
|
|
108 |
returning = intDecimalField(default=0)
|
|
109 |
released = intDecimalField(default=0)
|
|
110 |
releasing = intDecimalField(default=0)
|
|
91 | 111 |
|
92 | 112 |
objects = ForUpdateManager() |
93 | 113 |
|
... | ... | |
119 | 139 |
|
120 | 140 |
entity = ForeignKey(Entity, to_field='entity') |
121 | 141 |
resource = CharField(max_length=4096, null=False) |
122 |
quantity = decimalField()
|
|
142 |
quantity = intDecimalField()
|
|
123 | 143 |
|
124 | 144 |
objects = ForUpdateManager() |
125 | 145 |
|
... | ... | |
132 | 152 |
issue_time = CharField(max_length=4096) |
133 | 153 |
log_time = CharField(max_length=4096) |
134 | 154 |
resource = CharField(max_length=4096) |
135 |
source_quantity = decimalField()
|
|
136 |
source_capacity = decimalField()
|
|
137 |
source_import_limit = decimalField()
|
|
138 |
source_export_limit = decimalField()
|
|
139 |
source_imported = decimalField()
|
|
140 |
source_exported = decimalField()
|
|
141 |
source_returned = decimalField()
|
|
142 |
source_released = decimalField()
|
|
143 |
target_quantity = decimalField()
|
|
144 |
target_capacity = decimalField()
|
|
145 |
target_import_limit = decimalField()
|
|
146 |
target_export_limit = decimalField()
|
|
147 |
target_imported = decimalField()
|
|
148 |
target_exported = decimalField()
|
|
149 |
target_returned = decimalField()
|
|
150 |
target_released = decimalField()
|
|
151 |
delta_quantity = decimalField()
|
|
155 |
source_quantity = intDecimalField()
|
|
156 |
source_capacity = intDecimalField()
|
|
157 |
source_import_limit = intDecimalField()
|
|
158 |
source_export_limit = intDecimalField()
|
|
159 |
source_imported = intDecimalField()
|
|
160 |
source_exported = intDecimalField()
|
|
161 |
source_returned = intDecimalField()
|
|
162 |
source_released = intDecimalField()
|
|
163 |
target_quantity = intDecimalField()
|
|
164 |
target_capacity = intDecimalField()
|
|
165 |
target_import_limit = intDecimalField()
|
|
166 |
target_export_limit = intDecimalField()
|
|
167 |
target_imported = intDecimalField()
|
|
168 |
target_exported = intDecimalField()
|
|
169 |
target_returned = intDecimalField()
|
|
170 |
target_released = intDecimalField()
|
|
171 |
delta_quantity = intDecimalField()
|
|
152 | 172 |
reason = CharField(max_length=4096) |
153 | 173 |
|
154 | 174 |
objects = ForUpdateManager() |
Also available in: Unified diff