def update(self):
#        ## Defines.
        form = self.request.form
        context= aq_inner(self.context)
        context_state = self.context.restrictedTraverse("@@plone_context_state")
        url = context_state.view_url()
        currency_data = getUtility(ICurrencyData)

        self.view_url = '%s/@@currency-converter' % (url,)

        self.currency_data = currency_data.currencies
        self.updated_date = currency_data.updated_date()
        self.currency_code_tuples = currency_data.currency_code_tuples()
        self.days = currency_data.days()
        self.selected_base_currency = currency_data.selected_base_currency
        self.selected_days = currency_data.selected_days
        self.margin = currency_data.margin

        try:
            self.base_currency_rate = form.get('base_currency_rate', 1)
        except:
            self.base_currency_rate = 1
        try:
            self.selected_base_currency_code = form.get('base_currency_code', self.selected_base_currency)
        except:
            self.selected_base_currency_code = self.selected_base_currency
        try:
            self.selected_currency_code = form.get('currency_code', None)
        except:
            self.selected_currency_code = None


        self.calculated_rate = None

        self.error_message = None
        self.float_error_message = None

        ## Check buttons.
        convert_button = form.get('form.button.Convert', None) is not None

        if convert_button:
            if form.get('base_currency_code') != form.get('currency_code'):
                self.base_currency_rate = form.get('base_currency_rate')
                self.base_currency_code = form.get('base_currency_code')
                self.currency_code = form.get('currency_code')
                try:
                    self.calculated_rate = self.calculated_rate_against_base_rate(float(self.base_currency_rate), self.base_currency_code, self.currency_code)
                    return self.render()
                except ValueError:
                    self.float_error_message = _(u"Please input float like 5.00")
                    return self.render()
            else:
                self.error_message =_(u"Please choose different currencies.")
                return self.render()

        else:
            return self.render()
Exemplo n.º 2
0
    def __call__(self):

        #        ## Hide the editable-object border.
        self.request.set('disable_border', True)

        #        ## Defines.
        form = self.request.form
        #        currency_data = queryUtility(ICurrencyData)
        #        if currency_data.currency_data():
        #            currency_data.currencies = currency_data.currency_data()
        self.get_currency()
        currency_data = getUtility(ICurrencyData)
        try:
            self.updated_date = currency_data.date
        except AttributeError:
            self.updated_date = currency_data.updated_date()
#        self.updated_date = currency_data.date
        self.currency_code_tuples = currency_data.currency_code_tuples()
        try:
            self.days = currency_data.amount_of_days
        except AttributeError:
            self.days = currency_data.days()
#        self.days = currency_data.days()
        self.selected_currency = currency_data.selected_base_currency
        self.selected_days = currency_data.selected_days
        self.margin = currency_data.margin
        self.currencies = currency_data.currency_rate_against_base_code_with_margin(
            int(self.selected_days), self.selected_currency, self.margin)
        if self.currencies != False:
            self.currency_rate = self.currencies.items()
        else:
            self.currency_rate = False
        self.error_message = False

        ## Check buttons.
        update_button = form.get('form.button.Update', None) is not None

        if update_button:
            try:
                float(form.get('margin'))
                self.margin = float(form.get('margin'))
                currency_data.margin = self.margin
            except:
                self.error_message = _(u"Please input float like 5.00")
            self.selected_currency = form.get('currency_code')
            currency_data.selected_base_currency = self.selected_currency
            self.selected_days = int(form.get('days'))
            currency_data.selected_days = self.selected_days
            self.currencies = currency_data.currency_rate_against_base_code_with_margin(
                self.selected_days, self.selected_currency, self.margin)
            self.currency_rate = self.currencies.items()
            return self.template()

        else:
            return self.template()
    def __call__(self):

#        ## Hide the editable-object border.
        self.request.set('disable_border', True)

#        ## Defines.
        form = self.request.form
