PROBLEM SOLVED!
Thank you all for your fast response!
I have made a new *.py file in the model with that content:
# -*- coding: utf-8 -*-
from __future__ import division
ZERO = "ноль"
L_1_HE = HE = [ZERO, "один", "два", "три", "четыре", "пять", "шесть",
"семь", "восемь", "девять", "десять",
"одинадцать", "двенадцать", "тринадцать", "четырнадцать",
"пятнадцать",
"шестнадцать", "семнадцать", "восемнадцать", "девятнадцать"]
L_1_SHE = SHE = [ZERO, "одна", "две"] + L_1_HE[3:]
L_10 = [ZERO, "десять", "двадцать", "тридцать", "сорок", "пятьдесят",
"шестьдесят", "семьдесят", "восемьдесят", "девяносто"]
L_100 = [ZERO, "сто", "двести", "триста", "четыреста", "пятьсот",
"шестьсот", "семьсот", "восемьсот", "девятьсот"]
N_ROUBLE = "рубл"
N_COP = "копе"
RUR = (N_ROUBLE, N_COP)
N_DOLLAR = "доллар"
N_CENT = "цент"
USD = (N_DOLLAR, N_CENT)
GENDER = {
N_ROUBLE: HE,
N_COP: SHE,
N_DOLLAR: HE,
N_CENT: HE,
}
N_1000 = "тысяч"
N_MILLION = "миллион"
N_BILLION = "миллиард"
ENDINGS = {
N_ROUBLE: ["ей", "ь", "я", "я", "я"] + 30 * ["ей"],
N_COP: ["ек", "йка", "йки", "йки", "йки"] + 30 * ["ек"],
N_DOLLAR: ["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_CENT: ["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_1000: ["", "а", "и", "и", "и"] + 30 * [""],
N_MILLION: ["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_BILLION: ["ов", "", "а", "а", "а"] + 30 * ["ов"],
}
def write_1_to_999(n, gender_digits=HE):
assert n<=999
if n==0:
return ZERO
n_100 = n // 100
n_10 = n % 100 // 10
n_1 = n % 10
res = []
res.append(L_100[n_100])
if n_10 == 1:
res.append(gender_digits[10*n_10 + n_1])
else:
res.append(L_10[n_10])
res.append(gender_digits[n_1])
return " ".join([s for s in res if s != ZERO])
def ending_index(n):
n_2 = n % 100
return n_2 if n_2 < 20 else n_2 % 10
def form_group_name(group, n):
return group + ENDINGS[group][ending_index(n)]
def form_group(group, n, gender_digits=HE):
return ("%s %s" % (write_1_to_999(n, gender_digits),
form_group_name(group, n))) if n else ZERO
def write_number(n, gender_digits=HE):
assert type(n) in (int, long)
if n==0:
return ZERO
n_3 = n % 10**3
n_6 = n % 10**6 // 10**3
n_9 = n % 10**9 // 10**6
n_12 = n % 10**12 // 10**9
res = []
res.append(form_group(N_BILLION, n_12))
res.append(form_group(N_MILLION, n_9))
res.append(form_group(N_1000, n_6, SHE))
res.append(write_1_to_999(n_3, gender_digits))
return ", ".join([s for s in res if s != ZERO])
def write_price(n_rub, n_cop=0, currency=RUR):
rub_id, cop_id = currency
n = int(n_rub)
res = []
res.append("%s %s" % (write_number(n, GENDER[rub_id]),
form_group_name(rub_id, n)))
res.append(form_group(cop_id, n_cop, GENDER[cop_id]))
return ", ".join([s for s in res if s != ZERO])
And then I use the main function write_price() in my view like this:
{{=write_price(cur_invoice.invoice_sum, int(drob))}}
It works perfectly!
On 25 фев, 18:56, Anthony <[email protected]> wrote:
> On Saturday, February 25, 2012 3:28:39 AM UTC-5, cyber wrote:
>
> > ... but if I use web2py in MS Windows from the box?
> > I have no ideas of how to use additional modules to be able to import
> > required pieces of code from them.
>
> Are you using the web2py Windows binary, or are your running from web2py
> source using your own installation of Python? I recommend the latter. In
> that case, you can install Python setuptools
> (http://pypi.python.org/pypi/setuptools#windows) and use easy_install to
> install the Pytils egg. Alternatively, it might work if you simply copy the
> "pytils" folder from Pytils into your web2py site-packages folder (or even
> your application's "modules" folder).
>
> Anthony