Changed the url_with_return and url_keep_return template tags so that they work with URL instead of view names and parameters, not to mess up with the built-in url template tag in the Mia core application.

This commit is contained in:
依瑪貓 2020-08-09 18:03:16 +08:00
parent e86c150707
commit f26b303205
18 changed files with 71 additions and 73 deletions

View File

@ -39,7 +39,7 @@ First written: 2020/8/8
{% endif %}
<!-- the delete confirmation dialog -->
<form action="{% url_keep_return "accounting:accounts.delete" account %}" method="post">
<form action="{% url "accounting:accounts.delete" account as url %}{% url_keep_return url %}" method="post">
{% csrf_token %}
<!-- The Modal -->
<div class="modal" id="del-modal">
@ -141,7 +141,7 @@ First written: 2020/8/8
<div class="col-sm-2">{{ _("Child Accounts:")|force_escape }}</div>
<div class="col-sm-10">
{% for child in account.child_set.all %}
<a class="btn btn-primary" type="role" href="{% url_with_return "accounting:accounts.detail" child %}">
<a class="btn btn-primary" type="role" href="{% url "accounting:accounts.detail" child as url %}{% url_with_return url %}">
{{ child }}
</a>
{% empty %}

View File

@ -42,13 +42,13 @@ First written: 2020/7/20
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>

View File

@ -41,13 +41,13 @@ First written: 2020/7/15
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>

View File

@ -42,13 +42,13 @@ First written: 2020/7/1
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>
@ -122,7 +122,7 @@ First written: 2020/7/1
<td class="amount {% if record.balance < 0 %} text-danger {% endif %}">{{ record.balance|accounting_amount }}</td>
<td class="actions">
{% if record.pk is not None %}
<a href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}" class="btn btn-info" role="button">
<a href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -138,7 +138,7 @@ First written: 2020/7/1
{% for record in record_list %}
<li class="list-group-item {% if not record.is_balanced or record.has_order_hole %} list-group-item-danger {% endif %}">
{% if record.pk is not None %}
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}">
<a class="list-group-item-action" href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}">
<div class="date-account-line d-flex justify-content-between align-items-center">
{{ record.transaction.date|smart_date }} {{ record.account.title|title_case }}
</div>

View File

@ -42,13 +42,13 @@ First written: 2020/7/19
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>

View File

@ -42,13 +42,13 @@ First written: 2020/7/17
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>
@ -102,7 +102,7 @@ First written: 2020/7/17
<td>{{ record.transaction.note|default:"" }}</td>
<td class="actions">
{% if record.pk is not None %}
<a href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}" class="btn btn-info" role="button">
<a href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
{{ _("View")|force_escape }}
</a>
@ -118,7 +118,7 @@ First written: 2020/7/17
{% for record in record_list %}
<li class="list-group-item {% if not record.is_balanced or record.has_order_hole %} list-group-item-danger {% endif %}">
{% if record.pk is not None %}
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}">
<a class="list-group-item-action" href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}">
<div class="{% if record.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-account-line">
{{ record.transaction.date|smart_date }} {{ record.account.title|title_case }}

View File

@ -41,13 +41,13 @@ First written: 2020/7/16
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>

View File

@ -42,13 +42,13 @@ First written: 2020/7/16
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>
@ -123,7 +123,7 @@ First written: 2020/7/16
<td class="amount {% if record.balance < 0 %} text-danger {% endif %}">{{ record.balance|accounting_amount }}</td>
<td class="actions">
{% if record.pk is not None %}
<a href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}" class="btn btn-info" role="button">
<a href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -139,7 +139,7 @@ First written: 2020/7/16
{% for record in record_list %}
<li class="list-group-item {% if not record.is_balanced or record.has_order_hole or record.is_payable %} list-group-item-danger {% endif %}{% if record.is_existing_equipment %} list-group-item-info {% endif %}">
{% if record.pk is not None %}
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}">
<a class="list-group-item-action" href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}">
<div class="date-account-line">
{{ record.transaction.date|smart_date }} {{ record.account.title|title_case }}
</div>

View File

@ -41,13 +41,13 @@ First written: 2020/7/21
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>
@ -100,7 +100,7 @@ First written: 2020/7/21
<td class="amount">{{ record.credit_amount|accounting_amount }}</td>
<td>{{ record.transaction.notes|default:"" }}</td>
<td class="actions">
<a href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}" class="btn btn-info" role="button">
<a href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
{{ _("View")|force_escape }}
</a>
@ -114,7 +114,7 @@ First written: 2020/7/21
<ul class="list-group d-md-none">
{% for record in record_list %}
<li class="list-group-item {% if not record.is_balanced or record.has_order_hole %} list-group-item-danger {% endif %}">
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.detail" record.transaction.type record.transaction %}">
<a class="list-group-item-action" href="{% url "accounting:transactions.detail" record.transaction.type record.transaction as url %}{% url_with_return url %}">
<div class="{% if record.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-account-line">
{{ record.transaction.date|smart_date }} {{ record.account.title|title_case }}

View File

@ -55,7 +55,7 @@ First written: 2020/8/6
</div>
{% if txn_list|length > 1 %}
<form action="{% url_keep_return "accounting:transactions.sort" date %}" method="post">
<form action="{% url "accounting:transactions.sort" date as url %}{% url_keep_return url %}" method="post">
{% csrf_token %}
<table class="table general-journal-table">
<thead>
@ -75,7 +75,7 @@ First written: 2020/8/6
<button class="btn btn-outline-secondary" type="button">
<i class="fas fa-sort"></i>
</button>
<a class="btn btn-primary" role="button" href="{% url_with_return "accounting:transactions.detail" txn.type txn %}">
<a class="btn btn-primary" role="button" href="{% url "accounting:transactions.detail" txn.type txn as url %}{% url_with_return url %}">
<i class="fas fa-eye"></i>
</a>
</div>

View File

@ -40,7 +40,7 @@ First written: 2020/7/23
{% endif %}
<!-- the delete confirmation dialog -->
<form action="{% url_keep_return "accounting:transactions.delete" txn %}" method="post">
<form action="{% url "accounting:transactions.delete" txn as url %}{% url_keep_return url %}" method="post">
{% csrf_token %}
<!-- The Modal -->
<div class="modal" id="del-modal">
@ -71,7 +71,7 @@ First written: 2020/7/23
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
<a class="btn btn-primary" role="button" href="{% url_keep_return "accounting:transactions.edit" "expense" txn %}">
<a class="btn btn-primary" role="button" href="{% url "accounting:transactions.edit" "expense" txn as url %}{% url_keep_return url %}">
<i class="fas fa-edit"></i>
{{ _("Edit")|force_escape }}
</a>
@ -81,12 +81,12 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</button>
{% else %}
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>
{% endif %}
<a class="btn btn-primary d-none d-sm-inline" href="{% url_keep_return "accounting:transactions.detail" "transfer" txn %}">
<a class="btn btn-primary d-none d-sm-inline" href="{% url "accounting:transactions.detail" "transfer" txn as url %}{% url_keep_return url %}">
<i class="fas fa-exchange-alt"></i>
{{ _("To Transfer")|force_escape }}
</a>
@ -101,12 +101,12 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</span>
{% else %}
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="dropdown-item" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>
{% endif %}
<a class="dropdown-item" href="{% url_keep_return "accounting:transactions.detail" "transfer" txn %}">
<a class="dropdown-item" href="{% url "accounting:transactions.detail" "transfer" txn as url %}{% url_keep_return url %}">
<i class="fas fa-exchange-alt"></i>
{{ _("To Transfer")|force_escape }}
</a>

View File

@ -40,7 +40,7 @@ First written: 2020/7/23
{% endif %}
<!-- the delete confirmation dialog -->
<form action="{% url_keep_return "accounting:transactions.delete" txn %}" method="post">
<form action="{% url "accounting:transactions.delete" txn as url %}{% url_keep_return url %}" method="post">
{% csrf_token %}
<!-- The Modal -->
<div class="modal" id="del-modal">
@ -71,7 +71,7 @@ First written: 2020/7/23
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
<a class="btn btn-primary" role="button" href="{% url_keep_return "accounting:transactions.edit" "income" txn %}">
<a class="btn btn-primary" role="button" href="{% url "accounting:transactions.edit" "income" txn as url %}{% url_keep_return url %}">
<i class="fas fa-edit"></i>
{{ _("Edit")|force_escape }}
</a>
@ -81,12 +81,12 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</button>
{% else %}
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>
{% endif %}
<a class="btn btn-primary d-none d-sm-inline" href="{% url_keep_return "accounting:transactions.detail" "transfer" txn %}">
<a class="btn btn-primary d-none d-sm-inline" href="{% url "accounting:transactions.detail" "transfer" txn as url %}{% url_keep_return url %}">
<i class="fas fa-exchange-alt"></i>
{{ _("To Transfer")|force_escape }}
</a>
@ -101,12 +101,12 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</span>
{% else %}
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="dropdown-item" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>
{% endif %}
<a class="dropdown-item" href="{% url_keep_return "accounting:transactions.detail" "transfer" txn %}">
<a class="dropdown-item" href="{% url "accounting:transactions.detail" "transfer" txn as url %}{% url_keep_return url %}">
<i class="fas fa-exchange-alt"></i>
{{ _("To Transfer")|force_escape }}
</a>

View File

