示例#1
0
def test_all_babel_currencies():
    missing = sorted(
        list(
            set(get_global("all_currencies").keys()) - set(CURRENCIES.keys())))
    assert (
        missing == []
    ), "The following currencies defined in Babel are missing: " + ", ".join(
        missing)
示例#2
0
    def to_python(self, value):
        if not isinstance(value, tuple):
            raise Exception("Invalid money input, expected sum and currency.")

        amount = super(MoneyField, self).to_python(value[0])
        currency = value[1]
        if not currency:
            raise forms.ValidationError(_(u"Currency is missing"))
        currency = currency.upper()
        if not CURRENCIES.get(currency, False):
            raise forms.ValidationError(_(u"Unrecognized currency type '%s'." % currency))
        return Money(amount=amount, currency=currency)
示例#3
0
    def to_python(self, value):
        if not isinstance(value, tuple):
            raise Exception("Invalid money input, expected sum and currency.")

        amount = super(MoneyField, self).to_python(value[0])
        currency = value[1]
        if not currency:
            raise forms.ValidationError(_(u'Currency is missing'))
        currency = currency.upper()
        if not CURRENCIES.get(currency,
                              False) or currency == DEFAULT_CURRENCY_CODE:
            raise forms.ValidationError(
                _(u"Unrecognized currency type '%s'." % currency))
        return Money(amount=amount, currency=currency)
示例#4
0
    def to_python(self, value):

        if value is None:
            return None
        if isinstance(value, Money):
            return value

        if not isinstance(value, tuple):
            raise Exception(
                "Invalid money input, expected amount and currency, got: %s." % value)

        amount = super(MoneyField, self).to_python(value[0])

        currency = value[1]
        if not currency:
            raise forms.ValidationError(_(u'Currency is missing'))
        currency = currency.upper()
        if not CURRENCIES.get(currency,
                              False) or currency == DEFAULT_CURRENCY_CODE:
            raise forms.ValidationError(
                _(u"Unrecognized currency type '%s'." % currency))
        return Money(amount=amount, currency=currency)
def test_all_babel_currencies():
    missing = sorted(list(set(get_global('all_currencies').keys()) - set(CURRENCIES.keys())))
    assert missing == [], \
        'The following currencies defined in Babel are missing: ' + ', '.join(missing)
示例#6
0
    assert False, "expected KeyError"
except KeyError:
    pass

for idx in ('name', 'official_name', 'common_name'):
    index = pycountry.countries.indices[idx]
    for k in index.keys():
        index[k.upper()] = index[k]

# we should now be able to find both Palau and PALAU
assert find_country('Palau') is not None
assert find_country('PALAU') is not None

# search countries using py-moneyed data
from moneyed.classes import CURRENCIES
for cur_code, currency in CURRENCIES.iteritems():
    for country_name in currency.countries:
        try:
            cc = find_country(country_name)
            currencies = CC_TO_CURRENCIES.setdefault(str(cc), [])
            if cur_code not in currencies:
                print >> sys.stderr, "%s: %s augmenting hexorx data using py-moneyed" % (
                    cc, cur_code)
                currencies.append(str(cur_code))
        except KeyError:
            print >> sys.stderr, "cannot find country by the name of %s" % country_name
            continue

# Overrides based on some manual research (mostly Wikipedia)
OVERRIDES = {
    'WS': ('WST', ),  # http://en.wikipedia.org/wiki/Samoa
from collective.behavior.price import _
from collective.behavior.price.schema import PriceSchema
from moneyed.classes import CURRENCIES
from zope import schema
from zope.interface import Attribute
from zope.interface import Interface


class IPrice(PriceSchema):
    """Interface for behaviro: Price"""

    currency = Attribute('Currency like EUR')
    money = Attribute('Instance: moneyed.Money')


currencies = CURRENCIES.keys()
currencies.sort()


class ICurrency(Interface):

    default_currency = schema.Choice(
        title=_(u'Default Currency'),
        description=_(u'Default Currency for price field.'),
        required=True,
        values=currencies,
        default='EUR')