Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6425fa36

Přidáno uživatelem David Friesecký před téměř 4 roky(ů)

Re #8670 - Modified deletion for historical storage of certificates

Zobrazit rozdíly:

src/dao/certificate_repository.py
1
import time
1 2
from sqlite3 import Connection, Error
2 3
from typing import Dict, List
3 4

  
......
81 82

  
82 83
        try:
83 84
            sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
84
                   f"WHERE {COL_ID} = ?")
85
                   f"WHERE {COL_ID} = ? AND ({COL_DELETION_DATE} IS NULL OR {COL_DELETION_DATE} = '')")
85 86
            values = [certificate_id]
86 87
            self.cursor.execute(sql, values)
87 88
            certificate_row = self.cursor.fetchone()
......
103 104
                                                   certificate_row[2],
104 105
                                                   certificate_row[3],
105 106
                                                   certificate_row[4],
106
                                                   certificate_row[7],
107 107
                                                   certificate_row[8],
108 108
                                                   certificate_row[9],
109
                                                   certificate_row[10],
109 110
                                                   usage_dict,
110 111
                                                   certificate_row[5],
111 112
                                                   certificate_row[6])
......
127 128
            sql_extension = ""
128 129
            values = []
129 130
            if filter_type is not None:
130
                sql_extension = (f" WHERE {COL_TYPE_ID} = ("
131
                sql_extension = (f" AND {COL_TYPE_ID} = ("
131 132
                                 f"SELECT {COL_ID} FROM {TAB_CERTIFICATE_TYPES} WHERE {COL_ID} = ?)")
132 133
                values = [filter_type]
133 134

  
134
            sql = f"SELECT * FROM {TAB_CERTIFICATES}{sql_extension}"
135
            sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
136
                   f"WHERE ({COL_DELETION_DATE} IS NULL OR {COL_DELETION_DATE} = ''){sql_extension}")
135 137
            self.cursor.execute(sql, values)
136 138
            certificate_rows = self.cursor.fetchall()
137 139

  
......
152 154
                                                certificate_row[2],
153 155
                                                certificate_row[3],
154 156
                                                certificate_row[4],
155
                                                certificate_row[7],
156 157
                                                certificate_row[8],
157 158
                                                certificate_row[9],
159
                                                certificate_row[10],
158 160
                                                usage_dict,
159 161
                                                certificate_row[5],
160 162
                                                certificate_row[6]))
......
193 195
                      certificate.type_id,
194 196
                      certificate.parent_id,
195 197
                      certificate_id]
198

  
199
            print(f"Parent: {certificate.parent_id}")
200

  
196 201
            self.cursor.execute(sql, values)
197 202
            self.connection.commit()
198 203

  
......
227 232
        """
228 233

  
229 234
        try:
230
            sql = (f"DELETE FROM {TAB_CERTIFICATES} "
231
                   f"WHERE {COL_ID} = ?")
232
            values = [certificate_id]
235
            sql = (f"UPDATE {TAB_CERTIFICATES} "
236
                   f"SET {COL_DELETION_DATE} = ? "
237
                   f"WHERE {COL_ID} = ? AND ({COL_DELETION_DATE} IS NULL OR {COL_DELETION_DATE} = '')")
238
            values = [int(time.time()),
239
                      certificate_id]
233 240
            self.cursor.execute(sql, values)
234 241
            self.connection.commit()
235 242
        except Error as e:
......
331 338
                                                certificate_row[2],
332 339
                                                certificate_row[3],
333 340
                                                certificate_row[4],
334
                                                certificate_row[7],
335 341
                                                certificate_row[8],
336 342
                                                certificate_row[9],
343
                                                certificate_row[10],
337 344
                                                usage_dict,
338 345
                                                certificate_row[5],
339 346
                                                certificate_row[6]))
......
356 363

  
357 364
        try:
358 365
            sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
359
                   f"WHERE {COL_PARENT_ID} = ? AND {COL_ID} != ?")
366
                   f"WHERE {COL_PARENT_ID} = ? AND {COL_ID} != ? AND "
367
                   f"({COL_DELETION_DATE} IS NULL OR {COL_DELETION_DATE} = '')")
360 368
            values = [certificate_id, certificate_id]
361 369
            self.cursor.execute(sql, values)
362 370
            certificate_rows = self.cursor.fetchall()
......
378 386
                                                certificate_row[2],
379 387
                                                certificate_row[3],
380 388
                                                certificate_row[4],
381
                                                certificate_row[7],
382 389
                                                certificate_row[8],
383 390
                                                certificate_row[9],
391
                                                certificate_row[10],
384 392
                                                usage_dict,
385 393
                                                certificate_row[5],
386 394
                                                certificate_row[6]))

Také k dispozici: Unified diff