Revision eec92c03

b/commissioning/servers/quotaholder/django_backend/callpoint.py
7 7
                            ExportLimitError, ImportLimitError)
8 8

  
9 9

  
10
from commissioning.utils.newname import newname
10 11
from django.db.models import Model, BigIntegerField, CharField, ForeignKey
11 12
from django.db import transaction
12 13
from .models import Holder, Entity, Policy, Holding, Commission, Provision
......
220 221
                quantity, capacity,
221 222
                import_limit, export_limit, flags  ) in set_quota:
222 223

  
224
                p = None
225

  
223 226
                try:
224 227
                    h = Holding.objects.get(entity=entity, resource=resource)
225 228
                    if h.entity.key != key:
226 229
                        append((entity, resource))
227 230
                        continue
231
                    p = h.policy
232

  
228 233
                except Holding.DoesNotExist:
229
                    append(entity, resource)
230
                    continue
234
                    try:
235
                        e = Entity.objects.get(entity=entity)
236
                    except Entity.DoesNotExist:
237
                        append((entity, resource))
238
                        continue
231 239

  
232
                p = h.policy
233
                policy = newname()
234
                newp = Policy.objects.create    (
240
                    if e.key != key:
241
                        append((entity, resource))
242
                        continue
243

  
244
                    h = None
245

  
246
                policy = newname('policy_')
247
                newp = Policy   (
235 248
                            policy=policy,
236 249
                            quantity=quantity,
237 250
                            capacity=capacity,
......
239 252
                            export_limit=export_limit
240 253
                )
241 254

  
242
                h.policy = newp
255
                if h is None:
256
                    h = Holding(entity=entity, resource=resource,
257
                                policy=newp, flags=flags)
258
                else:
259
                    h.policy = newp
260
                    h.flags = flags
261

  
243 262
                h.save()
263
                newp.save()
244 264

  
245
                if p.holdings.count() == 0:
265
                if p is not None and p.holdings.count() == 0:
246 266
                    p.delete()
247 267

  
248 268
        return rejected
b/commissioning/utils/newname.py
1

  
2
from time import time
3

  
4
_counter = 0
5

  
6
def newname(prefix):
7
    global _counter;
8
    _counter += 1
9
    ident = id(locals())
10
    nonce = int(time() * 1000) + _counter
11
    return "%s%x%x" % (prefix, ident, nonce)
12

  

Also available in: Unified diff