Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
0.99, number format from sqliteboy
Browse files Browse the repository at this point in the history
  • Loading branch information
nopri committed Dec 18, 2013
1 parent 58a998e commit e855fea
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 32 deletions.
29 changes: 14 additions & 15 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ Simple Online Store application
(c) Noprianto <nop@tedut.com>
2010
GPL
v0.98
v0.99


SCREENSHOTS / USERS: https://github.com/nopri/onlinestore-multi/wiki


NOTE (As of 18-December-2013 UTC+7):
- This is first version (v0.98) with SQLite database, need more testing
- v0.97 is the last version with MySQL database


FEATURES:
- Run as WSGI Application
- Multi Language (currently English and Bahasa Indonesia)
Expand Down Expand Up @@ -48,8 +43,9 @@ REQUIREMENTS:
- Apache HTTP Server (and mod_wsgi)
(or alternative web server/wsgi)

(If you need simple web-based SQLite management tool, please consider
sqliteboy, https://github.com/nopri/sqliteboy :) )
If you need simple web-based SQLite management tool,
please consider sqliteboy,
https://github.com/nopri/sqliteboy :)


DEFAULT USER/PASSWORD: admin
Expand All @@ -58,24 +54,27 @@ DEFAULT USER/PASSWORD: admin
INSTALLATION:
1) Install all the requirements above (except for bundled)

2) Download / clone onlinestore-multi: https://github.com/nopri/onlinestore-multi.git
2) Download / clone onlinestore-multi:
https://github.com/nopri/onlinestore-multi.git

For example, we put it in /tmp/onlinestore-multi

3) Make sure that application directory is writeable by user who is running web server.
3) Make sure that application directory is writeable by user
who is running web server.

Please note that onlinestore-multi.db will be automatically created (and populated)
in application directory, on first visit, if there is write access on that directory.
Please note that onlinestore-multi.db will be automatically
created (and populated) in application directory,
on first visit, if there is write access on that directory.

Debian-based distribution:
Debian/Debian-based distribution:
(run these commands as root, adjust accordingly)

# chgrp www-data /tmp/onlinestore-multi
# chmod g+w /tmp/onlinestore-multi


4) Configure WSGI:
Debian-based distribution: edit /etc/apache2/sites-available/default
Debian/Debian-based distribution:
edit /etc/apache2/sites-available/default
(put these lines below DocumentRoot, adjust accordingly)

WSGIScriptAlias / /tmp/onlinestore-multi/app.py/
Expand Down
101 changes: 85 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# (c) Noprianto <nop@tedut.com>
# 2010
# GPL
# v0.98
#
# migrated from MySQL to SQLite on 2013-12-17

Expand All @@ -27,7 +26,7 @@
import urlparse
import random
import cStringIO
import locale

#
try:
from hashlib import md5
Expand Down Expand Up @@ -187,6 +186,39 @@ def handle_data(self, data):
del conn


##################### FROM SQLITEBOY (UNMODIFIED) ######################


def sqliteboy_chunk(s, n, separator, justify, padding):
s = str(s)
separator = str(separator)
padding = str(padding)
#
if (not n) or (not s) or (n < 1):
return s
#
if padding:
pad = padding[0]
else:
pad = ' '
#
if not justify:
justify = 0
#
mod = len(s) % n
if mod:
ln = len(s) + (n - mod)
if justify == 0: #left
s = s.ljust(ln, pad)
else: #right
s = s.rjust(ln, pad)
#
res = [s[i:i+n] for i in range(0, len(s), n)]
ret = separator.join(res)
#
return ret


########################### IMPORTANT FUNCTION #########################


Expand Down Expand Up @@ -242,7 +274,7 @@ def pget(option, default='', strip=True, callback=None):
############################### CONSTANT ###############################


VERSION = '0.98'
VERSION = '0.99'
NAME = 'onlinestore-multi'
PRECISION = 2
TEMPLATE_DIR = CURDIR + PS + 'template'
Expand Down Expand Up @@ -335,21 +367,58 @@ def detect_ua(ua):


def number_format(number, localeset='', places=0):
localeset = str(localeset)
saved = locale.getlocale(locale.LC_NUMERIC)
'''from sqliteboy, modified'''

n = str(number)
decimals = places
decimal_point = m.t(m.NUMBER_FORMAT, localeset)['decimal_point']
thousands_sep = m.t(m.NUMBER_FORMAT, localeset)['thousands_separator']
#
neg = False
try:
locale.setlocale(locale.LC_NUMERIC, localeset)
f = float(n)
if f < 0:
neg = True
except:
try:
localeset = localeset + '.utf8' #quick+dirty, will be fixed later
locale.setlocale(locale.LC_NUMBERIC, localeset)
except:
pass
if locale:
ret = locale.format('%.*f', (places, number), True)
locale.setlocale(locale.LC_NUMERIC, saved)
return ret
return number
return n
#
if 'e' in n.lower():
efmt = '%%.%sf' %len(n)
n = efmt %float(n)
#
dec = decimals
if not isinstance(dec, int) or dec < 0:
dec = 0
#
nn = ''
dd = ''
if '.' in n: #float
nn, dd = n.split('.')
else:
nn = n
nn = nn.replace('-', '')
nn = nn.replace('+', '')
nn = nn.strip()
dd = dd.strip()
#
if dd:
if dec <= len(dd):
dd = dd[:dec]
else:
dd = dd.ljust(dec, '0')
#
nn = sqliteboy_chunk(nn, 3, thousands_sep, 1, '').strip()
dd = dd.strip()
#
if neg:
nn = '-' + nn
#
if dd:
ret = nn + decimal_point + dd
else:
ret = nn
#
return ret


def now(format='%Y-%m-%d %H:%M:%S'):
Expand Down
6 changes: 5 additions & 1 deletion messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
NUMBER_FORMAT = {
'default': {'decimal_point': '.', 'thousands_separator': ','},
'en_US' : {'decimal_point': '.', 'thousands_separator': ','},
'id_ID' : {'decimal_point': ',', 'thousands_separator': '.'},
}

COUNTRY = {
'default' : ('_', '', ''),
Expand Down

0 comments on commit e855fea

Please sign in to comment.