#        currency_data = queryUtility(ICurrencyData)
#        if currency_data.currency_data():
#            currency_data.currencies = currency_data.currency_data()
        self.get_currency()
        currency_data = getUtility(ICurrencyData)
        try:
            self.updated_date = currency_data.date
        except AttributeError:
            self.updated_date = currency_data.updated_date()
#        self.updated_date = currency_data.date
        self.currency_code_tuples = currency_data.currency_code_tuples()
        try:
            self.days = currency_data.amount_of_days
        except AttributeError:
            self.days = currency_data.days()
#        self.days = currency_data.days()
        self.selected_currency = currency_data.selected_base_currency
        self.selected_days = currency_data.selected_days
        self.margin = currency_data.margin
        self.currencies = currency_data.currency_rate_against_base_code_with_margin(int(self.selected_days), self.selected_currency, self.margin)
        if self.currencies != False:
            self.currency_rate = self.currencies.items()
        else:
            self.currency_rate = False
        self.error_message = False

        ## Check buttons.
        update_button = form.get('form.button.Update', None) is not None

        if update_button:
            try:
                float(form.get('margin'))
                self.margin = float(form.get('margin'))
                currency_data.margin = self.margin
            except:
                self.error_message = _(u"Please input float like 5.00")
            self.selected_currency = form.get('currency_code')
            currency_data.selected_base_currency = self.selected_currency
            self.selected_days = int(form.get('days'))
            currency_data.selected_days = self.selected_days
            self.currencies = currency_data.currency_rate_against_base_code_with_margin(self.selected_days, self.selected_currency, self.margin)
            self.currency_rate = self.currencies.items()
            return self.template()

        else:
            return self.template()
Exemplo n.º 4
0
# Currency data from ISO 4217. 
# Currency symbols have been taken from http://www.xe.com/symbols.php

from currency.converter import CurrencyConverterMessageFactory as _

## "Currency Code" : (Name, Unit, Decimal)

