Revision 39462ae0

b/snf-common/synnefo/lib/quotaholder/api/__init__.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from .quotaholder import QuotaholderAPI
34
from .quotaholder import QuotaholderAPI, QH_PRACTICALLY_INFINITE
35 35
from .exception import ( InvalidKeyError, NoEntityError,
36 36
                         NoQuantityError, NoCapacityError,
37 37
                         ExportLimitError, ImportLimitError,
b/snf-common/synnefo/lib/quotaholder/api/quotaholder.py
59 59
    def init(self):
60 60
        self.opts.update({'minimum': 1})
61 61

  
62
QH_PRACTICALLY_INFINITE =   10**32
63

  
62 64
Serial              =   Positive(classname='Serial')
63 65

  
64 66
ClientKey           =   Name(classname='ClientKey')
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()
b/snf-quotaholder-app/quotaholder_django/test/simpletests.py
252 252

  
253 253
        r = self.qh.get_quota(get_quota=[(e0, resource0, k0),
254 254
                                         (e0, resource1, k0)])
255
        self.assertEqual(r, [(e0, resource0, 5, 3, QH_MAX_INT, 5)
255
        self.assertEqual(r, [(e0, resource0, 5, 3, QH_MAX_INT+4, 5)
256 256
                             + DEFAULT_HOLDING + (0,),
257 257
                             (e0, resource1, 0, QH_MAX_INT, 5, 5)
258 258
                             + DEFAULT_HOLDING + (0,)])
......
422 422
        if r:
423 423
            raise AssertionError("cannot create entities")
424 424

  
425
        self.qh.set_quota(set_quota=[(sys, resource, '', 10, 0, None, None, 0),
426
                                     (e0, resource, k0, 0, 10, None, None, 0),
427
                                     (e1, resource, k1, 0, 10, None, None, 0)])
425
        self.qh.set_quota(set_quota=[(sys, resource, '', 10, 0, QH_MAX_INT, QH_MAX_INT, 0),
426
                                     (e0, resource, k0, 0, 10, QH_MAX_INT, QH_MAX_INT, 0),
427
                                     (e1, resource, k1, 0, 10, QH_MAX_INT, QH_MAX_INT, 0)])
428 428

  
429 429
        s0 = self.qh.issue_commission(clientkey=self.client, target=e0, key=k0,
430 430
                                      name='a commission',

Also available in: Unified diff