Commit 3ff801eb authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Simplify set_quota implementation

parent dca66ad0
...@@ -446,27 +446,11 @@ class QuotaholderDjangoDBCallpoint(Callpoint): ...@@ -446,27 +446,11 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
quantity, capacity, quantity, capacity,
import_limit, export_limit, flags ) in set_quota: import_limit, export_limit, flags ) in set_quota:
p = None
try: try:
h = Holding.objects.get(entity=entity, resource=resource) e = Entity.objects.get(entity=entity, key=key)
if h.entity.key != key: except Entity.DoesNotExist:
append((entity, resource)) append((entity, resource))
continue continue
p = h.policy
except Holding.DoesNotExist:
try:
e = Entity.objects.get(entity=entity)
except Entity.DoesNotExist:
append((entity, resource))
continue
if e.key != key:
append((entity, resource))
continue
h = None
policy = newname('policy_') policy = newname('policy_')
newp = Policy ( newp = Policy (
...@@ -477,12 +461,15 @@ class QuotaholderDjangoDBCallpoint(Callpoint): ...@@ -477,12 +461,15 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
export_limit=export_limit export_limit=export_limit
) )
if h is None: try:
h = Holding(entity=e, resource=resource, h = Holding.objects.get(entity=entity, resource=resource)
policy=newp, flags=flags) p = h.policy
else:
h.policy = newp h.policy = newp
h.flags = flags h.flags = flags
except Holding.DoesNotExist:
h = Holding(entity=e, resource=resource,
policy=newp, flags=flags)
p = None
# the order is intentionally reversed so that it # the order is intentionally reversed so that it
# would break if we are not within a transaction. # would break if we are not within a transaction.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment