mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2864 from matmair/remove-dead-code
Remove dead code
This commit is contained in:
commit
7ae9586c82
@ -1,11 +1,8 @@
|
|||||||
from django.shortcuts import HttpResponseRedirect
|
from django.shortcuts import HttpResponseRedirect
|
||||||
from django.urls import reverse_lazy, Resolver404
|
from django.urls import reverse_lazy, Resolver404
|
||||||
from django.db import connection
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
import operator
|
|
||||||
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from allauth_2fa.middleware import BaseRequire2FAMiddleware, AllauthTwoFactorMiddleware
|
from allauth_2fa.middleware import BaseRequire2FAMiddleware, AllauthTwoFactorMiddleware
|
||||||
@ -92,67 +89,6 @@ class AuthRequiredMiddleware(object):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class QueryCountMiddleware(object):
|
|
||||||
"""
|
|
||||||
This middleware will log the number of queries run
|
|
||||||
and the total time taken for each request (with a
|
|
||||||
status code of 200). It does not currently support
|
|
||||||
multi-db setups.
|
|
||||||
|
|
||||||
To enable this middleware, set 'log_queries: True' in the local InvenTree config file.
|
|
||||||
|
|
||||||
Reference: https://www.dabapps.com/blog/logging-sql-queries-django-13/
|
|
||||||
|
|
||||||
Note: 2020-08-15 - This is no longer used, instead we now rely on the django-debug-toolbar addon
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, get_response):
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
|
|
||||||
t_start = time.time()
|
|
||||||
response = self.get_response(request)
|
|
||||||
t_stop = time.time()
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
total_time = 0
|
|
||||||
|
|
||||||
if len(connection.queries) > 0:
|
|
||||||
|
|
||||||
queries = {}
|
|
||||||
|
|
||||||
for query in connection.queries:
|
|
||||||
query_time = query.get('time')
|
|
||||||
|
|
||||||
sql = query.get('sql').split('.')[0]
|
|
||||||
|
|
||||||
if sql in queries:
|
|
||||||
queries[sql] += 1
|
|
||||||
else:
|
|
||||||
queries[sql] = 1
|
|
||||||
|
|
||||||
if query_time is None:
|
|
||||||
# django-debug-toolbar monkeypatches the connection
|
|
||||||
# cursor wrapper and adds extra information in each
|
|
||||||
# item in connection.queries. The query time is stored
|
|
||||||
# under the key "duration" rather than "time" and is
|
|
||||||
# in milliseconds, not seconds.
|
|
||||||
query_time = float(query.get('duration', 0))
|
|
||||||
|
|
||||||
total_time += float(query_time)
|
|
||||||
|
|
||||||
logger.debug('{n} queries run, {a:.3f}s / {b:.3f}s'.format(
|
|
||||||
n=len(connection.queries),
|
|
||||||
a=total_time,
|
|
||||||
b=(t_stop - t_start)))
|
|
||||||
|
|
||||||
for x in sorted(queries.items(), key=operator.itemgetter(1), reverse=True):
|
|
||||||
print(x[0], ':', x[1])
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
url_matcher = url('', include(frontendpatterns))
|
url_matcher = url('', include(frontendpatterns))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
"""
|
|
||||||
This script is used to simplify the translation process.
|
|
||||||
|
|
||||||
Django provides a framework for working out which strings are "translatable",
|
|
||||||
and these strings are then dumped in a file under InvenTree/locale/<lang>/LC_MESSAGES/django.po
|
|
||||||
|
|
||||||
This script presents the translator with a list of strings which have not yet been translated,
|
|
||||||
allowing for a simpler and quicker translation process.
|
|
||||||
|
|
||||||
If a string translation needs to be updated, this will still need to be done manually,
|
|
||||||
by editing the appropriate .po file.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def manually_translate_file(filename, save=False):
|
|
||||||
"""
|
|
||||||
Manually translate a .po file.
|
|
||||||
Present any missing translation strings to the translator,
|
|
||||||
and write their responses back to the file.
|
|
||||||
"""
|
|
||||||
|
|
||||||
print("Add manual translations to '{f}'".format(f=filename))
|
|
||||||
print("For each missing translation:")
|
|
||||||
print("a) Directly enter a new tranlation in the target language")
|
|
||||||
print("b) Leave empty to skip")
|
|
||||||
print("c) Press Ctrl+C to exit")
|
|
||||||
|
|
||||||
print("-------------------------")
|
|
||||||
input("Press <ENTER> to start")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
with open(filename, 'r') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
out = []
|
|
||||||
|
|
||||||
# Context data
|
|
||||||
source_line = ''
|
|
||||||
msgid = ''
|
|
||||||
|
|
||||||
for num, line in enumerate(lines):
|
|
||||||
# Keep track of context data BEFORE an empty msgstr object
|
|
||||||
line = line.strip()
|
|
||||||
|
|
||||||
if line.startswith("#: "):
|
|
||||||
source_line = line.replace("#: ", "")
|
|
||||||
|
|
||||||
elif line.startswith("msgid "):
|
|
||||||
msgid = line.replace("msgid ", "")
|
|
||||||
|
|
||||||
if line.strip() == 'msgstr ""':
|
|
||||||
# We have found an empty translation!
|
|
||||||
|
|
||||||
if msgid and len(msgid) > 0 and not msgid == '""':
|
|
||||||
print("Source:", source_line)
|
|
||||||
print("Enter translation for {t}".format(t=msgid))
|
|
||||||
|
|
||||||
try:
|
|
||||||
translation = str(input(">"))
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
break
|
|
||||||
|
|
||||||
if translation and len(translation) > 0:
|
|
||||||
# Update the line with the new translation
|
|
||||||
line = 'msgstr "{msg}"'.format(msg=translation)
|
|
||||||
|
|
||||||
out.append(line + "\r\n")
|
|
||||||
|
|
||||||
if save:
|
|
||||||
with open(filename, 'w') as output_file:
|
|
||||||
output_file.writelines(out)
|
|
||||||
|
|
||||||
print("Translation done: written to", filename)
|
|
||||||
print("Run 'invoke translate' to rebuild translation data")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
MY_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
LOCALE_DIR = os.path.join(MY_DIR, '..', 'locale')
|
|
||||||
|
|
||||||
if not os.path.exists(LOCALE_DIR):
|
|
||||||
print("Error: {d} does not exist!".format(d=LOCALE_DIR))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="InvenTree Translation Helper")
|
|
||||||
|
|
||||||
parser.add_argument('language', help='Language code', action='store')
|
|
||||||
|
|
||||||
parser.add_argument('--fake', help="Do not save updated translations", action='store_true')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
language = args.language
|
|
||||||
|
|
||||||
LANGUAGE_DIR = os.path.abspath(os.path.join(LOCALE_DIR, language))
|
|
||||||
|
|
||||||
# Check that a locale directory exists for the given language!
|
|
||||||
if not os.path.exists(LANGUAGE_DIR):
|
|
||||||
print("Error: Locale directory for language '{l}' does not exist".format(l=language))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Check that a .po file exists for the given language!
|
|
||||||
PO_FILE = os.path.join(LANGUAGE_DIR, 'LC_MESSAGES', 'django.po')
|
|
||||||
|
|
||||||
if not os.path.exists(PO_FILE):
|
|
||||||
print("Error: File '{f}' does not exist".format(f=PO_FILE))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Ok, now we run the user through the translation file
|
|
||||||
manually_translate_file(PO_FILE, save=args.fake is not True)
|
|
Loading…
Reference in New Issue
Block a user