Refactor "Currency settings" view

This commit is contained in:
Oliver 2021-07-27 00:29:55 +10:00
parent de89c3997d
commit ca1c692b15
4 changed files with 20 additions and 40 deletions

View File

@ -39,7 +39,7 @@ from rest_framework.documentation import include_docs_urls
from .views import auth_request from .views import auth_request
from .views import IndexView, SearchView, DatabaseStatsView from .views import IndexView, SearchView, DatabaseStatsView
from .views import SettingsView, EditUserView, SetPasswordView from .views import SettingsView, EditUserView, SetPasswordView
from .views import CurrencySettingsView, CurrencyRefreshView from .views import CurrencyRefreshView
from .views import AppearanceSelectView, SettingCategorySelectView from .views import AppearanceSelectView, SettingCategorySelectView
from .views import DynamicJsView from .views import DynamicJsView
@ -84,7 +84,6 @@ settings_urls = [
url(r'^appearance/?', AppearanceSelectView.as_view(), name='settings-appearance'), url(r'^appearance/?', AppearanceSelectView.as_view(), name='settings-appearance'),
url(r'^category/', SettingCategorySelectView.as_view(), name='settings-category'), url(r'^category/', SettingCategorySelectView.as_view(), name='settings-category'),
url(r'^currencies/', CurrencySettingsView.as_view(), name='settings-currencies'),
url(r'^currencies-refresh/', CurrencyRefreshView.as_view(), name='settings-currencies-refresh'), url(r'^currencies-refresh/', CurrencyRefreshView.as_view(), name='settings-currencies-refresh'),
url(r'^(?P<pk>\d+)/edit/user', UserSettingEdit.as_view(), name='user-setting-edit'), url(r'^(?P<pk>\d+)/edit/user', UserSettingEdit.as_view(), name='user-setting-edit'),

View File

@ -12,6 +12,7 @@ from django.utils.translation import gettext_lazy as _
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import redirect
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
@ -787,6 +788,18 @@ class SettingsView(TemplateView):
ctx['settings'] = InvenTreeSetting.objects.all().order_by('key') ctx['settings'] = InvenTreeSetting.objects.all().order_by('key')
ctx["base_currency"] = currency_code_default()
ctx["currencies"] = currency_codes
ctx["rates"] = Rate.objects.filter(backend="InvenTreeExchange")
# When were the rates last updated?
try:
backend = ExchangeBackend.objects.get(name='InvenTreeExchange')
ctx["rates_updated"] = backend.last_update
except:
ctx["rates_updated"] = None
return ctx return ctx
@ -805,34 +818,7 @@ class CurrencyRefreshView(RedirectView):
# Will block for a little bit # Will block for a little bit
InvenTree.tasks.update_exchange_rates() InvenTree.tasks.update_exchange_rates()
return self.get(request, *args, **kwargs) return redirect(reverse_lazy('settings'))
class CurrencySettingsView(TemplateView):
"""
View for configuring currency settings
"""
template_name = "InvenTree/settings/currencies.html"
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs).copy()
ctx['settings'] = InvenTreeSetting.objects.all().order_by('key')
ctx["base_currency"] = currency_code_default()
ctx["currencies"] = currency_codes
ctx["rates"] = Rate.objects.filter(backend="InvenTreeExchange")
# When were the rates last updated?
try:
backend = ExchangeBackend.objects.get(name='InvenTreeExchange')
ctx["rates_updated"] = backend.last_update
except:
ctx["rates_updated"] = None
return ctx
class AppearanceSelectView(FormView): class AppearanceSelectView(FormView):

View File

@ -1,16 +1,14 @@
{% extends "InvenTree/settings/settings.html" %} {% extends "panel.html" %}
{% load i18n %} {% load i18n %}
{% load inventree_extras %} {% load inventree_extras %}
{% block tabs %} {% block label %}currencies{% endblock %}
{% include "InvenTree/settings/tabs.html" with tab='currencies' %}
{% endblock %}
{% block subtitle %} {% block heading %}
{% trans "Currency Settings" %} {% trans "Currency Settings" %}
{% endblock %} {% endblock %}
{% block settings %} {% block content %}
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
{% include "InvenTree/settings/header.html" %} {% include "InvenTree/settings/header.html" %}
@ -55,8 +53,4 @@
</tbody> </tbody>
</table> </table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
{% endblock %} {% endblock %}

View File

@ -20,6 +20,7 @@
{% if user.is_staff %} {% if user.is_staff %}
{% include "InvenTree/settings/global.html" %} {% include "InvenTree/settings/global.html" %}
{% include "InvenTree/settings/currencies.html" %}
{% include "InvenTree/settings/report.html" %} {% include "InvenTree/settings/report.html" %}
{% include "InvenTree/settings/part.html" %} {% include "InvenTree/settings/part.html" %}
{% include "InvenTree/settings/stock.html" %} {% include "InvenTree/settings/stock.html" %}