P-42 Не забыть исправить проверку валидации

This commit is contained in:
iriska-gri committed 2024-06-26 14:41:52 +03:00
1 parent 8d8ad9390e
commit 90994e83de
12 files changed
+226 -316

No files matched your search

+8 -4
View File
@@ -39,13 +39,15 @@ class MyCalendars(APIView):
''' '''
print(request.data, '---------------')
try: try:
ob=MyCalendarPostParameters(data=request.data) ob=MyCalendarPostParameters(data=request.data)
if ob.is_valid(): if ob.is_valid():
ob = ob.data ob = ob.data
participant = ob['participant'] if 'participant' in ob else False participant = ob['participant'] if 'participant' in ob else False
del ob['participant'] del ob['participant']
if 'id' in ob: if 'id' in ob:
newcal,created = Calendar.objects.update_or_create(id=ob['id'],defaults=ob) newcal,created = Calendar.objects.update_or_create(id=ob['id'],defaults=ob)
@@ -55,14 +57,16 @@ class MyCalendars(APIView):
if participant != False: if participant != False:
ptspnt = [] ptspnt = []
for x in participant: for x in participant:
x['participant_calendar']=DictEmployee(id=x['participant_calendar']) x['participant_calendar']=DictEmployee(id=x['participant_calendar'])
print(x['participant_calendar'])
CalendarParticipants.objects.update_or_create(calendar=newcal, participant_calendar=x['participant_calendar'], newpart, created = CalendarParticipants.objects.update_or_create(calendar=newcal, participant_calendar=x['participant_calendar'],
defaults=x) defaults=x)
ptspnt.append(x['participant_calendar']) ptspnt.append(x['participant_calendar'])
print(ptspnt) print(ptspnt)
CalendarParticipants.objects.exclude(calendar=newcal,participant_calendar__in=ptspnt).delete() CalendarParticipants.objects.exclude(participant_calendar__in=ptspnt).filter(calendar=newcal).delete()
else: else:
return Response({"mess":"Ошибка валидации полей"}) return Response({"mess":"Ошибка валидации полей"})
except Exception as e: except Exception as e:
+1 -1
View File
@@ -138,7 +138,7 @@ class DailyloadAPIView(APIView):
}] }]
daily = result daily = result
print(daily,'dailydaily')
@@ -7,7 +7,6 @@
<v-form @submit.prevent="submit"> <v-form @submit.prevent="submit">
<v-row no-gutters class="justify-center"> <v-row no-gutters class="justify-center">
<v-col lg="8"> <v-col lg="8">
<v-text-field <v-text-field
v-model="form.fio" v-model="form.fio"
:counter="10" :counter="10"
@@ -51,10 +50,9 @@
<script> <script>
import { ref } from "vue"; import { ref } from "vue";
import { useAlertStore } from '@/store/useAlertStore' import { useAlertStore } from "@/store/useAlertStore";
import { clearAxios } from "@/utils/axios-api"; import { clearAxios } from "@/utils/axios-api";
export default { export default {
props: { props: {
idVacations: { idVacations: {
@@ -64,12 +62,11 @@ export default {
}, },
setup(props) { setup(props) {
const form = ref({ fio: "", email: "", tel: "", text: "" }); const form = ref({ fio: "", email: "", tel: "", text: "" });
const feedalert = useAlertStore().alert const feedalert = useAlertStore().alert;
const req = (val) => { const req = (val) => {
return !!val || "Поле обязательно" return !!val || "Поле обязательно";
} };
const rules = { const rules = {
fio: [ fio: [
@@ -93,11 +90,11 @@ export default {
"data", "data",
JSON.stringify({ ...form.value, vacancy_id: props.idVacations }) JSON.stringify({ ...form.value, vacancy_id: props.idVacations })
); );
if (file.value !==null) { if (file.value !== null) {
postFile.append("file", file.value[0]); postFile.append("file", file.value[0]);
} }
// Отправляет сообщение об отправлении при отсутсвии валидации!!!!!!!!!!!!!!!!!!!!!!!!!
clearAxios clearAxios
.post(`api/about_inspection/postresponsevacancy/`, postFile) .post(`api/about_inspection/postresponsevacancy/`, postFile)
.then((data) => { .then((data) => {
@@ -105,7 +102,6 @@ export default {
feedalert.text = data.data; feedalert.text = data.data;
feedalert.color = "teal-lighten-4"; feedalert.color = "teal-lighten-4";
feedalert.ico = "mdi-email-outline"; feedalert.ico = "mdi-email-outline";
}); });
}; };
@@ -72,7 +72,7 @@
</v-row> </v-row>
</v-card> </v-card>
</v-col> </v-col>
<v-col class="bg-green"> <v-col>
<v-btn @click="drawer_right = !drawer_right"> <v-btn @click="drawer_right = !drawer_right">
{{ drawer_right }} {{ drawer_right }}
</v-btn> </v-btn>
@@ -1,152 +0,0 @@
<template>
<v-select
v-model="selectedStaff"
:items="staff"
label="Выберите из списка или найдите по ФИО"
item-title="department"
item-value="department"
multiple
hide-details
variant="outlined"
density="compact"
class="max-height-select"
return-object
>
<template v-slot:selection="{ item, index }">
<!-- <v-chip v-if="(index < 1) && allStaff">
<span>Выбраны все сотрудники</span>
</v-chip> -->
<v-chip>
<span> {{ item.value }}</span>
</v-chip>
<!-- <span
v-if="index === 2"
class="text-grey text-caption align-self-center"
>
(+{{ selectedFruits.length - 2 }} others)
</span> -->
</template>
<template v-slot:prepend-item>
<v-list-item @click="toggle" class="text-body-2">
<span class="text-body-2"> ВСЕ СОТРУДНИКИ </span>
<template v-slot:prepend>
<v-checkbox-btn
:color="onePlusStaff ? 'indigo-darken-4' : undefined"
:indeterminate="onePlusStaff && !allStaff"
:model-value="allStaff"
></v-checkbox-btn>
</template>
</v-list-item>
<v-divider class="mt-2"></v-divider>
</template>
<template v-slot:item="{ props, item }">
<v-list-group v-bind="props" :value="item.raw.department">
<template v-slot:activator="{ props }">
<v-list-item
v-bind="props"
@click.stop=""
density="compact"
class="text-body-2"
>
</v-list-item>
</template>
<v-list-item
v-for="(x, i) in item.raw.staff"
:key="i"
:value="x.fio"
@click.stop="selectFIO(x, item.raw.id)"
density="compact"
>
<span class="text-body-2"> {{ x.fio }} </span>
</v-list-item>
</v-list-group>
<!-- <v-list-item v-bind="props" :title="item.raw.department">
<template v-slot:prepend>
<v-checkbox-btn
:color="onePlusStaff ? 'indigo-darken-4' : undefined"
:indeterminate="onePlusStaff && !allStaff"
:model-value="allStaff"
></v-checkbox-btn>
</template>
</v-list-item> -->
</template>
</v-select>
</template>
<script>
import { ref, onMounted, computed } from "vue";
export default {
setup() {
const staff = ref([
{
department: "ОКТП",
id: 1,
staff: [{ fio: "ГИС", id: 1 }, { fio: "СВВ", id: 2 }, { fio: "ФА", id: 3 }, { fio: "АА", id: 4 }],
},
{ department: "ОВТП", id: 2, staff: [{ fio: "ЩВ", id: 1 }, { fio: "ДК", id: 2 }] },
]);
const selectedStaff = ref([]);
const allStaff = computed(
() => selectedStaff.value.length === staff.value.length
);
const onePlusStaff = computed(() => selectedStaff.value.length > 0);
function toggle() {
if (allStaff.value) {
selectedStaff.value = [];
} else {
selectedStaff.value = staff.value.slice();
}
}
function selectFIO(user, dep) {
let ob = staff.value.find(el => el.id == dep)
ob['chek'] = false
let indx = selectedStaff.value.findIndex((i) => i.id == dep)
if (indx ==-1) {
selectedStaff.value.push(ob)
}
console.log(ob, 'ki')
}
return {
staff,
selectedStaff,
allStaff,
onePlusStaff,
selectFIO,
toggle,
};
},
};
</script>
<style>
.max-height-select .v-field__input {
max-height: 60px; /* Установите желаемую максимальную высоту */
overflow-y: auto; /* Добавьте прокрутку, если список превышает максимальную высоту */
overflow-x: hidden;
margin: 5px;
}
</style>
@@ -100,6 +100,10 @@ export default {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
editor: {
type: Boolean,
default: false,
},
}, },
setup(props, { emit }) { setup(props, { emit }) {
@@ -132,6 +136,7 @@ export default {
}); });
const selectedStaff = computed(() => { const selectedStaff = computed(() => {
let selected = []; let selected = [];
let idEmployees = []; let idEmployees = [];
@@ -139,7 +144,7 @@ export default {
e.employees e.employees
.filter((n) => n.selected == true) .filter((n) => n.selected == true)
.map((res) => { .map((res) => {
idEmployees.push({ participant_calendar: res.id }); idEmployees.push({ participant_calendar: res.id, editor: props.editor?1:props.participant.editor });
}); });
if (e.employees.every((n) => n.selected == true)) { if (e.employees.every((n) => n.selected == true)) {
e.selected = true; e.selected = true;
@@ -149,8 +154,10 @@ export default {
selected.push(...e.employees.filter((n) => n.selected == true)); selected.push(...e.employees.filter((n) => n.selected == true));
} }
}); });
emit("returnIdParticant", idEmployees); emit("returnIdParticant", idEmployees);
// console.log(selected, accountStore.user.is_idEmployee, props.editor, selected.some(e=> e.id== accountStore.user.is_idEmployee), '222222222222222222222222222222222222')
return selected; return selected;
}); });
@@ -1,10 +1,9 @@
<template> <template>
<v-dialog v-model="dialog_create_calendar" min-width="636" max-width="800"> <v-dialog v-model="dialog_create_calendar" min-width="636" max-width="800">
<v-card min-height="436" class="pa-3"> <v-card min-height="436" class="pa-3">
{{ calendar }}
<v-card-title class="pr-0 pl-2 d-flex justify-space-between"> <v-card-title class="pr-0 pl-2 d-flex justify-space-between">
{{ {{
calendar.hasOwnProperty("id") propsCalendar.hasOwnProperty("id")
? "Редактирование календаря" ? "Редактирование календаря"
: "Новый календарь" : "Новый календарь"
}} }}
@@ -15,110 +14,128 @@
@click="dialog_create_calendar = false" @click="dialog_create_calendar = false"
></v-icon> ></v-icon>
</v-card-title> </v-card-title>
<v-card-text class="d-flex py-0 px-3"> <v-form @submit.prevent="postCalendar">
<v-row no-gutters class="flex-column"> <v-card-text class="d-flex py-0 px-3">
<v-col class="d-flex flex-column"> <v-row no-gutters class="flex-column">
<v-row no-gutters class="align-center"> <v-col class="d-flex flex-column">
<v-col class="text-body-2 text-text_grey" lg="2"> <v-row no-gutters class="align-center">
Название <v-col class="text-body-2 text-text_grey" lg="2">
</v-col> Название
<v-col> </v-col>
<v-textarea <v-col>
density="compact" <v-textarea
label="Описание" density="compact"
row-height="25" label="Описание"
rows="1" row-height="25"
variant="outlined" rows="1"
hide-details variant="outlined"
v-model="calendar.cl_name" v-model="propsCalendar.cl_name"
></v-textarea></v-col :rules="rules.cl_name"
></v-row> ></v-textarea></v-col
<v-row no-gutters class="align-center pt-3"> ></v-row>
<v-col class="text-body-2 text-text_grey" lg="2"> Цвет </v-col> <v-row no-gutters class="align-center pt-3">
<v-col v-for="(x, key) in color" :key="key"> <v-col class="text-body-2 text-text_grey" lg="2"> Цвет </v-col>
<v-avatar <v-col v-for="(x, key) in color" :key="key">
class="cursor-pointer" <v-avatar
@click="colorPik(x, key)" class="cursor-pointer"
size="x-small" @click="colorPik(x, key)"
:color="x" size="x-small"
:variant=" :color="x"
calendar.cl_color === null :variant="
? 'flat' propsCalendar.cl_color === null
: calendar.cl_color === x ? 'flat'
? 'flat' : propsCalendar.cl_color === x
: 'tonal' ? 'flat'
" : 'tonal'
/> </v-col "
></v-row> /> </v-col
></v-row>
<v-row no-gutters class="align-center">
<v-col class="text-body-2 text-text_grey" lg="2">
Участники
</v-col>
<v-col>
<calendar-create-select
:participant="propsCalendar.participant"
@returnIdParticant="returnIdParticant"
/> </v-col
></v-row>
</v-col>
<v-col class="d-flex flex-grow-0">
<v-textarea
density="compact"
label="Описание"
row-height="25"
rows="4"
variant="outlined"
shaped
no-resize
:rules="rules.cl_descr"
v-model="propsCalendar.cl_descr"
></v-textarea>
</v-col>
<v-row no-gutters class="align-center"> <v-row no-gutters class="align-center">
<v-col class="text-body-2 text-text_grey" lg="2"> <v-col class="text-body-2 text-text_grey" lg="2">
Участники Редакторы
</v-col> </v-col>
<v-col> <v-col>
<calendar-create-select <calendar-create-select
:participant="calendar.participant" :editor="true"
:participant="
propsCalendar.participant.filter((e) => e.editor == 1)
"
@returnIdParticant="returnIdParticant" @returnIdParticant="returnIdParticant"
/> </v-col
></v-row>
</v-col>
<v-col class="d-flex flex-grow-0">
<v-textarea
density="compact"
label="Описание"
row-height="25"
rows="4"
variant="outlined"
hide-details
shaped
no-resize
v-model="calendar.cl_descr"
></v-textarea>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-btn
class="text-subtitle-1"
elevation="0"
width="150"
@click="dialog_create_calendar = false"
>Отменить</v-btn
>
<v-btn
class="text-subtitle-1 font-weight-regular"
color="btn_text"
variant="flat"
elevation="0"
width="150"
@click="postCalendar"
>
{{ calendar.hasOwnProperty("id") ? "Редактировать" : "Создать" }}
</v-btn>
</v-card-actions>
<!-- <v-row no-gutters class="gap flex-column">
v-col*
</v-row> -->
<!-- <v-row>
<v-col>
<v-textarea
v-model="newcalendar.cl_name"
placeholder="Название календаря"
no-resize
rows="1"
hide-details
density="compact"
/> />
</v-col> </v-col>
</v-row> <v-col lg="1" class="text-center">
<v-tooltip location="top">
<template v-slot:activator="{ props }">
<v-icon v-bind="props" icon="mdi-help-circle-outline" />
</template>
<div class="custom-tooltip">
Участники с доступом редактирования смогут изменять поля
календаря, а также редактировать и удалять события
</div>
</v-tooltip>
</v-col>
</v-row>
</v-row>
</v-card-text>
<v-card-actions class="justify-end">
<v-btn
icon="mdi-delete"
variant="tonal"
rounded
size="36px"
:disabled="!propsCalendar.hasOwnProperty('id')"
@click="delCalendar(propsCalendar.id)"
/>
<v-btn
class="text-subtitle-1"
elevation="0"
width="150"
@click="dialog_create_calendar = false"
color="btn_gray"
variant="flat"
>Отменить</v-btn
>
{{newcalendar}} --> <v-btn
class="text-subtitle-1 font-weight-regular"
color="btn_text"
variant="flat"
elevation="0"
width="150"
type="postCalendar"
>
{{
propsCalendar.hasOwnProperty("id") ? "Редактировать" : "Создать"
}}
</v-btn>
</v-card-actions>
</v-form>
</v-card> </v-card>
</v-dialog> </v-dialog>
</template> </template>
@@ -128,6 +145,7 @@ import { computed, ref } from "vue";
import { axiosApiInstance } from "@/utils/axios-api"; import { axiosApiInstance } from "@/utils/axios-api";
import calendarCreateSelect from "@/components/calendar_of_events/calendar-create-select.vue"; import calendarCreateSelect from "@/components/calendar_of_events/calendar-create-select.vue";
import { useAlertStore } from "@/store/useAlertStore"; import { useAlertStore } from "@/store/useAlertStore";
import { useAccountStore } from "@/store/AccountStore";
export default { export default {
components: { calendarCreateSelect }, components: { calendarCreateSelect },
@@ -140,31 +158,17 @@ export default {
calendar: { calendar: {
type: Object, type: Object,
default: { default: {},
cl_name: "",
participant: [{ editor: true, participant_calendar: 0 }],
cl_color: "",
cl_descr: "",
},
}, },
}, },
setup(props, { emit }) { setup(props, { emit }) {
const postParticant = {}; const postParticant = {};
const accountStore = useAccountStore();
// Возможно можно сделать запись короче // Возможно можно сделать запись короче
const returnIdParticant = (idPart) => { const returnIdParticant = (idPart) => {
console.log(props.calendar, "props.calendar"); postParticant.value = { ...props.calendar, participant: idPart };
let g = {
participant: [{participant_calendar: 107 }],
cl_name: "проба2",
cl_color: "lime",
cl_descr: "описание",
};
postParticant.value = g
// postParticant.value = { ...props.calendar, participant: idPart };
}; };
const dialog_create_calendar = computed({ const dialog_create_calendar = computed({
@@ -172,20 +176,45 @@ export default {
set: (value) => emit("update:opendialog", value), set: (value) => emit("update:opendialog", value),
}); });
const feedalert = useAlertStore().alert; const propsCalendar = computed({
get: () => props.calendar,
set: (value) => emit("update:calendar", value),
});
const feedalert = useAlertStore().alert;
const rules = {
cl_name: [(val) => req(val)],
cl_descr: [(val) => req(val)],
};
const postCalendar = () => { const postCalendar = () => {
console.log(postParticant.value, 'postParticant.valuepostParticant.value')
axiosApiInstance if (
.post(`api/calendar_of_events/my_calendars/`, postParticant.value) postParticant.value.participant.some(
.then((result) => { (e) => e.participant_calendar == accountStore.user.is_idEmployee
feedalert.alert = true; )
feedalert.text = result.data.mess; ) {
feedalert.ico = "mdi-check"; axiosApiInstance
feedalert.color = "green-darken-4"; .post(`api/calendar_of_events/my_calendars/`, postParticant.value)
emit("getCalendar"); .then((result) => {
});
dialog_create_calendar.value = false; feedalert.alert = true;
feedalert.text = result.data.mess;
feedalert.ico = "mdi-check";
feedalert.color = "green-darken-4";
emit("getCalendar");
if (result.data.mess != "Ошибка валидации полей") {
dialog_create_calendar.value = false;
}
});
} else {
feedalert.alert = true;
feedalert.text = "Вы не можете удалить себя из редакторов";
feedalert.color = "red-darken-2";
feedalert.ico = "mdi-alert-outline";
}
}; };
const color = [ const color = [
@@ -207,13 +236,33 @@ export default {
]; ];
const colorPik = (col) => { const colorPik = (col) => {
if (props.calendar.cl_color === col) { if (propsCalendar.value.cl_color === col) {
props.calendar.cl_color = null; propsCalendar.value.cl_color = null;
} else { } else {
props.calendar.cl_color = col; propsCalendar.value.cl_color = col;
} }
}; };
const delCalendar = (idcal) => {
console.log(idcal, "idcal");
axiosApiInstance
.delete(`api/calendar_of_events/my_calendars/?delid=${idcal}`)
.then((result) => {
feedalert.alert = true;
feedalert.text = result.data.mess;
feedalert.ico = "mdi-check";
feedalert.color = "orange-accent-1";
emit("getCalendar");
});
dialog_create_calendar.value = false;
};
const req = (val) => {
return !!val || "Поле обязательно";
};
return { return {
dialog_create_calendar, dialog_create_calendar,
@@ -221,9 +270,16 @@ export default {
color, color,
colorPik, colorPik,
returnIdParticant, returnIdParticant,
propsCalendar,
delCalendar,
rules,
}; };
}, },
}; };
</script> </script>
<style></style> <style>
.custom-tooltip {
max-width: 350px; /* Установка максимальной ширины для подсказки */
}
</style>
@@ -74,10 +74,12 @@
</template> </template>
</v-expansion-panel-text> </v-expansion-panel-text>
</v-expansion-panel> </v-expansion-panel>
<calendar-create <calendar-create
@update:opendialog="showDialog = $event" @update:opendialog="showDialog = $event"
:opendialog="showDialog" :opendialog="showDialog"
:calendar="calendar" :calendar="calendar"
@update:calendar="calendar = $event"
@getCalendar="$emit('getCalendar')" @getCalendar="$emit('getCalendar')"
/> />
</v-expansion-panels> </v-expansion-panels>
@@ -110,10 +112,17 @@ export default {
const trans = ref(false); const trans = ref(false);
const hover = ref(0); const hover = ref(0);
const editCreatedCalendar = (cal) => { const editCreatedCalendar = (cal) => {
calendar.value = cal; if (cal === undefined) {
calendar.value = {
cl_name: "",
participant: [{ editor: true, participant_calendar: accountStore.user.is_idEmployee }],
cl_color: "red",
cl_descr: "",
};
} else {
calendar.value = cal;
}
showDialog.value = true; showDialog.value = true;
}; };
@@ -136,7 +145,6 @@ export default {
openGroup, openGroup,
trans, trans,
hover, hover,
}; };
}, },
}; };
@@ -117,7 +117,6 @@ export default {
axiosApiInstance axiosApiInstance
.get("api/calendar_of_events/calendarEvents/") .get("api/calendar_of_events/calendarEvents/")
.then((data) => { .then((data) => {
console.log(data.data,'-vvv');
data.data.forEach((e) => { data.data.forEach((e) => {
e.start = formaDashTime(e.start); e.start = formaDashTime(e.start);
e.end = e.start; e.end = e.start;
@@ -22,16 +22,6 @@ export default {
set: (value) => emit("update:opendialog", value), set: (value) => emit("update:opendialog", value),
}); });
// const confirmation = () => {
// axiosApiInstance
// .get(`api/calendar_of_events/createEvents/`)
// .then((data) => {
// console.log(data.data, "datadatadatawwwwwwwwwwww");
// });
// };
// confirmation()
return { return {
dialog_create_event, dialog_create_event,
}; };
@@ -4,7 +4,7 @@
v-model="feedalert.alert" v-model="feedalert.alert"
:color="feedalert.color" :color="feedalert.color"
:icon="feedalert.ico" :icon="feedalert.ico"
variant="outlined"
> >
<v-icon :icon="feedalert.ico" /> <v-icon :icon="feedalert.ico" />
<span class="pl-2 text-body-2"> <span class="pl-2 text-body-2">
+4 -2
View File
@@ -45,7 +45,8 @@ export default createVuetify({
grey_white: '#FFFFFF', // Цвет для карточек grey_white: '#FFFFFF', // Цвет для карточек
insert_table: '#FAFAFA', insert_table: '#FAFAFA',
btn_text: '#00897B', // фигма, текст кнопки с иконкой btn_text: '#00897B', // фигма, текст кнопки с иконкой
select_list: '#E0EAE8' select_list: '#E0EAE8',
btn_gray: '#E0E0E0'
}, },
}, },
dark: { dark: {
@@ -72,7 +73,8 @@ export default createVuetify({
grey_white: '#212121', grey_white: '#212121',
insert_table: '#323030', insert_table: '#323030',
btn_text: '#00897B', btn_text: '#00897B',
select_list: '#E0EAE8' select_list: '#E0EAE8',
btn_gray: '#E0E0E0'
}, },
}, },
options: { options: {