Пример #1
0
def send_purchase_receipt(contrib_id, **kw):
    """
    Sends an email to the purchaser of the app.
    """
    contrib = Contribution.objects.get(pk=contrib_id)

    with contrib.user.activate_lang():
        addon = contrib.addon
        version = addon.current_version or addon.latest_version
        # L10n: {0} is the app name.
        subject = _('Receipt for {0}').format(contrib.addon.name)
        data = {
            'app_name': addon.name,
            'developer_name': version.developer_name if version else '',
            'price': contrib.get_amount_locale(get_locale_from_lang(
                contrib.source_locale)),
            'date': jingo.helpers.datetime(contrib.created.date()),
            'purchaser_email': contrib.user.email,
            #'purchaser_phone': '',  # TODO: See bug 894614.
            #'purchaser_last_four': '',
            'transaction_id': contrib.uuid,
            'purchases_url': absolutify('/purchases'),
            'support_url': addon.support_url,
            'terms_of_service_url': absolutify('/terms-of-use'),
        }

        log.info('Sending email about purchase: %s' % contrib_id)
        text_template = 'purchase/receipt.ltxt'
        html_template = 'purchase/receipt.html'
        send_html_mail_jinja(subject, html_template, text_template, data,
                             recipient_list=[contrib.user.email])
Пример #2
0
    def get_price_data(self, currency=None):
        """Returns a tuple of Decimal(price), currency, locale.

        The price is the actual price in the current locale.
        That is, if the instance is tier 1 ($0.99) and the current locale
        maps to Euros then you get 5,01 EUR or whatever the exchange is.

        If currency is None, the default currency from the current locale will
        be returned. If you do pass in an explicit currency, you will still
        get the currently active locale which may or may not match.
        """
        if not hasattr(self, '_currencies'):
            Price.transformer([])

        lang = translation.get_language()
        locale = get_locale_from_lang(lang)
        if not currency:
            currency = amo.LOCALE_CURRENCY.get(locale.language)
        # If the currency is USD, we just use the price, not the price tier.
        if currency and currency != 'USD':
            price_currency = Price._currencies.get((currency, self.id))
            if not price_currency:
                # Asking for a currency that doesn't exist.
                raise KeyError('No currency found: %s' % currency)

            return price_currency.price, currency, locale

        return self.price, currency or self.currency, locale
Пример #3
0
 def get_amount_locale(self, locale=None):
     """Localise the amount paid into the current locale."""
     if not locale:
         lang = translation.get_language()
         locale = get_locale_from_lang(lang)
     return numbers.format_currency(self.amount or 0,
                                    self.currency or 'USD',
                                    locale=locale)
Пример #4
0
def price_locale(price, currency):
    lang = translation.get_language()
    locale = get_locale_from_lang(lang)
    pricestr = numbers.format_currency(price, currency, locale=locale)
    if currency == 'EUR':
        # See bug 865358. EU style guide
        # (http://publications.europa.eu/code/en/en-370303.htm#position)
        # disagrees with Unicode CLDR on placement of Euro symbol.
        bare = pricestr.strip(u'\xa0\u20ac')
        if lang.startswith(('en', 'ga', 'lv', 'mt')):
            return u'\u20ac' + bare
        else:
            return bare + u'\xa0\u20ac'
    return pricestr
Пример #5
0
def price_locale(price, currency):
    lang = translation.get_language()
    locale = get_locale_from_lang(lang)
    pricestr = numbers.format_currency(price, currency, locale=locale)
    if currency == "EUR":
        # See bug 865358. EU style guide
        # (http://publications.europa.eu/code/en/en-370303.htm#position)
        # disagrees with Unicode CLDR on placement of Euro symbol.
        bare = pricestr.strip(u"\xa0\u20ac")
        if lang.startswith(("en", "ga", "lv", "mt")):
            return u"\u20ac" + bare
        else:
            return bare + u"\xa0\u20ac"
    return pricestr
Пример #6
0
    def _price(self):
        """
        Return the price and currency for the current locale.
        This will take the locale and find the tier, should one
        exist.
        """
        if not hasattr(self, '_currencies'):
            Price.transformer([])

        lang = translation.get_language()
        locale = get_locale_from_lang(lang)
        currency = amo.LOCALE_CURRENCY.get(locale.language)
        if currency:
            price_currency = Price._currencies.get((currency, self.id), None)
            if price_currency:
                return price_currency.price, currency, locale

        return self.price, self.currency, locale
Пример #7
0
    def get_price_data(self, currency=None):
        """Returns a tuple of Decimal(price), currency, locale.

        The price is the actual price in the current locale.
        That is, if the instance is tier 1 ($0.99) and the current locale
        maps to Euros then you get 5,01 EUR or whatever the exchange is.

        If currency is None, the default currency from the current locale will
        be returned. If you do pass in an explicit currency, you will still
        get the currently active locale which may or may not match.
        """
        if not hasattr(self, '_currencies'):
            Price.transformer([])

        lang = translation.get_language()
        locale = get_locale_from_lang(lang)
        if not currency:
            currency = amo.LOCALE_CURRENCY.get(locale.language)
        if currency:
            price_currency = Price._currencies.get((currency, self.id), None)
            if price_currency:
                return price_currency.price, currency, locale

        return self.price, currency or self.currency, locale
Пример #8
0
    def get_price_data(self, currency=None):
        """Returns a tuple of Decimal(price), currency, locale.

        The price is the actual price in the current locale.
        That is, if the instance is tier 1 ($0.99) and the current locale
        maps to Euros then you get 5,01 EUR or whatever the exchange is.

        If currency is None, the default currency from the current locale will
        be returned. If you do pass in an explicit currency, you will still
        get the currently active locale which may or may not match.
        """
        if not hasattr(self, '_currencies'):
            Price.transformer([])

        lang = translation.get_language()
        locale = get_locale_from_lang(lang)
        if not currency:
            currency = amo.LOCALE_CURRENCY.get(locale.language)
        if currency:
            price_currency = Price._currencies.get((currency, self.id), None)
            if price_currency:
                return price_currency.price, currency, locale

        return self.price, currency or self.currency, locale
Пример #9
0
def _get_format():
    lang = translation.get_language()
    return Format(utils.get_locale_from_lang(lang))
Пример #10
0
def _get_format():
    lang = translation.get_language()
    return Format(utils.get_locale_from_lang(lang))
Пример #11
0
 def get_price_locale(self):
     """Return the price as a nicely localised string for the locale."""
     lang = translation.get_language()
     locale = get_locale_from_lang(lang)
     return numbers.format_currency(self.price, self.currency,
                                    locale=locale)
Пример #12
0
def price_locale(price, currency):
    lang = translation.get_language()
    locale = get_locale_from_lang(lang)
    return numbers.format_currency(price, currency, locale=locale)
Пример #13
0
 def get_price_locale(self):
     """Return the price as a nicely localised string for the locale."""
     lang = translation.get_language()
     locale = get_locale_from_lang(lang)
     return numbers.format_currency(self.price, self.currency,
                                    locale=locale)