Skip to content

Commit

Permalink
fix webserver bug
Browse files Browse the repository at this point in the history
  • Loading branch information
artyl committed Jun 28, 2020
1 parent fef269b commit 857743a
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BalanceHistory.sqlite
balance.html
plugin/personalsetting.py
mbplugin*.zip
python-3.8.3-embed-win32_TKINTER.zip
python-*.zip
dllplugin
jsmblhplugin
httpserver
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions plugin/dbengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def report(self,fields):
rows = self.cur.execute(reportsql)
headers = list(zip(*rows.description))[0]
data = rows.fetchall()
# округляем float до 2х знаков
data = [tuple([(round(i, 2) if type(i) == float else i) for i in line]) for line in data]
return headers,data

def check_and_add_addition(self):
Expand Down
15 changes: 12 additions & 3 deletions plugin/httpserver_mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

lang='p' # Для плагинов на python преффикс lang всегда 'p'

HTML_NO_REPORT = '''Для того чтобы были доступны отчеты необходимо в mbplugin.ini включить запись результатов в sqlite базу<br>
sqlitestore = 1<br>Также можно настроить импорт из базы BalanceHistory.mdb включив <br>
createhtmlreport = 1<br>
После включения, запустите mbplugin\setup_and_check.bat
'''

def find_ini_up(fn):
allroot = [os.getcwd().rsplit('\\',i)[0] for i in range(len(os.getcwd().split('\\')))]
all_ini = [i for i in allroot if os.path.exists(os.path.join(i,fn))]
Expand Down Expand Up @@ -125,8 +131,7 @@ def getreport(param=[]):
el = ''
if he != 'Balance' and (el == 0.0 or el == 0):
el = ''
html_line.append(
f'<{"th" if he=="NN" else "td"} id="{he}"{mark}>{el}</td>')
html_line.append(f'<{"th" if he=="NN" else "td"} id="{he}"{mark}>{el}</td>')
html_table.append(f'<tr id="row" class="n">{"".join(html_line)}</tr>')
res = template.format(style=style, html_header=html_header, html_table='\n'.join(html_table))
return 'text/html', [res]
Expand Down Expand Up @@ -287,7 +292,11 @@ def simple_app(self,environ, start_response):
if cmd.lower() == 'getbalance':
ct, text = getbalance(param) # TODO !!! Но правильно все-таки через POST
if cmd == '' or cmd == 'report': # report
ct, text = getreport(param)
options = store.read_ini()['Options']
if options['sqlitestore'] == '1':
ct, text = getreport(param)
else:
ct, text = 'text/html', HTML_NO_REPORT
if cmd == 'exit': # exit cmd
self.cmdqueue.put('STOP')
text = ['exit']
Expand Down

0 comments on commit 857743a

Please sign in to comment.