VAT validation: Move cache to data directory

This commit is contained in:
Raphael Michel
2021-11-16 10:20:38 +01:00
parent 72455209bb
commit 993da5a392
2 changed files with 6 additions and 1 deletions

View File

@@ -20,11 +20,13 @@
# <https://www.gnu.org/licenses/>.
#
import logging
import os
import re
from urllib.error import HTTPError
import vat_moss.errors
import vat_moss.id
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from zeep import Client, Transport
from zeep.cache import SqliteCache
@@ -83,7 +85,7 @@ def _validate_vat_id_CH(vat_id, country_code):
vat_id = re.sub('[^A-Z0-9]', '', vat_id.replace('HR', '').replace('MWST', ''))
try:
transport = Transport(cache=SqliteCache())
transport = Transport(cache=SqliteCache(os.path.join(settings.CACHE_DIR, "validate_vat_id_ch_zeep_cache.db")))
client = Client(
'https://www.uid-wse-a.admin.ch/V5.0/PublicServices.svc?wsdl',
transport=transport

View File

@@ -67,6 +67,7 @@ DATA_DIR = config.get('pretix', 'datadir', fallback=os.environ.get('DATA_DIR', '
LOG_DIR = os.path.join(DATA_DIR, 'logs')
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
PROFILE_DIR = os.path.join(DATA_DIR, 'profiles')
CACHE_DIR = os.path.join(DATA_DIR, 'cache')
if not os.path.exists(DATA_DIR):
os.mkdir(DATA_DIR)
@@ -74,6 +75,8 @@ if not os.path.exists(LOG_DIR):
os.mkdir(LOG_DIR)
if not os.path.exists(MEDIA_ROOT):
os.mkdir(MEDIA_ROOT)
if not os.path.exists(CACHE_DIR):
os.mkdir(CACHE_DIR)
if config.has_option('django', 'secret'):
SECRET_KEY = config.get('django', 'secret')