From d475ee2999a1fd43c03518100bd55b0929acc5d9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 24 Jul 2019 15:41:54 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82=D0=B8=D0=BF=20=D0=B2?= =?UTF-8?q?=D1=81=D0=BF=D0=BB=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B8=D1=85=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9.=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20UPDATE?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?mysql=20=D0=BE=D0=B1=D0=B5=D1=80=D1=82=D0=BA=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day9/task5_vue/backend/database/wrappers.py | 20 ++++++++++++++------ day9/task5_vue/src/App.vue | 12 ++++++------ day9/task5_vue/src/components/EditFormBox.vue | 2 +- day9/task5_vue/src/components/PopupMessage.vue | 20 ++++++++++++++++---- day9/task5_vue/src/components/Table.vue | 13 +++++++++---- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/day9/task5_vue/backend/database/wrappers.py b/day9/task5_vue/backend/database/wrappers.py index d380b2e..d7dc6d4 100644 --- a/day9/task5_vue/backend/database/wrappers.py +++ b/day9/task5_vue/backend/database/wrappers.py @@ -90,17 +90,25 @@ class MySQLWrapper(Wrapper): self.connection.commit() def update(self, table_name, expressions, conditions): + scheme = self.schemes[table_name] expressions_formatted = [] + for field_name, value in expressions.items(): - if value != 'NULL' or not value.isnumeric(): - value = f'"{value}"' - expressions_formatted.append(f'`{field_name}`={value}') + if scheme.fields[field_name].nullable and value is None: + expressions_formatted.append(f'`{field_name}`=NULL') + elif scheme.fields[field_name].data_type == str: + expressions_formatted.append(f'`{field_name}`="{value}"') + else: + expressions_formatted.append(f'`{field_name}`={value}') conditions_formatted = [] for field_name, value in conditions.items(): - if value != 'NULL' or not value.isnumeric(): - value = f'"{value}"' - conditions_formatted.append(f'`{field_name}`={value}') + if scheme.fields[field_name].nullable and value is None: + conditions_formatted.append(f'`{field_name}`=NULL') + elif scheme.fields[field_name].data_type == str: + conditions_formatted.append(f'`{field_name}`="{value}"') + else: + conditions_formatted.append(f'`{field_name}`={value}') with self.connection.cursor() as cursor: cursor.execute("UPDATE `{}` SET {} WHERE {};".format( diff --git a/day9/task5_vue/src/App.vue b/day9/task5_vue/src/App.vue index 42ba3b1..9322db3 100644 --- a/day9/task5_vue/src/App.vue +++ b/day9/task5_vue/src/App.vue @@ -7,12 +7,12 @@ @show-popup="showPopup($event)" v-if="isFormShown" /> - +
- + @@ -39,7 +39,7 @@ isFormShown: false, isPopupShown: false, - popupMessage: '', + popupData: null, } }, @@ -61,14 +61,14 @@ }) }, - showPopup(message) { + showPopup(data) { if (!this.isPopupShown) { this.isPopupShown = true; - this.popupMessage = message; + this.popupData = data; setTimeout(() => { this.isPopupShown = false; - this.popupMessage = ''; + this.popupData = null; }, 2000) } }, diff --git a/day9/task5_vue/src/components/EditFormBox.vue b/day9/task5_vue/src/components/EditFormBox.vue index 42bb3c6..276dbbe 100644 --- a/day9/task5_vue/src/components/EditFormBox.vue +++ b/day9/task5_vue/src/components/EditFormBox.vue @@ -170,7 +170,7 @@ }) .then(response => { this.$emit('close-form'); - this.$emit('show-popup', 'Database updated successfully'); + this.$emit('show-popup', {'type': 'success', 'meg': 'Database updated successfully'}); }); } } diff --git a/day9/task5_vue/src/components/PopupMessage.vue b/day9/task5_vue/src/components/PopupMessage.vue index a905b4d..90e28da 100644 --- a/day9/task5_vue/src/components/PopupMessage.vue +++ b/day9/task5_vue/src/components/PopupMessage.vue @@ -1,19 +1,23 @@ \ No newline at end of file diff --git a/day9/task5_vue/src/components/Table.vue b/day9/task5_vue/src/components/Table.vue index 97bc24d..d94afe2 100644 --- a/day9/task5_vue/src/components/Table.vue +++ b/day9/task5_vue/src/components/Table.vue @@ -50,15 +50,20 @@ }, removeField(serviceId) { - this.tableData.content = this.tableData.content.filter(row => row[0].toString() !== serviceId); axios .request({ url: '/api/delete', method: 'post', - data: {'service_id': serviceId} + data: {'service_id': parseInt(serviceId)} }) .then(response => { - if (response.status === 200) - this.tableData = this.tableData.content.filter(row => row[0] !== serviceId); + if (response.status === 200) { + let err = response.data.error; + + if (err) this.$emit('show-popup', {'type': 'failure', 'msg': response.data.service_id}); + else this.tableData.content = this.tableData.content.filter(row => row[0].toString() !== serviceId); + + } + }); } -- cgit v1.2.3