Esempio n. 1
0
def get_user(user, name, app=None, raise_error=True):
    """Return a parameter for a specific user

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param ``User`` user: the desired user
    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value as a string
    """
    from .models import UserParameter

    if app is None:
        app = guess_extension_name()
    try:
        __is_defined(app, "U", name)
    except NotDefined:
        if raise_error:
            raise
        return None
    try:
        p = UserParameter.objects.get(user=user, name="%s.%s" % (app, name))
    except UserParameter.DoesNotExist:
        return _params["U"][app]["defaults"][name]
    return p.value.decode("unicode_escape")
Esempio n. 2
0
def get_user(user, name, app=None, raise_error=True):
    """Return a parameter for a specific user

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param ``User`` user: the desired user
    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value as a string
    """
    from .models import UserParameter

    if app is None:
        app = guess_extension_name()
    try:
        __is_defined(app, "U", name)
    except NotDefined:
        if raise_error:
            raise
        return None
    try:
        p = UserParameter.objects.get(user=user, name="%s.%s" % (app, name))
    except UserParameter.DoesNotExist:
        return _params["U"][app]["defaults"][name]
    return p.value.decode("unicode_escape")
Esempio n. 3
0
 def get_values(self, app=None):
     """Return all values for the given level/app."""
     if app is None:
         app = guess_extension_name()
     values = registry.get_defaults(self._level, app)
     for parameter, value in list(values.items()):
         if app in self._parameters:
             value = self._parameters[app].get(parameter, value)
         yield (parameter, value)
Esempio n. 4
0
 def get_values(self, app=None):
     """Return all values for the given level/app."""
     if app is None:
         app = guess_extension_name()
     values = registry.get_defaults(self._level, app)
     for parameter, value in list(values.items()):
         if app in self._parameters:
             value = self._parameters[app].get(parameter, value)
         yield (parameter, value)
Esempio n. 5
0
 def get_values_dict(self, app=None):
     """Return all values for the given app as a dictionary."""
     if app is None:
         app = guess_extension_name()
     values = registry.get_defaults(self._level, app)
     for parameter, value in list(values.items()):
         if app in self._parameters:
             values[parameter] = self._parameters[app].get(parameter, value)
     return values
Esempio n. 6
0
 def set_value(self, parameter, value, app=None):
     """Set parameter for the given app."""
     if app is None:
         app = guess_extension_name()
     if not registry.exists(self._level, app, parameter):
         raise NotDefined(app, parameter)
     if app not in self._parameters:
         self._parameters[app] = copy.deepcopy(
             registry.get_defaults(self._level, app))
     self._parameters[app][parameter] = value
Esempio n. 7
0
 def set_values(self, values, app=None):
     """Set/update values for the given app."""
     if app is None:
         app = guess_extension_name()
     if not registry.exists(self._level, app):
         raise NotDefined(app)
     if app not in self._parameters:
         self._parameters[app] = copy.deepcopy(
             registry.get_defaults(self._level, app))
     self._parameters[app].update(values)
Esempio n. 8
0
 def set_values(self, values, app=None):
     """Set/update values for the given app."""
     if app is None:
         app = guess_extension_name()
     if not registry.exists(self._level, app):
         raise NotDefined(app)
     if app not in self._parameters:
         self._parameters[app] = copy.deepcopy(
             registry.get_defaults(self._level, app))
     self._parameters[app].update(values)
Esempio n. 9
0
 def set_value(self, parameter, value, app=None):
     """Set parameter for the given app."""
     if app is None:
         app = guess_extension_name()
     if not registry.exists(self._level, app, parameter):
         raise NotDefined(app, parameter)
     if app not in self._parameters:
         self._parameters[app] = copy.deepcopy(
             registry.get_defaults(self._level, app))
     self._parameters[app][parameter] = value
Esempio n. 10
0
def unregister_extension(extension=None):
    """Unregister all callbacks declared by an extension.

    :param str extension: extension full name (ie. module name)
    """
    if extension is None:
        extension = guess_extension_name()
    for evt, values in callbacks.items():
        for name in values.keys():
            if extension in name:
                del callbacks[evt][name]
Esempio n. 11
0
def unregister_extension(extension=None):
    """Unregister all callbacks declared by an extension.

    :param str extension: extension full name (ie. module name)
    """
    if extension is None:
        extension = guess_extension_name()
    for evt, values in callbacks.items():
        for name in values.keys():
            if extension in name:
                del callbacks[evt][name]
Esempio n. 12
0
def get_parameter_form(level, name, app=None):
    """Return the form containing a specific parameter

    :param string level: associated level
    :param string name: paremeter's name
    :param string app: parameter's application
    :return: a form class
    """
    if app is None:
        app = guess_extension_name()
    __is_defined(app, level, name)
    return _params[level][app]["form"]
Esempio n. 13
0
def get_parameter_form(level, name, app=None):
    """Return the form containing a specific parameter

    :param string level: associated level
    :param string name: paremeter's name
    :param string app: parameter's application
    :return: a form class
    """
    if app is None:
        app = guess_extension_name()
    __is_defined(app, level, name)
    return _params[level][app]["form"]
