def save_history(self, SS, label, messge, request): user = SS.get_key('USER') swho_name = "%s %s" % (user['uname'], user['ufam']) sid_contr = sid_org = 'NULL' if request.has_key('id_contr') and request['id_contr'].isdigit(): sid_contr = request['id_contr'] if request.has_key('id_org') and request['id_org'].isdigit(): sid_org = request['id_org'] query = "INSERT INTO history (who_id, who_name, label, messge, id_contr, id_org) VALUES (%d, '%s', '%s', '%s', %s, %s);" % ( user['user_id'], swho_name, cglob.ptext(label), cglob.ptext(messge), sid_contr, sid_org) return self.idb.qexecute(query)
def insert(self, SS, request): """ Добавить контакт """ pdict = dicts.CONTRCT['persons'] # print "insert_persons", request, pdict nams = [] vals = [] for k in pdict['order']: if request.has_key(k) and request[k].strip(): nams.append(k) vals.append("'%s'" % cglob.ptext(request[k])) #.strip()) print "~wform_result|" if nams: query = "INSERT INTO persons (%s) VALUES (%s);" % (', '.join(nams), ', '.join(vals)) xnams = [] xvals = [] for k in ['id_contr', 'id_org']: if request.has_key(k) and int(request[k]) > 0: xnams.append(k) xvals.append(request[k]) if xnams: query = "%s INSERT INTO person2x (%s, id_persn) VALUES (%s, (SELECT max(id_persn) FROM persons));" % ( query, ', '.join(xnams), ', '.join(xvals)) if self.idb.qexecute(query): print "Ok!", self.save_history(SS, "Добавить контакт", ', '.join(vals), request) return True else: print query else: print "INSERT: Нет Данных!"
def insert(self, SS, request): pdict = dicts.CONTRCT['varms'] if request.has_key('id_org') and request['id_org'].isdigit(): sid_org = request['id_org'] elif not (request.has_key('login') or request.has_key('passwd') or request.has_key('family') or request.has_key('pname')): print "~error|<div class='error'> ARMS INSERN", request, "</div>" else: print "~error|<div class='error'>Нет дрнных!</div>" return """ print "insert_arms", request, pdict """ nams = ['id_org'] vals = [sid_org] if request.has_key('id_bid') and request['id_bid'].isdigit(): nams.append('id_bid') vals.append(request['id_bid']) if request.has_key('id_contr') and request['id_contr'].isdigit(): nams.append('id_contr') vals.append(request['id_contr']) for k in pdict['update'].keys(): if request.has_key(k) and request[k].strip(): nams.append(k) vals.append("'%s'" % cglob.ptext(request[k])) #.strip()) print "~wform_result|" if nams: query = "INSERT INTO arms (%s) VALUES (%s);" % (', '.join(nams), ', '.join(vals)) xnams = [] xvals = [] for k in ['id_contr', 'id_org']: if request.has_key(k) and int(request[k]) > 0: xnams.append(k) xvals.append(request[k]) ''' if xnams: query = "%s INSERT INTO person2x (%s, id_persn) VALUES (%s, (SELECT max(id_persn) FROM arms));" % (query, ', '.join(xnams), ', '.join(xvals)) ''' if self.idb.qexecute(query): print "Ok!", self.save_history(SS, "Добавить АРМ", ', '.join(vals), request) return True else: print query print query else: print "INSERT: Нет Данных!"
def update(self, SS, request): """ Изменить контакт """ print "~wform_result|" if request.has_key('id_persn') and int(request['id_persn']) > 0: pdict = dicts.CONTRCT['persons'] sset = [] for k in pdict['order']: if request.has_key(k) and request[k].strip(): sset.append("%s = '%s'" % (k, cglob.ptext(request[k]))) #.strip())) if sset: query = "UPDATE persons SET %s WHERE id_persn = %s;" % ( ', '.join(sset), request['id_persn']) if self.idb.qexecute(query): print "Ok!", self.save_history( SS, "Изменить контакт id_persn: %s" % request['id_persn'], ', '.join(sset), request) return True else: print query else: print "UPDATE: Нет Данных!"