Added the add_css and add_js template tags to add local CSS and JavaScript files to the base template in the Mia core application, and applied them in the templates of the accounting application.

This commit is contained in:
依瑪貓 2020-08-03 00:20:26 +08:00
parent cbac2ba61e
commit 841fbc1223
10 changed files with 45 additions and 18 deletions

View File

@ -30,8 +30,7 @@ First written: 2020/7/20
{% blocktrans asvar title with period=period.description context "Accounting|" %}Balance Sheet in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -29,8 +29,7 @@ First written: 2020/7/15
{% block settings %}
{% blocktrans asvar title with account=account.title|title context "Accounting|" %}Cash Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/1
{% blocktrans asvar title with account=account.title|title period=period.description context "Accounting|" %}Cash Account for {{ account }} in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/19
{% blocktrans asvar title with period=period.description context "Accounting|" %}Income Statement in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/17
{% blocktrans asvar title with period=period.description context "Accounting|" %}Journal in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -29,8 +29,7 @@ First written: 2020/7/16
{% block settings %}
{% blocktrans asvar title with account=account.title|title context "Accounting|" %}Ledger Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/16
{% blocktrans asvar title with account=account.title|title period=period.description context "Accounting|" %}Ledger for {{ account }} in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/21
{% blocktrans asvar title with query=request.GET.q context "Accounting|" %}Search Result for “{{ query }}”{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -30,8 +30,7 @@ First written: 2020/7/19
{% blocktrans asvar title with period=period.description context "Accounting|" %}Trial Balance in {{ period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
{% block content %}

View File

@ -114,6 +114,42 @@ def url_keep_return(context, view_name, *args):
return str(UrlBuilder(url).set("r", context.request.GET.get("r")))
@register.simple_tag(takes_context=True)
def add_css(context, url):
"""Adds a local CSS file. The file is added to the "css" template
list variable.
Args:
context (RequestContext): The request context.
url (str): The URL or path of the CSS file.
Returns:
str: An empty string
"""
if "css" not in context.dicts[0]:
context.dicts[0]["css"] = []
context.dicts[0]["css"].append(url)
return ""
@register.simple_tag(takes_context=True)
def add_js(context, url):
"""Adds a local JavaScript file. The file is added to the "js" template
list variable.
Args:
context (RequestContext): The request context.
url (str): The URL or path of the JavaScript file.
Returns:
str: An empty string
"""
if "js" not in context.dicts[0]:
context.dicts[0]["js"] = []
context.dicts[0]["js"].append(url)
return ""
@register.simple_tag(takes_context=True, name="retrieve_status")
def retrieve_status_tag(context):
"""Returns the success message from the previously-stored status. The