Exemplo n.º 1
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Exemplo n.º 2
0
    def _get_parameter_value(self, detail):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        data = sysparam.get(detail.key, detail.type, self.store)
        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % detail.key)
            return data.get_description()
        elif detail.options:
            return detail.options[int(data)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif isinstance(data, decimal.Decimal):
            return quantize(data)
        elif detail.key == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)

        if data is None:
            return ''
        return unicode(data)
Exemplo n.º 3
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Exemplo n.º 4
0
    def _get_parameter_value(self, detail):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        data = sysparam.get(detail.key, detail.type, self.store)
        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % detail.key)
            return data.get_description()
        elif detail.options:
            return detail.options[int(data)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif isinstance(data, decimal.Decimal):
            return quantize(data)
        elif detail.key == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, str):
            # FIXME: workaround to handle locale specific data
            return _(data)

        if data is None:
            return ''
        return str(data)
Exemplo n.º 5
0
def get_countries():
    """Fetch a list of translated/untranslated countries suitable for usage
    within combo.prefill()::

    [(translated label, label), ...]

    :returns: a list of tuples
    """
    # FIXME: Get this lazely from /usr/share/xml/iso-codes/iso_3166.xml
    #        as pointed out on bug 5100.
    def cmp_func(a, b):
        return locale.strcoll(a[0], b[0])
    # We store translated country names in a set to ensure
    # there are no dupes because the combo expects that.
    items = set()
    for country in countries:
        items.add((dgettext("iso_3166", country), country))
    return locale_sorted(items, key=operator.itemgetter(0))
Exemplo n.º 6
0
 def _get_parameter_value(self, obj):
     """Given a ParameterData object, returns a string representation of
     its current value.
     """
     constant = sysparam(self.store).get_parameter_constant(obj.field_name)
     data = getattr(sysparam(self.store), obj.field_name)
     if isinstance(data, Domain):
         if not (IDescribable in providedBy(data)):
             raise TypeError(u"Parameter `%s' must implement IDescribable "
                             "interface." % obj.field_name)
         return data.get_description()
     elif constant.options:
         return constant.options[int(obj.field_value)]
     elif isinstance(data, PathParameter):
         return data.path
     elif isinstance(data, bool):
         return [_(u"No"), _(u"Yes")][data]
     elif obj.field_name == u'COUNTRY_SUGGESTED':
         return dgettext("iso_3166", data)
     elif isinstance(data, unicode):
         # FIXME: workaround to handle locale specific data
         return _(data)
     return unicode(data)
Exemplo n.º 7
0
                                     ClientCategoryPrice)
from stoqlib.domain.till import Till, TillSummary
from stoqlib.exceptions import LoginError
from stoqlib.lib.configparser import get_config
from stoqlib.lib.dateutils import (INTERVALTYPE_MONTH, create_date_interval,
                                   localnow)
from stoqlib.lib.formatters import raw_document
from stoqlib.lib.osutils import get_application_dir
from stoqlib.lib.translation import dgettext
#from stoqlib.lib.threadutils import threadit
from stoqlib.lib.pluginmanager import get_plugin_manager, PluginError
from storm.expr import Desc, LeftJoin, Join, And, Ne

from stoqserver import main

_ = lambda s: dgettext('stoqserver', s)

try:
    from stoqntk.ntkapi import Ntk, NtkException, PwInfo
    from stoqntk.ntkenums import PwDat
    # The ntk lib instance.
    has_ntk = True
except ImportError:
    has_ntk = False
    ntk = None

try:
    from stoqnfe.events import NfeProgressEvent, NfeWarning, NfeSuccess, NfeYesNoQuestion
    has_nfe = True
except ImportError:
    has_nfe = False