-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdl_feedback.py
117 lines (108 loc) · 4.96 KB
/
mdl_feedback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from sqlalchemy import create_engine
import psycopg2
from psycopg2.extras import RealDictCursor
### Postgresql Connection ###
global_host = "localhost"
global_user = "allykadmin"
global_password = "systems"
global_db = "live"
global_port = 5432
db_string = "postgresql+psycopg2://" + global_user + ":" + global_password + "@" + global_host + "/" + global_db + ""
#############################
class ModelFeedback:
# Feedback Note GET && CRUD operations -- Begin --
def getfeedbacknote(eventlist_id):
print('inside getfeedbacknote')
getfeedbacknote_query = "select * from tbl_feedback where COALESCE(feedback_removed, FALSE) = FALSE and eventlistid = %s"
try:
connection = psycopg2.connect(host=global_host, user=global_user, password=global_password,
dbname=global_db, port=global_port)
cursor = connection.cursor('cursor_unique_name', cursor_factory=psycopg2.extras.RealDictCursor)
cursor.execute(getfeedbacknote_query, [eventlist_id])
getfeedbacknote_data = list(cursor)
print('getfeedbacknote success')
except Exception as e:
getfeedbacknote_data = "[{errormessage: 'error'}]"
print(str(e))
raise
connection.close()
return getfeedbacknote_data
def getfeedbackgrid(eventlistid_collection):
print('inside getfeedbackgrid')
getfeedbackgrid_query = "select eventlistid, '' as eventdescription, feedbacknote from tbl_feedback where eventlistid IN %(eventlistid)s AND COALESCE(feedback_removed, FALSE) = FALSE;"
try:
connection = psycopg2.connect(host=global_host, user=global_user, password=global_password,
dbname=global_db, port=global_port)
cursor = connection.cursor('cursor_unique_name', cursor_factory=psycopg2.extras.RealDictCursor)
# Note: This is a variation of "loadeventlistgallery" method in mdl_eventlist.py
cursor.execute(getfeedbackgrid_query,
{
'eventlistid': tuple(eventlistid_collection), # Converts the list to a tuple.
})
getfeedbacknote_data = list(cursor)
print('getfeedbackgrid success')
except Exception as e:
getfeedbacknote_data = "[{errormessage: 'error'}]"
print(str(e))
raise
connection.close()
return getfeedbacknote_data
def insertfeedbacknote(eventlistid, feedbacknote):
print('inside insertfeedbacknote')
engine = create_engine(db_string)
connection = engine.connect()
transaction = connection.begin()
try:
connection.execute("INSERT INTO tbl_feedback(eventlistid, feedbacknote) VALUES (%s, %s);", eventlistid,
feedbacknote)
transaction.commit()
print('insert success')
except Exception as e:
transaction.rollback()
print(str(e))
raise
connection.close()
engine.dispose()
def updatefeedbacknote(eventlistid, feedbacknote):
print('inside updatefeedbacknote')
# Create Dictionary for holding update columns.
Dictionary_Updatelist = {}
# Add dictionary items based on update fields. -- BEGIN --
if (feedbacknote and str(feedbacknote).strip() != ""):
Dictionary_Updatelist['feedbacknote'] = feedbacknote
# Add dictionary items based on update fields. -- END --
# Create Update Query and Parameters for execution.
Query_Update_String = "UPDATE tbl_feedback SET %s WHERE eventlistid = %s" % (
', '.join("%s = %%s" % u for u in Dictionary_Updatelist.keys()), eventlistid)
Parameters = (tuple(Dictionary_Updatelist.values()),)
# print (Query_Update_String, Parameters)
# Create engine, connection, begin transaction and after execution dispose.
engine = create_engine(db_string)
connection = engine.connect()
transaction = connection.begin()
try:
connection.execute(Query_Update_String, Parameters)
transaction.commit()
print('update success')
except Exception as e:
transaction.rollback()
print(str(e))
raise
connection.close()
engine.dispose()
def removefeedbacknote(eventlistid):
print('inside removefeedbacknote')
engine = create_engine(db_string)
connection = engine.connect()
transaction = connection.begin()
try:
connection.execute("UPDATE tbl_feedback SET feedback_removed = TRUE WHERE eventlistid = %s", eventlistid)
transaction.commit()
print('removed success')
except Exception as e:
transaction.rollback()
print(str(e))
raise
connection.close()
engine.dispose()
# Feedback Note CRUD operations -- End --