Title need undo redo
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
from psycopg.rows import dict_row
|
from psycopg.rows import dict_row
|
||||||
|
from operation import *
|
||||||
from connection import g_conn_dict as conn
|
from connection import g_conn_dict as conn
|
||||||
|
|
||||||
def set_title(name: str, value: str) -> None:
|
|
||||||
with conn[name].cursor() as cur:
|
|
||||||
cur.execute(f"update title set value = '{value}'")
|
|
||||||
|
|
||||||
def get_title(name: str) -> str:
|
def get_title(name: str) -> str:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||||
cur.execute(f"select * from title")
|
cur.execute(f"select * from title")
|
||||||
return cur.fetchone()['value']
|
return cur.fetchone()['value']
|
||||||
|
|
||||||
|
def set_title(name: str, value: str) -> None:
|
||||||
|
old = get_title(name)
|
||||||
|
|
||||||
|
with conn[name].cursor() as cur:
|
||||||
|
sql = f"update title set value = '{value}'"
|
||||||
|
cur.execute(sql)
|
||||||
|
|
||||||
|
redo = sql.replace("'", '"')
|
||||||
|
undo = f'update title set value = "{old}"'
|
||||||
|
add_operation(name, redo, undo)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from operation import execute_undo
|
||||||
from project import *
|
from project import *
|
||||||
from s1_title import *
|
from s1_title import *
|
||||||
|
|
||||||
@@ -20,5 +21,11 @@ print(get_title(p))
|
|||||||
set_title(p, "test")
|
set_title(p, "test")
|
||||||
print(get_title(p))
|
print(get_title(p))
|
||||||
|
|
||||||
|
execute_undo(p)
|
||||||
|
print(get_title(p))
|
||||||
|
|
||||||
|
execute_undo(p)
|
||||||
|
print(get_title(p))
|
||||||
|
|
||||||
close_project(p)
|
close_project(p)
|
||||||
delete_project(p)
|
delete_project(p)
|
||||||
|
|||||||
Reference in New Issue
Block a user