Files
modoboa/modoboa/limits/utils.py
T
Andrew Fyfe f71414ddfa add missing utf8 header
use `# -*- coding: utf-8 -*-` which is more widely supported by editors
2018-02-03 00:59:08 +00:00

33 lines
903 B
Python

# -*- coding: utf-8 -*-
"""Modoboa limits utilities."""
from __future__ import unicode_literals
from . import constants
def get_user_limit_templates():
"""Return defined templates."""
return list(constants.DEFAULT_USER_LIMITS.items())
def get_domain_limit_templates():
"""Return defined templates."""
return list(constants.DEFAULT_DOMAIN_LIMITS.items())
def move_pool_resource(owner, user):
"""Move resource from one pool to another.
When an account doesn't need a pool anymore, we move the
associated resource to the pool of its owner.
"""
for name, _definition in get_user_limit_templates():
user_limit = user.userobjectlimit_set.get(name=name)
if user_limit.max_value < 0:
continue
owner_limit = owner.userobjectlimit_set.get(name=name)
owner_limit.max_value += user_limit.max_value
owner_limit.save()