(request, action)
| 33 | |
| 34 | @user_passes_test(lambda u: u.is_superuser) |
| 35 | def dev_tools(request, action): |
| 36 | if not settings.DEV: |
| 37 | raise Http404() |
| 38 | |
| 39 | if request.method == 'POST': |
| 40 | if action == "reloadTranslation": |
| 41 | try: |
| 42 | args = json.loads(request.body).get('args') |
| 43 | |
| 44 | fd, tmpzipPath = tempfile.mkstemp(suffix=".zip") |
| 45 | os.close(fd) |
| 46 | |
| 47 | logger.info("Downloading %s" % args[0]) |
| 48 | download_file(args[0], tmpzipPath) |
| 49 | |
| 50 | tmpPath = tempfile.mkdtemp() |
| 51 | |
| 52 | logger.info("Extracting... %s" % tmpzipPath) |
| 53 | with zipfile.ZipFile(tmpzipPath, 'r') as zip: |
| 54 | zip.extractall(path=tmpPath) |
| 55 | os.unlink(tmpzipPath) |
| 56 | |
| 57 | locale_paths = glob.glob(os.path.join(tmpPath, "**", "locale"), recursive=True) |
| 58 | if len(locale_paths) == 0: |
| 59 | raise Exception(_("Cannot find locale/ folder in .zip archive")) |
| 60 | |
| 61 | webodm_locale_dir = os.path.join(settings.BASE_DIR, "locale") |
| 62 | |
| 63 | for locale_path in locale_paths: |
| 64 | logger.info("Found locale at %s" % locale_path) |
| 65 | logger.info("Moving %s to %s..." % (locale_path, webodm_locale_dir)) |
| 66 | copymerge(locale_path, webodm_locale_dir) |
| 67 | |
| 68 | logger.info("Running python manage.py translate extract && python manage.py translate build --safe") |
| 69 | subprocess.call(['bash', '-c', 'python manage.py translate extract && %s python manage.py translate build --safe'], cwd=settings.BASE_DIR) |
| 70 | |
| 71 | return JsonResponse({'message': _("Translation files reloaded!"), 'reload': True}) |
| 72 | except Exception as e: |
| 73 | return JsonResponse({'error': str(e)}) |
| 74 | else: |
| 75 | return JsonResponse({'error': _("Invalid action")}) |
| 76 | else: |
| 77 | return render(request, 'app/dev_tools.html', { |
| 78 | 'title': _('Developer Tools'), |
| 79 | 'current_locale': get_language() |
| 80 | }) |
| 81 |
nothing calls this directly
no test coverage detected