From c97ddc41c79fc3bf0890f3db2a95fdfbd4b101e7 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Mon, 5 Aug 2024 15:57:30 +0300 Subject: [PATCH] add tg filter --- back/api/settings.py | 6 +- back/tgbot/views.py | 13 ++- dev.sh | 2 +- front/Dockerfile | 2 +- front/nuxt.config.ts | 7 +- front/package-lock.json | 158 ++++++++++++++++++++++++------------ front/package.json | 1 + front/pages/table/[id].vue | 2 +- front/pages/table/index.vue | 14 +++- 9 files changed, 143 insertions(+), 62 deletions(-) diff --git a/back/api/settings.py b/back/api/settings.py index 2b927e8..0f78bf0 100644 --- a/back/api/settings.py +++ b/back/api/settings.py @@ -32,14 +32,14 @@ NGROK_TEMP = os.environ.get("NGROK_TEMP") ALLOWED_HOSTS = [ "localhost", NGROK_TEMP, - "192.168.103.159", + "192.168.106.234", "back", "toinv.svs-tech.pro", ] CORS_ALLOWED_ORIGINS = [ "http://localhost", "http://localhost:3000", - "http://192.168.103.159:3000", + "http://192.168.106.234:3000", "https://toinv.svs-tech.pro", ] CSRF_TRUSTED_ORIGINS = [ @@ -50,6 +50,7 @@ CSRF_TRUSTED_ORIGINS = [ INSTALLED_APPS = [ "corsheaders", + "django_filters", "rest_framework", "inventory", "tgbot", @@ -97,6 +98,7 @@ WSGI_APPLICATION = "api.wsgi.application" # Rest Framework REST_FRAMEWORK = { + "DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"], "DEFAULT_PAGINATION_CLASS": "tgbot.pagination.CustomPagination", "PAGE_SIZE": 5, } diff --git a/back/tgbot/views.py b/back/tgbot/views.py index eb0f820..36187b6 100644 --- a/back/tgbot/views.py +++ b/back/tgbot/views.py @@ -10,11 +10,16 @@ from rest_framework import mixins, viewsets from rest_framework.response import Response from rest_framework.decorators import action +from django_filters.rest_framework import DjangoFilterBackend + from .tgbot import TgBot from .apps import TgBotUpdater -from .models import TgItem, TmcElement, TmcField +from .models import TgItem, TmcField from .serializers import TgItemSerializer, TmcFieldSerializer +from tmc.models import TerritoryItem +from tmc.serializers import TerritoryItemSerializer + import logging logger = logging.getLogger("root") @@ -27,6 +32,9 @@ class TgItemViewSet(viewsets.ModelViewSet): permission_classes = () authentication_classes = () + filter_backends = [DjangoFilterBackend] + filterset_fields = ['user_id'] + def retrieve(self, request, pk=None): item = TgItem.objects.get(id=pk) logger.info( @@ -36,7 +44,8 @@ class TgItemViewSet(viewsets.ModelViewSet): # return Response(serializer.data) def partial_update(self, request, *args, **kwargs): - # logger.info(request.data['location_id']) + if 'location_id' in request.data: + request.data['location'] = 35 return super().partial_update(request) @action(detail=False, methods=["post"], url_path=settings.TGBOT["WEBHOOK_URL"]) diff --git a/dev.sh b/dev.sh index db8ad11..66390fe 100755 --- a/dev.sh +++ b/dev.sh @@ -1,3 +1,3 @@ #!/bin/bash -x-terminal-emulator -title "To Invetory FRONT" -e "cd front && npm run dev -- --host"& +x-terminal-emulator -title "To Invetory FRONT" -e "cd front && npm run dev -p 80 -- --host"& x-terminal-emulator -title "To Invetory BACK" -e "cd back && poetry run task server" \ No newline at end of file diff --git a/front/Dockerfile b/front/Dockerfile index 1c08803..7e70360 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -1,4 +1,4 @@ -FROM ci.svs-tech.pro/library/node:21 +FROM ci.svs-tech.pro/library/node:22 RUN mkdir -p /src diff --git a/front/nuxt.config.ts b/front/nuxt.config.ts index 01ea01d..a0c264b 100644 --- a/front/nuxt.config.ts +++ b/front/nuxt.config.ts @@ -2,7 +2,12 @@ export default defineNuxtConfig({ ssr: false, devtools: { enabled: true }, - modules: ["@nuxt/ui", "nuxt-svgo", "@pinia/nuxt", "@nuxt/image"], + modules: [ + "@nuxt/ui", + "nuxt-svgo", + "@pinia/nuxt", + "@nuxt/image", + ], runtimeConfig: { public: { apiBase: '/api', diff --git a/front/package-lock.json b/front/package-lock.json index 62bddcb..269d348 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -15,6 +15,7 @@ "pinia": "^2.1.7", "vue": "^3.4.27", "vue-router": "^4.3.2", + "vue3-telegram-login": "^1.1.0", "yup": "^1.4.0" }, "devDependencies": { @@ -1350,9 +1351,10 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.25", @@ -4930,22 +4932,31 @@ } }, "node_modules/c12": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/c12/-/c12-1.10.0.tgz", - "integrity": "sha512-0SsG7UDhoRWcuSvKWHaXmu5uNjDCDN3nkQLRL4Q42IlFy+ze58FcCoI3uPwINXinkz7ZinbhEgyzYFw9u9ZV8g==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/c12/-/c12-1.11.1.tgz", + "integrity": "sha512-KDU0TvSvVdaYcQKQ6iPHATGz/7p/KiVjPg4vQrB6Jg/wX9R0yl5RZxWm9IoZqaIHD2+6PZd81+KMGwRr/lRIUg==", + "license": "MIT", "dependencies": { "chokidar": "^3.6.0", - "confbox": "^0.1.3", + "confbox": "^0.1.7", "defu": "^6.1.4", "dotenv": "^16.4.5", - "giget": "^1.2.1", - "jiti": "^1.21.0", - "mlly": "^1.6.1", + "giget": "^1.2.3", + "jiti": "^1.21.6", + "mlly": "^1.7.1", "ohash": "^1.1.3", "pathe": "^1.1.2", "perfect-debounce": "^1.0.0", - "pkg-types": "^1.0.3", - "rc9": "^2.1.1" + "pkg-types": "^1.1.1", + "rc9": "^2.1.2" + }, + "peerDependencies": { + "magicast": "^0.3.4" + }, + "peerDependenciesMeta": { + "magicast": { + "optional": true + } } }, "node_modules/cac": { @@ -6554,9 +6565,10 @@ } }, "node_modules/globby": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.1.tgz", - "integrity": "sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", + "integrity": "sha512-s3Fq41ZVh7vbbe2PN3nrW7yC7U7MFVc5c98/iTl9c2GawNMKx/J648KQRW6WKkuU8GIbbh2IXfIRQjOZnXcTnw==", + "license": "MIT", "dependencies": { "@sindresorhus/merge-streams": "^2.1.0", "fast-glob": "^3.3.2", @@ -7250,9 +7262,10 @@ } }, "node_modules/jiti": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", - "integrity": "sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==", + "version": "1.21.6", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.6.tgz", + "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==", + "license": "MIT", "bin": { "jiti": "bin/jiti.js" } @@ -7684,11 +7697,12 @@ } }, "node_modules/magic-string": { - "version": "0.30.10", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", - "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", + "version": "0.30.11", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.11.tgz", + "integrity": "sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==", + "license": "MIT", "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.15" + "@jridgewell/sourcemap-codec": "^1.5.0" } }, "node_modules/magic-string-ast": { @@ -8077,13 +8091,14 @@ "optional": true }, "node_modules/mlly": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.7.0.tgz", - "integrity": "sha512-U9SDaXGEREBYQgfejV97coK0UL1r+qnF2SyO9A3qcI8MzKnsIFKHNVEkrDyNncQTKQQumsasmeq84eNMdBfsNQ==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.7.1.tgz", + "integrity": "sha512-rrVRZRELyQzrIUAVMHxP97kv+G786pHmOKzuFII8zDYahFBS7qnHh2AlYSl1GAHhaMPCz6/oHjVMcfFYgFYHgA==", + "license": "MIT", "dependencies": { "acorn": "^8.11.3", "pathe": "^1.1.2", - "pkg-types": "^1.1.0", + "pkg-types": "^1.1.1", "ufo": "^1.5.3" } }, @@ -9223,12 +9238,13 @@ } }, "node_modules/pkg-types": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.1.1.tgz", - "integrity": "sha512-ko14TjmDuQJ14zsotODv7dBlwxKhUKQEhuhmbqo1uCi9BB0Z2alo/wAXg6q1dTR5TyuqYyWhjtfe/Tsh+X28jQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.1.3.tgz", + "integrity": "sha512-+JrgthZG6m3ckicaOB74TwQ+tBWsFl3qVQg7mN8ulwSOElJ7gBhKzj2VkCPnZ4NlF6kEquYU+RIYNVAvzd54UA==", + "license": "MIT", "dependencies": { "confbox": "^0.1.7", - "mlly": "^1.7.0", + "mlly": "^1.7.1", "pathe": "^1.1.2" } }, @@ -10542,9 +10558,10 @@ "integrity": "sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==" }, "node_modules/semver": { - "version": "7.6.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", - "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -11644,9 +11661,10 @@ } }, "node_modules/ufo": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.3.tgz", - "integrity": "sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==" + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.4.tgz", + "integrity": "sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==", + "license": "MIT" }, "node_modules/ultrahtml": { "version": "1.5.3", @@ -11748,23 +11766,36 @@ } }, "node_modules/unimport": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/unimport/-/unimport-3.7.2.tgz", - "integrity": "sha512-91mxcZTadgXyj3lFWmrGT8GyoRHWuE5fqPOjg5RVtF6vj+OfM5G6WCzXjuYtSgELE5ggB34RY4oiCSEP8I3AHw==", + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/unimport/-/unimport-3.10.0.tgz", + "integrity": "sha512-/UvKRfWx3mNDWwWQhR62HsoM3wxHwYdTq8ellZzMOHnnw4Dp8tovgthyW7DjTrbjDL+i4idOp06voz2VKlvrLw==", + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.1.0", - "acorn": "^8.11.3", + "acorn": "^8.12.1", "escape-string-regexp": "^5.0.0", "estree-walker": "^3.0.3", "fast-glob": "^3.3.2", "local-pkg": "^0.5.0", - "magic-string": "^0.30.10", - "mlly": "^1.7.0", + "magic-string": "^0.30.11", + "mlly": "^1.7.1", "pathe": "^1.1.2", - "pkg-types": "^1.1.1", + "pkg-types": "^1.1.3", "scule": "^1.3.0", "strip-literal": "^2.1.0", - "unplugin": "^1.10.1" + "unplugin": "^1.12.0" + } + }, + "node_modules/unimport/node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" } }, "node_modules/unique-filename": { @@ -11844,14 +11875,15 @@ } }, "node_modules/unplugin": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/unplugin/-/unplugin-1.10.1.tgz", - "integrity": "sha512-d6Mhq8RJeGA8UfKCu54Um4lFA0eSaRa3XxdAJg8tIdxbu1ubW0hBCZUL7yI2uGyYCRndvbK8FLHzqy2XKfeMsg==", + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/unplugin/-/unplugin-1.12.0.tgz", + "integrity": "sha512-KeczzHl2sATPQUx1gzo+EnUkmN4VmGBYRRVOZSGvGITE9rGHRDGqft6ONceP3vgXcyJ2XjX5axG5jMWUwNCYLw==", + "license": "MIT", "dependencies": { - "acorn": "^8.11.3", + "acorn": "^8.12.1", "chokidar": "^3.6.0", "webpack-sources": "^3.2.3", - "webpack-virtual-modules": "^0.6.1" + "webpack-virtual-modules": "^0.6.2" }, "engines": { "node": ">=14.0.0" @@ -11896,6 +11928,18 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/unplugin/node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/unstorage": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/unstorage/-/unstorage-1.10.2.tgz", @@ -12554,6 +12598,15 @@ "resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz", "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==" }, + "node_modules/vue3-telegram-login": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/vue3-telegram-login/-/vue3-telegram-login-1.1.0.tgz", + "integrity": "sha512-/uDFS1nrKaUemR9y63mu5et9axqfkGExrC4bpmX5iOuquQXZK4RXrPd3WQvOJ/LDRZDkITpdN18fVmcveTGJCA==", + "license": "MIT", + "dependencies": { + "vue": "^3.4.21" + } + }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", @@ -12568,9 +12621,10 @@ } }, "node_modules/webpack-virtual-modules": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/webpack-virtual-modules/-/webpack-virtual-modules-0.6.1.tgz", - "integrity": "sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==" + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/webpack-virtual-modules/-/webpack-virtual-modules-0.6.2.tgz", + "integrity": "sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==", + "license": "MIT" }, "node_modules/whatwg-url": { "version": "5.0.0", diff --git a/front/package.json b/front/package.json index e8d4114..c04f0fd 100644 --- a/front/package.json +++ b/front/package.json @@ -18,6 +18,7 @@ "pinia": "^2.1.7", "vue": "^3.4.27", "vue-router": "^4.3.2", + "vue3-telegram-login": "^1.1.0", "yup": "^1.4.0" }, "devDependencies": { diff --git a/front/pages/table/[id].vue b/front/pages/table/[id].vue index c4903fb..3bd5598 100644 --- a/front/pages/table/[id].vue +++ b/front/pages/table/[id].vue @@ -46,7 +46,7 @@ const patchField = async (field) => { await apiCall(`tgbot/items/${field.id}/`, 'patch', { text: field.text }) } const patchItem = async () => { - await apiCall(`tgbot/${state.id}/`, 'patch', { name: state.name, location: state.location }) + await apiCall(`tgbot/${state.id}/`, 'patch', { name: state.name, location_id: state.location }) }