@ -40,7 +40,7 @@ First written: 2020/7/23
{% endif %}
<!-- the delete confirmation dialog -->
<form action="{% url_keep_return "accounting:transactions.delete" txn %}" method="post">
<form action="{% url "accounting:transactions.delete" txn as url %}{% url_keep_return url %}" method="post">
{% csrf_token %}
<!-- The Modal -->
<div class="modal" id="del-modal">
@ -71,7 +71,7 @@ First written: 2020/7/23
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
<a class="btn btn-primary" role="button" href="{% url_keep_return "accounting:transactions.edit" "transfer" txn %}">
<a class="btn btn-primary" role="button" href="{% url "accounting:transactions.edit" "transfer" txn as url %}{% url_keep_return url %}">
<i class="fas fa-edit"></i>
{{ _("Edit")|force_escape }}
</a>
@ -81,7 +81,7 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</button>
{% else %}
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="btn btn-primary d-none d-sm-inline" role="button" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>
@ -97,7 +97,7 @@ First written: 2020/7/23
{{ _("Sort")|force_escape }}
</span>
{% else %}
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.sort" txn.date %}">
<a class="dropdown-item" href="{% url "accounting:transactions.sort" txn.date as url %}{% url_with_return url %}">
<i class="fas fa-sort"></i>
{{ _("Sort")|force_escape }}
</a>

View File

@ -46,7 +46,7 @@ First written: 2020/7/23
{% endfor %}
<div class="btn-group btn-actions">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url_keep_return "accounting:transactions.detail" "expense" form.transaction %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url "accounting:transactions.detail" "expense" form.transaction as url %}{% url_keep_return url %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
@ -55,7 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url_keep_return "accounting:transactions.update" "expense" form.transaction %}{% else %}{% url_keep_return "accounting:transactions.store" "expense" %}{% endif %}" method="post">
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "expense" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.store" "expense" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %}
<div class="row form-group">
<div class="col-sm-2">

View File

@ -46,7 +46,7 @@ First written: 2020/7/23
{% endfor %}
<div class="btn-group btn-actions">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url_keep_return "accounting:transactions.detail" "income" form.transaction %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url "accounting:transactions.detail" "income" form.transaction as url %}{% url_keep_return url %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
@ -55,7 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url_keep_return "accounting:transactions.update" "income" form.transaction %}{% else %}{% url_keep_return "accounting:transactions.store" "income" %}{% endif %}" method="post">
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "income" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.store" "income" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %}
<div class="row form-group">
<div class="col-sm-2">

View File

@ -46,7 +46,7 @@ First written: 2020/7/23
{% endfor %}
<div class="btn-group btn-actions">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url_keep_return "accounting:transactions.detail" "transfer" form.transaction %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<a class="btn btn-primary" role="button" href="{% if form.transaction %}{% url "accounting:transactions.detail" "transfer" form.transaction as url %}{% url_keep_return url %}{% elif request.GET.r %}{{ request.GET.r }}{% else %}{% url "accounting:home" %}{% endif %}">
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
@ -55,7 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url_keep_return "accounting:transactions.update" "transfer" form.transaction %}{% else %}{% url_keep_return "accounting:transactions.store" "transfer" %}{% endif %}" method="post">
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "transfer" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.store" "transfer" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %}
<div class="row form-group">
<div class="col-sm-2">

View File

@ -42,13 +42,13 @@ First written: 2020/7/19
{% trans "New" context "Accounting" as text %}{{ text|force_escape }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "expense" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "expense" as url %}{% url_with_return url %}">
{{ _("Cash Expense")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "income" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "income" as url %}{% url_with_return url %}">
{{ _("Cash Income")|force_escape }}
</a>
<a class="dropdown-item" href="{% url_with_return "accounting:transactions.create" "transfer" %}">
<a class="dropdown-item" href="{% url "accounting:transactions.create" "transfer" as url %}{% url_with_return url %}">
{{ _("Transfer")|force_escape }}
</a>
</div>

View File

@ -83,35 +83,33 @@ def url_period(context, period_spec):
@register.simple_tag(takes_context=True)
def url_with_return(context, view_name, *args):
"""Returns the transaction URL.
def url_with_return(context, url):
"""Returns the URL with the current page added as the "r" query parameter,
so that returning to this page is possible.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
url (str): The URL.
Returns:
str: The URL.
str: The URL with the current page added as the "r" query parameter.
"""
url = reverse(view_name, args=args)
return str(UrlBuilder(url).query(
r=str(UrlBuilder(context.request.get_full_path()).remove("s"))))
@register.simple_tag(takes_context=True)
def url_keep_return(context, view_name, *args):
"""Returns the transaction URL.
def url_keep_return(context, url):
"""Returns the URL with the current "r" query parameter set, so that the
next processor can still return to the same page.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
url (str): The URL.
Returns:
str: The URL.
str: The URL with the current "r" query parameter set.
"""
url = reverse(view_name, args=args)
return str(UrlBuilder(url).query(r=context.request.GET.get("r")))