currencies = { 
        "AED" : (_(u"UAE Dirham"), u""),
        "AFA" : (_(u"Afghani"), u"\u060b"),
        "ALL" : (_(u"Albanian Lek"), u"Lek"),
        "AMD" : (_(u"Armenian Dram"), u""),
        "ANG" : (_(u"Netherlands Antillian Guilder"), u"\u0192"),
        "AOA" : (_(u"Angola Kwanza"), u""),
        "ARS" : (_(u"Argentine Peso"), u"$"),
        "AUD" : (_(u"Australian Dollar"), u"$"),
        "AWG" : (_(u"Aruban Guilder"), u"\u0192"),
        "AZN" : (_(u"Azerbaijanian New Manats"), u"\u043c\u0430\u043d"),
        "BAM" : (_(u"Convertible Marks"), u"KM"),
        "BBD" : (_(u"Barbados Dollar"), u"$"),
        "BDT" : (_(u"Bangladeshi Taka"), u""),
        "BGL" : (_(u"Bulgarian Lev"), u""),
        "BGN" : (_(u"Bulgarian Lev"), u"\u043b\u0432"),
        "BHD" : (_(u"Bahraini Dinar"), u""),
        "BIF" : (_(u"Burundi Franc"), u""),
        "BMD" : (_(u"Bermudian Dollar"), u"$"),
        "BND" : (_(u"Brunei Dollar"), u"$"),
        "BOB" : (_(u"Boliviano"), u"$b"),
        "BOV" : (_(u"Bolivian Mvdol"), u""),
        "BRL" : (_(u"Brazilian Real"), u"R$"),
        "BSD" : (_(u"Bahamian Dollar"), u"$"),
    def __call__(self):

#        ## Hide the editable-object border.
        self.request.set('disable_border', True)

#        ## Defines.
        form = self.request.form

        ## Data from ICurrencyData
        currency_data = getUtility(ICurrencyData)
        self.currency_data = currency_data.currencies
        try:
            self.updated_date = currency_data.date
        except AttributeError:
            self.updated_date = currency_data.updated_date()
#        self.updated_date = currency_data.date
        self.currency_code_tuples = currency_data.currency_code_tuples()
        try:
            self.days = currency_data.amount_of_days
        except AttributeError:
            self.days = currency_data.days()
#        self.days = currency_data.amount_of_days
        self.selected_base_currency = currency_data.selected_base_currency
        self.selected_days = currency_data.selected_days
        self.margin = currency_data.margin

        try:
            self.base_currency_rate = form.get('base_currency_rate', 1)
        except:
            self.base_currency_rate = 1
        try:
            self.selected_base_currency_code = form.get('base_currency_code', self.selected_base_currency)
        except:
            self.selected_base_currency_code = self.selected_base_currency
        try:
            self.selected_currency_code = form.get('currency_code', None)
        except:
            self.selected_currency_code = None


        self.calculated_rate = None

        self.error_message = None

        ## Check buttons.
        convert_button = form.get('form.button.Convert', None) is not None

        if convert_button:
            if form.get('base_currency_code') != form.get('currency_code'):
                self.base_currency_rate = form.get('base_currency_rate')
                self.base_currency_code = form.get('base_currency_code')
                self.currency_code = form.get('currency_code')
                try:
                    self.calculated_rate = self.calculated_rate_against_base_rate(float(self.base_currency_rate), self.base_currency_code, self.currency_code)
                    return self.template()
                except ValueError:
                    self.float_error_message = _(u"Please input float like 5.00")
#                self.calculated_rate = self.calculated_rate_against_base_rate(float(self.base_currency_rate), self.base_currency_code, self.currency_code)
                    return self.template()
            else:
                self.error_message =_(u"Please choose different currencies.")
                return self.template()

        else:
            return self.template()
Exemplo n.º 6
0
    def __call__(self):

        #        ## Hide the editable-object border.
        self.request.set('disable_border', True)

        #        ## Defines.
        form = self.request.form

        ## Data from ICurrencyData
        currency_data = getUtility(ICurrencyData)
        self.currency_data = currency_data.currencies
        try:
            self.updated_date = currency_data.date
        except AttributeError:
            self.updated_date = currency_data.updated_date()
#        self.updated_date = currency_data.date
        self.currency_code_tuples = currency_data.currency_code_tuples()
        try:
            self.days = currency_data.amount_of_days
        except AttributeError:
            self.days = currency_data.days()
#        self.days = currency_data.amount_of_days
        self.selected_base_currency = currency_data.selected_base_currency
        self.selected_days = currency_data.selected_days
        self.margin = currency_data.margin

        try:
            self.base_currency_rate = form.get('base_currency_rate', 1)
        except:
            self.base_currency_rate = 1
        try:
            self.selected_base_currency_code = form.get(
                'base_currency_code', self.selected_base_currency)
        except:
            self.selected_base_currency_code = self.selected_base_currency
        try:
            self.selected_currency_code = form.get('currency_code', None)
        except:
            self.selected_currency_code = None

        self.calculated_rate = None

        self.error_message = None

        ## Check buttons.
        convert_button = form.get('form.button.Convert', None) is not None

        if convert_button:
            if form.get('base_currency_code') != form.get('currency_code'):
                self.base_currency_rate = form.get('base_currency_rate')
                self.base_currency_code = form.get('base_currency_code')
                self.currency_code = form.get('currency_code')
                try:
                    self.calculated_rate = self.calculated_rate_against_base_rate(
                        float(self.base_currency_rate),
                        self.base_currency_code, self.currency_code)
                    return self.template()
                except ValueError:
                    self.float_error_message = _(
                        u"Please input float like 5.00")
                    #                self.calculated_rate = self.calculated_rate_against_base_rate(float(self.base_currency_rate), self.base_currency_code, self.currency_code)
                    return self.template()
            else:
                self.error_message = _(u"Please choose different currencies.")
                return self.template()

        else:
            return self.template()
 def title(self):
     return _(u'Currency Converter')
Exemplo n.º 8
0
 def title(self):
     return _(u'Currency Converter')