add tg filter

This commit is contained in:
Kseninia Mikhaylova 2024-08-05 15:57:30 +03:00
parent 85875778ae
commit c97ddc41c7
9 changed files with 143 additions and 62 deletions

View File

@ -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,
}

View File

@ -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"])

2
dev.sh
View File

@ -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"

View File

@ -1,4 +1,4 @@
FROM ci.svs-tech.pro/library/node:21
FROM ci.svs-tech.pro/library/node:22
RUN mkdir -p /src

View File

@ -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',

158
front/package-lock.json generated
View File

@ -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",

View File

@ -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": {

View File

@ -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 })
}
</script>
<template>

View File

@ -1,10 +1,13 @@
<script setup lang="ts">
import { telegramLoginTemp } from 'vue3-telegram-login'
const items = ref()
const page = ref(1)
const pagination = ref({ total: 10, pageCount: 10 })
const user_id = ref()
const loadData = async () => {
const items_data = await apiCall<ApiPaged<TgItem>>(`tgbot/?page=${page.value}`)
const items_data = await apiCall<ApiPaged<TgItem>>(`tgbot/?page=${page.value}&user_id=${user_id.value}`)
const res = items_data.results
res.map(item => {
const uniq = [...new Set(item.tmc.map(el => el.tmc.id))]
@ -32,12 +35,19 @@ const columns = [
label: 'ID автора'
}
]
const testCallback = (user:any) => {
user_id.value = user.id
}
</script>
<template>
<div class="col-span-12 page-header">
<h1>Проведенные инвентаризации</h1>
</div>
<div class="col-span-12">
<div class="col-span-12" v-if="!user_id">
<telegramLoginTemp mode="callback" telegram-login="aarizona_test_bot" @callback="testCallback" />
</div>
<div class="col-span-12" v-if="user_id">
<UTable :rows="items" :columns="columns" :ui="{ td: { base: 'whitespace-normal max-w-sm align-top' } }">
<template #name-data="{ row }">
<h3>