Beispiel #1
0
 class Quotas(quotas_models.QuotaModelMixin.Quotas):
     counter_quota = fields.CounterQuotaField(
         target_models=lambda: [ChildModel],
         path_to_scope='parent',
     )
     two_targets_counter_quota = fields.CounterQuotaField(
         target_models=lambda: [ChildModel, SecondChildModel],
         path_to_scope='parent',
     )
     delta_quota = fields.CounterQuotaField(
         target_models=lambda: [ChildModel],
         path_to_scope='parent',
         get_delta=lambda scope: 10
     )
     usage_aggregator_quota = fields.UsageAggregatorQuotaField(
         get_children=lambda scope: scope.children.all(),
     )
     limit_aggregator_quota = fields.LimitAggregatorQuotaField(
         get_children=lambda scope: scope.children.all(),
         default_limit=0,
     )
     second_usage_aggregator_quota = fields.UsageAggregatorQuotaField(
         get_children=lambda scope: scope.children.all(),
         child_quota_name='usage_aggregator_quota',
     )
     total_quota = fields.TotalQuotaField(
         target_models=lambda: [SecondChildModel],
         path_to_scope='parent',
         target_field='size',
     )
Beispiel #2
0
 class Quotas(quotas_models.QuotaModelMixin.Quotas):
     regular_quota = fields.QuotaField()
     quota_with_default_limit = fields.QuotaField(default_limit=100)
     usage_aggregator_quota = fields.UsageAggregatorQuotaField(
         get_children=lambda scope: ChildModel.objects.filter(parent__parent
                                                              =scope), )
     limit_aggregator_quota = fields.LimitAggregatorQuotaField(
         get_children=lambda scope: ChildModel.objects.filter(parent__parent
                                                              =scope), )
Beispiel #3
0
def inject_tenant_quotas():
    for model in TENANT_PATHS:
        for (quota_name, child_quota_name) in TENANT_QUOTAS:

            def get_children(scope):
                path = TENANT_PATHS[type(scope)]
                return models.Tenant.objects.filter(**{path: scope})

            model.add_quota_field(
                name=quota_name,
                quota_field=quota_fields.UsageAggregatorQuotaField(
                    get_children=get_children,
                    child_quota_name=child_quota_name,
                ))