Esempio n. 14
0
def unregister(app=None):
    """Unregister an application

    All parameters associated to this application will also be
    removed.

    :param app: the application's name (string)
    """
    if app is None:
        app = guess_extension_name()
    for lvlparams in _params.values():
        if app in lvlparams:
            del lvlparams[app]
Esempio n. 15
0
def unregister(app=None):
    """Unregister an application

    All parameters associated to this application will also be
    removed.

    :param app: the application's name (string)
    """
    if app is None:
        app = guess_extension_name()
    for lvlparams in _params.values():
        if app in lvlparams:
            del lvlparams[app]
Esempio n. 16
0
def save_admin(name, value, app=None):
    from .models import Parameter

    if app is None:
        app = guess_extension_name()
    __is_defined(app, 'A', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = Parameter.objects.get(name=fullname)
    except Parameter.DoesNotExist:
        p = Parameter()
        p.name = fullname
        p.value = None
    f = get_parameter_form('A', name, app)
    f()._save_parameter(p, name, value)
Esempio n. 17
0
def save_user(user, name, value, app=None):
    from .models import UserParameter

    if app is None:
        app = guess_extension_name()
    __is_defined(app, 'U', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = UserParameter.objects.get(user=user, name=fullname)
    except UserParameter.DoesNotExist:
        p = UserParameter()
        p.user = user
        p.name = fullname
    f = get_parameter_form('U', name, app)
    f()._save_parameter(p, name, value)
Esempio n. 18
0
def save_user(user, name, value, app=None):
    from .models import UserParameter

    if app is None:
        app = guess_extension_name()
    __is_defined(app, 'U', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = UserParameter.objects.get(user=user, name=fullname)
    except UserParameter.DoesNotExist:
        p = UserParameter()
        p.user = user
        p.name = fullname
    f = get_parameter_form('U', name, app)
    f()._save_parameter(p, name, value)
Esempio n. 19
0
def get_global_parameter(name, app=None, **kwargs):
    """Retrieve a global parameter.

    This is a shortcut to use when a LocalConfig instance is not
    available (ie. when no request object is available).

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value
    """
    if app is None:
        app = guess_extension_name()
    return get_localconfig().parameters.get_value(name, app=app, **kwargs)
Esempio n. 20
0
 def get_value(self, parameter, app=None, raise_exception=True):
     """Return the value associated to the specified parameter."""
     if app is None:
         app = guess_extension_name()
     # Compat. with the old way...
     parameter = parameter.lower()
     try:
         default = registry.get_default(self._level, app, parameter)
     except NotDefined:
         if raise_exception:
             raise
         return None
     if app in self._parameters:
         return self._parameters[app].get(parameter, default)
     return default
Esempio n. 21
0
 def get_value(self, parameter, app=None, raise_exception=True):
     """Return the value associated to the specified parameter."""
     if app is None:
         app = guess_extension_name()
     # Compat. with the old way...
     parameter = parameter.lower()
     try:
         default = registry.get_default(self._level, app, parameter)
     except NotDefined:
         if raise_exception:
             raise
         return None
     if app in self._parameters:
         return self._parameters[app].get(parameter, default)
     return default
Esempio n. 22
0
def get_global_parameter(name, app=None, **kwargs):
    """Retrieve a global parameter.

    This is a shortcut to use when a LocalConfig instance is not
    available (ie. when no request object is available).

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value
    """
    if app is None:
        app = guess_extension_name()
    return get_localconfig().parameters.get_value(name, app=app, **kwargs)
Esempio n. 23
0
def save_admin(name, value, app=None):
    from .models import Parameter

    if app is None:
        app = guess_extension_name()
    __is_defined(app, 'A', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = Parameter.objects.get(name=fullname)
    except Parameter.DoesNotExist:
        p = Parameter()
        p.name = fullname
        p.value = None
    f = get_parameter_form('A', name, app)
    f()._save_parameter(p, name, value)
Esempio n. 24
0
def get_admin(name, app=None, raise_error=True):
    """Return an administrative parameter

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value as a string
    """
    from .models import Parameter

    if app is None:
        app = guess_extension_name()
    try:
        __is_defined(app, "A", name)
    except NotDefined:
        if raise_error:
            raise
        return None
    try:
        p = Parameter.objects.get(name="%s.%s" % (app, name))
    except Parameter.DoesNotExist:
        return _params["A"][app]["defaults"][name]
    return p.value.decode("unicode_escape").replace('\\r\\n', '\n')
Esempio n. 25
0
def get_admin(name, app=None, raise_error=True):
    """Return an administrative parameter

    A ``NotDefined`` exception if the parameter doesn't exist.

    :param name: the parameter's name
    :param app: the application owning the parameter
    :return: the corresponding value as a string
    """
    from .models import Parameter

    if app is None:
        app = guess_extension_name()
    try:
        __is_defined(app, "A", name)
    except NotDefined:
        if raise_error:
            raise
        return None
    try:
        p = Parameter.objects.get(name="%s.%s" % (app, name))
    except Parameter.DoesNotExist:
        return _params["A"][app]["defaults"][name]
    return p.value.decode("unicode_escape").replace('\\r\\n', '\n')