delete btn
This commit is contained in:
parent
6e2cee0968
commit
64b3271c35
|
@ -1,14 +1,13 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http import StreamingHttpResponse, HttpResponse
|
from django.http import HttpResponse
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import boto3
|
import boto3
|
||||||
import io
|
|
||||||
|
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
|
|
||||||
from rest_framework import mixins, viewsets
|
from rest_framework import viewsets, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ logger = logging.getLogger("root")
|
||||||
class TgItemViewSet(viewsets.ModelViewSet):
|
class TgItemViewSet(viewsets.ModelViewSet):
|
||||||
queryset = TgItem.objects.all().order_by("-created_at")
|
queryset = TgItem.objects.all().order_by("-created_at")
|
||||||
serializer_class = TgItemSerializer
|
serializer_class = TgItemSerializer
|
||||||
http_method_names = ["post", "get", "patch"]
|
http_method_names = ["post", "get", "patch", "delete"]
|
||||||
permission_classes = ()
|
permission_classes = ()
|
||||||
authentication_classes = ()
|
authentication_classes = ()
|
||||||
|
|
||||||
|
@ -47,6 +46,13 @@ class TgItemViewSet(viewsets.ModelViewSet):
|
||||||
request.data["location"] = 35
|
request.data["location"] = 35
|
||||||
return super().partial_update(request)
|
return super().partial_update(request)
|
||||||
|
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
instance = self.get_object()
|
||||||
|
if instance.tmc.count() == 0:
|
||||||
|
return super().destroy(request)
|
||||||
|
else:
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
@action(detail=False, methods=["post"], url_path=settings.TGBOT["WEBHOOK_URL"])
|
@action(detail=False, methods=["post"], url_path=settings.TGBOT["WEBHOOK_URL"])
|
||||||
def send_tg_data(self, request):
|
def send_tg_data(self, request):
|
||||||
tg_bot_updater_instance.my_queue.put(
|
tg_bot_updater_instance.my_queue.put(
|
||||||
|
@ -110,6 +116,6 @@ class TmcFieldViewset(viewsets.ModelViewSet):
|
||||||
)
|
)
|
||||||
get_object_response = s3.get_object(Bucket="inventorization", Key=file_id)
|
get_object_response = s3.get_object(Bucket="inventorization", Key=file_id)
|
||||||
image = get_object_response["Body"].read()
|
image = get_object_response["Body"].read()
|
||||||
response = HttpResponse(image, content_type='image/jpeg')
|
response = HttpResponse(image, content_type="image/jpeg")
|
||||||
response['Content-Disposition'] = 'inline; filename="image.jpeg"'
|
response["Content-Disposition"] = 'inline; filename="image.jpeg"'
|
||||||
return response
|
return response
|
|
@ -6,12 +6,14 @@ const items = ref()
|
||||||
const page = ref(1)
|
const page = ref(1)
|
||||||
const pagination = ref({ total: 10, pageCount: 10 })
|
const pagination = ref({ total: 10, pageCount: 10 })
|
||||||
const user_id = ref()
|
const user_id = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
if (process.env.NODE_ENV == 'development') {
|
if (process.env.NODE_ENV == 'development') {
|
||||||
user_id.value = ''
|
user_id.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
|
loading.value = true
|
||||||
const items_data = await apiCall<ApiPaged<TgItem>>(`tgbot/?page=${page.value}&user_id=${user_id.value || ''}`)
|
const items_data = await apiCall<ApiPaged<TgItem>>(`tgbot/?page=${page.value}&user_id=${user_id.value || ''}`)
|
||||||
const res = items_data.results
|
const res = items_data.results
|
||||||
res.map(item => {
|
res.map(item => {
|
||||||
|
@ -22,6 +24,7 @@ const loadData = async () => {
|
||||||
items.value = res
|
items.value = res
|
||||||
pagination.value.total = items_data.count
|
pagination.value.total = items_data.count
|
||||||
pagination.value.pageCount = items_data.per_page
|
pagination.value.pageCount = items_data.per_page
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
onMounted(loadData)
|
onMounted(loadData)
|
||||||
watch(page, loadData)
|
watch(page, loadData)
|
||||||
|
@ -45,6 +48,11 @@ const testCallback = (user: any) => {
|
||||||
user_id.value = user.id
|
user_id.value = user.id
|
||||||
loadData()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteInv = async (id: string) => {
|
||||||
|
const res = await apiCall<ApiPaged<TgItem>>(`tgbot/${id}/`, 'delete')
|
||||||
|
loadData()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="col-span-12 page-header">
|
<div class="col-span-12 page-header">
|
||||||
|
@ -59,7 +67,8 @@ const testCallback = (user: any) => {
|
||||||
</UCard>
|
</UCard>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-12" v-else>
|
<div class="col-span-12" v-else>
|
||||||
<UTable :rows="items" :columns="columns" :ui="{ td: { base: 'whitespace-normal max-w-sm align-top' } }">
|
<UTable :rows="items" :columns="columns" :ui="{ td: { base: 'whitespace-normal max-w-sm align-top' } }"
|
||||||
|
:loading="loading">
|
||||||
<template #name-data="{ row }">
|
<template #name-data="{ row }">
|
||||||
<h3>
|
<h3>
|
||||||
<NuxtLink :to="`table/${row.id}`">{{ row.name }}</NuxtLink>
|
<NuxtLink :to="`table/${row.id}`">{{ row.name }}</NuxtLink>
|
||||||
|
@ -68,26 +77,31 @@ const testCallback = (user: any) => {
|
||||||
Обновлено: {{ new Date(row.updated_at).toLocaleString('ru-RU') }}
|
Обновлено: {{ new Date(row.updated_at).toLocaleString('ru-RU') }}
|
||||||
</template>
|
</template>
|
||||||
<template #tmc-data="{ row }">
|
<template #tmc-data="{ row }">
|
||||||
<div v-for="uniq_tmc in row.uniq" class="inv_element">
|
<template v-if="row.uniq.length">
|
||||||
<h3>{{ uniq_tmc[0].tmc.name }}</h3>
|
<div v-for="uniq_tmc in row.uniq" class="inv_element">
|
||||||
<div class="inv_item" v-for="item in uniq_tmc">
|
<h3>{{ uniq_tmc[0].tmc.name }}</h3>
|
||||||
<ul class="inv_list">
|
<div class="inv_item" v-for="item in uniq_tmc">
|
||||||
<li v-for="el in item.field" class="inv_inner">
|
<ul class="inv_list">
|
||||||
<span class="inv_inner_name">
|
<li v-for="el in item.field" class="inv_inner">
|
||||||
{{ el.field.name }}:
|
<span class="inv_inner_name">
|
||||||
</span>
|
{{ el.field.name }}:
|
||||||
<span class="inv_inner_text" v-if="el.text">
|
</span>
|
||||||
{{ el.text }}
|
<span class="inv_inner_text" v-if="el.text">
|
||||||
</span>
|
{{ el.text }}
|
||||||
<UBadge color="gray" v-else>no text</UBadge>
|
</span>
|
||||||
<span class="inv_inner_image" v-if="el.file_id">
|
<UBadge color="gray" v-else>no text</UBadge>
|
||||||
<GetImage :file_id="el.file_id" :image_aws_url="el.image_aws_url" />
|
<span class="inv_inner_image" v-if="el.file_id">
|
||||||
</span>
|
<GetImage :file_id="el.file_id" :image_aws_url="el.image_aws_url" />
|
||||||
<UBadge color="gray" v-else>no img</UBadge>
|
</span>
|
||||||
</li>
|
<UBadge color="gray" v-else>no img</UBadge>
|
||||||
</ul>
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<UButton @click="deleteInv(row.id)" :disabled="loading">Удалить инвентаризацию</UButton>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<template #user_id-data="{ row }">
|
<template #user_id-data="{ row }">
|
||||||
<GetAuthor :user_id="row.user_id" />
|
<GetAuthor :user_id="row.user_id" />
|
||||||
|
|
Loading…
Reference in New Issue