Commit 5b3fafb4 authored by olb's avatar olb
Browse files

fix: css url is now relative

parent cb1ee69e
......@@ -5,7 +5,6 @@ from __future__ import unicode_literals
""" Annual report
"""
import getopt
import locale
import logging
import os
......@@ -29,7 +28,7 @@ tpl_env = Environment(
)
def incomes_statement(accounting_years, report):
def incomes_statement(accounting_years, report, context={}):
expenses = accounting_years.extract(match='|'.join(
report['expenses']['accounts']
))
......@@ -37,50 +36,51 @@ def incomes_statement(accounting_years, report):
report['incomes']['accounts']
))
context.update({
'incomes': incomes,
'expenses': expenses,
'conf': report,
})
template = tpl_env.get_template('income-statement.html')
return template.render(
incomes=incomes,
expenses=expenses,
conf=report,
).encode('utf-8')
return template.render(**context).encode('utf-8')
def balance_sheet(accounting_years, report):
def balance_sheet(accounting_years, report, context={}):
liabilities = accounting_years.extract(match='|'.join(
report['liabilities']['accounts']
))
assets = accounting_years.extract(match='|'.join(
report['assets']['accounts']
))
context.update({
'liabilities': liabilities,
'assets': assets,
'conf': report,
})
template = tpl_env.get_template('balance-sheet.html')
return template.render(
liabilities=liabilities,
assets=assets,
conf=report,
).encode('utf-8')
return template.render(**context).encode('utf-8')
def cash(accounting_years, report):
def cash(accounting_years, report, context={}):
accounting_year = accounting_years.get_year(accounting_years.last_year())
#locale.setlocale(locale.LC_ALL, 'fr_FR.utf-8')
context.update({
'accounting_year': accounting_year,
'conf': report,
})
template = tpl_env.get_template('cash.html')
return template.render(
accounting_year=accounting_year,
conf=report,
).encode('utf-8')
return template.render(**context).encode('utf-8')
def chart_of_accounts(accounting_years, report):
def chart_of_accounts(accounting_years, report, context={}):
accounting_year = accounting_years.get_year(accounting_years.last_year())
chart_of_accounts = accounting_year.chart_of_accounts
context.update({
'chart_of_accounts': chart_of_accounts
})
template = tpl_env.get_template('chart-of-accounts.html')
return template.render(
chart_of_accounts=chart_of_accounts
).encode('utf-8')
return template.render(**context).encode('utf-8')
def process_args(argv):
......@@ -118,27 +118,35 @@ def load(options):
return (accounting_years, accounting_years_closed)
def doreport(accounting_years, accounting_years_closed, report):
def doreport(accounting_years, accounting_years_closed, report, context={}):
accounting_years = accounting_years.clone_until(report['year'])
accounting_years_closed = accounting_years_closed.clone_until(report['year'])
directory = os.path.dirname(report['output'])
css_path = os.path.join(settings.get('OUTPUT_DIR'), 'style.css')
css_url = os.path.relpath(css_path, directory)
context.update({
'css_url': css_url,
})
if report['type'] in ['incomes_statement', 'is']:
output = incomes_statement(accounting_years, report)
output = incomes_statement(accounting_years, report, context)
elif report['type'] in ['balance_sheet', 'bs']:
output = balance_sheet(accounting_years_closed, report)
output = balance_sheet(accounting_years_closed, report, context)
elif report['type'] in ['cash', ]:
output = cash(accounting_years, report)
output = cash(accounting_years, report, context)
elif report['type'] in ['chart_of_accounts', 'coa']:
output = chart_of_accounts(accounting_years, report)
output = chart_of_accounts(accounting_years, report, context)
directory = os.path.dirname(report['output'])
if not os.path.exists(directory):
os.makedirs(directory)
elif not os.path.isdir(directory):
raise Exception('%s must be a directory' % directory)
logger.info('write report {type} to file {file}'.format(file=report['output'], type=report['type']))
logger.info('write report {type} to file {file}'.format(file=report['output'],
type=report['type']))
ofile = open(report['output'], 'w+')
print >>ofile, output
ofile.close()
......@@ -150,7 +158,7 @@ def doreports(options):
doreport(accounting_years, accounting_years_closed, report)
def doindex(options):
def doindex(options, context={}):
template = tpl_env.get_template('index.html')
output = os.path.join(
settings.get('OUTPUT_DIR'),
......@@ -165,11 +173,13 @@ def doindex(options):
reports_by_year[report['year']] = []
reports_by_year[report['year']].append(report)
context.update({
'css_url': 'style.css',
'accounting_years': settings.get('ACCOUNTING_YEARS'),
'reports': reports_by_year,
})
logger.info('write index to file {file}'.format(file=output))
print >>ofile, template.render(
accounting_years=settings.get('ACCOUNTING_YEARS'),
reports=reports_by_year,
).encode('utf-8')
print >>ofile, template.render(**context).encode('utf-8')
def doassets(options):
......
......@@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>{% block title %}titre à définir{% endblock %}</title>
{% block css %}
<link rel="stylesheet" href="../style.css">
<link rel="stylesheet" href="{{ css_url }}">
{% endblock %}
</head>
<body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment