示例#1
0
def set_quota(quotas):
    holding_keys = [key for (key, limit) in quotas]
    holdings = _get_holdings_for_update(holding_keys)

    for key, limit in quotas:
        try:
            h = holdings[key]
        except KeyError:
            holder, source, resource = key
            h = Holding(holder=holder, source=source, resource=resource)
        h.limit = limit
        h.save()
        holdings[key] = h
示例#2
0
def set_quota(quotas):
    holding_keys = [key for (key, limit) in quotas]
    holdings = _get_holdings_for_update(holding_keys)

    for key, limit in quotas:
        try:
            h = holdings[key]
        except KeyError:
            holder, source, resource = key
            h = Holding(holder=holder,
                        source=source,
                        resource=resource)
        h.limit = limit
        h.save()
        holdings[key] = h
示例#3
0
def set_quota(quotas, resource=None):
    holding_keys = [key for (key, limit) in quotas]
    holdings = _get_holdings_for_update(holding_keys,
                                        resource=resource,
                                        delete=True)

    new_holdings = {}
    for key, limit in quotas:
        holder, source, res = key
        if resource is not None and resource != res:
            continue
        h = Holding(holder=holder, source=source, resource=res, limit=limit)
        try:
            h_old = holdings[key]
            h.usage_min = h_old.usage_min
            h.usage_max = h_old.usage_max
            h.id = h_old.id
        except KeyError:
            pass
        new_holdings[key] = h

    Holding.objects.bulk_create(new_holdings.values())
示例#4
0
def set_quota(quotas, resource=None):
    holding_keys = [key for (key, limit) in quotas]
    holdings = _get_holdings_for_update(
        holding_keys, resource=resource, delete=True)

    new_holdings = {}
    for key, limit in quotas:
        holder, source, res = key
        if resource is not None and resource != res:
            continue
        h = Holding(holder=holder,
                    source=source,
                    resource=res,
                    limit=limit)
        try:
            h_old = holdings[key]
            h.usage_min = h_old.usage_min
            h.usage_max = h_old.usage_max
            h.id = h_old.id
        except KeyError:
            pass
        new_holdings[key] = h

    Holding.objects.bulk_create(new_holdings.values())