delete btn
This commit is contained in:
parent
6e2cee0968
commit
64b3271c35
|
@ -1,14 +1,13 @@
|
|||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.http import StreamingHttpResponse, HttpResponse
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
import time
|
||||
import boto3
|
||||
import io
|
||||
|
||||
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.decorators import action
|
||||
|
||||
|
@ -27,7 +26,7 @@ logger = logging.getLogger("root")
|
|||
class TgItemViewSet(viewsets.ModelViewSet):
|
||||
queryset = TgItem.objects.all().order_by("-created_at")
|
||||
serializer_class = TgItemSerializer
|
||||
http_method_names = ["post", "get", "patch"]
|
||||
http_method_names = ["post", "get", "patch", "delete"]
|
||||
permission_classes = ()
|
||||
authentication_classes = ()
|
||||
|
||||
|
@ -47,6 +46,13 @@ class TgItemViewSet(viewsets.ModelViewSet):
|
|||
request.data["location"] = 35
|
||||
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"])
|
||||
def send_tg_data(self, request):
|
||||
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)
|
||||
image = get_object_response["Body"].read()
|
||||
response = HttpResponse(image, content_type='image/jpeg')
|
||||
response['Content-Disposition'] = 'inline; filename="image.jpeg"'
|
||||
response = HttpResponse(image, content_type="image/jpeg")
|
||||
response["Content-Disposition"] = 'inline; filename="image.jpeg"'
|
||||
return response
|
|
@ -6,12 +6,14 @@ const items = ref()
|
|||
const page = ref(1)
|
||||
const pagination = ref({ total: 10, pageCount: 10 })
|
||||
const user_id = ref()
|
||||
const loading = ref(false)
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
user_id.value = ''
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
const items_data = await apiCall<ApiPaged<TgItem>>(`tgbot/?page=${page.value}&user_id=${user_id.value || ''}`)
|
||||
const res = items_data.results
|
||||
res.map(item => {
|
||||
|
@ -22,6 +24,7 @@ const loadData = async () => {
|
|||
items.value = res
|
||||
pagination.value.total = items_data.count
|
||||
pagination.value.pageCount = items_data.per_page
|
||||
loading.value = false
|
||||
}
|
||||
onMounted(loadData)
|
||||
watch(page, loadData)
|
||||
|
@ -45,6 +48,11 @@ const testCallback = (user: any) => {
|
|||
user_id.value = user.id
|
||||
loadData()
|
||||
}
|
||||
|
||||
const deleteInv = async (id: string) => {
|
||||
const res = await apiCall<ApiPaged<TgItem>>(`tgbot/${id}/`, 'delete')
|
||||
loadData()
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="col-span-12 page-header">
|
||||
|
@ -59,7 +67,8 @@ const testCallback = (user: any) => {
|
|||
</UCard>
|
||||
</div>
|
||||
<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 }">
|
||||
<h3>
|
||||
<NuxtLink :to="`table/${row.id}`">{{ row.name }}</NuxtLink>
|
||||
|
@ -68,6 +77,7 @@ const testCallback = (user: any) => {
|
|||
Обновлено: {{ new Date(row.updated_at).toLocaleString('ru-RU') }}
|
||||
</template>
|
||||
<template #tmc-data="{ row }">
|
||||
<template v-if="row.uniq.length">
|
||||
<div v-for="uniq_tmc in row.uniq" class="inv_element">
|
||||
<h3>{{ uniq_tmc[0].tmc.name }}</h3>
|
||||
<div class="inv_item" v-for="item in uniq_tmc">
|
||||
|
@ -89,6 +99,10 @@ const testCallback = (user: any) => {
|
|||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<UButton @click="deleteInv(row.id)" :disabled="loading">Удалить инвентаризацию</UButton>
|
||||
</template>
|
||||
</template>
|
||||
<template #user_id-data="{ row }">
|
||||
<GetAuthor :user_id="row.user_id" />
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue