Revision ae16bcad snf-astakos-app/astakos/im/quotas.py

b/snf-astakos-app/astakos/im/quotas.py
35 35
    Resource, AstakosUserQuota, AstakosUser,
36 36
    Project, ProjectMembership, ProjectResourceGrant, ProjectApplication)
37 37
from astakos.quotaholder.callpoint import QuotaholderDjangoDBCallpoint
38
from django.db.models import Q
38 39

  
39 40
qh = QuotaholderDjangoDBCallpoint()
40 41

  
......
248 249

  
249 250

  
250 251
def qh_add_resource_limit(resource, diff):
251
    users = AstakosUser.forupdate.all().select_for_update()
252
    qh.add_resource_limit(SYSTEM, resource, diff)
252
    objs = AstakosUser.forupdate.filter(Q(email_verified=True) &
253
                                        ~Q(policy=resource))
254
    users = objs.select_for_update()
255
    uuids = [u.uuid for u in users]
256
    qh.add_resource_limit(holders=uuids, sources=[SYSTEM],
257
                          resources=[resource.name], diff=diff)
253 258

  
254 259

  
255 260
def qh_sync_new_resource(resource, limit):
256 261
    users = AstakosUser.forupdate.filter(
257 262
        email_verified=True).select_for_update()
258 263

  
264
    resource_name = resource.name
259 265
    data = []
260 266
    for user in users:
261 267
        uuid = user.uuid
262
        key = uuid, SYSTEM, resource
268
        key = uuid, SYSTEM, resource_name
263 269
        data.append((key, limit))
264 270

  
265 271
    qh.set_quota(data)

Also available in: Unified diff