DmitrMakeev commited on
Commit
6b0524e
1 Parent(s): f219257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1490,14 +1490,15 @@ def add_or_update_contact(contact_data):
1490
  if field not in contact_data:
1491
  contact_data[field] = ''
1492
 
1493
- placeholders = ", ".join([f"{field} = ?" for field in fields])
1494
-
1495
  cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
1496
  contact = cursor.fetchone()
1497
 
1498
  if contact:
1499
- update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
1500
- cursor.execute(update_query, (*[contact_data[field] for field in fields], contact[0]))
 
 
 
1501
  else:
1502
  insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
1503
  cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
@@ -1505,8 +1506,6 @@ def add_or_update_contact(contact_data):
1505
  conn.commit()
1506
  conn.close()
1507
 
1508
-
1509
-
1510
  @app.route('/add_data_ver_cur', methods=['GET'])
1511
  def add_data_ver_cur():
1512
  global current_curator_index
@@ -1539,8 +1538,6 @@ def add_data_ver_cur():
1539
  if curator_on_off == "1":
1540
  current_curator_index = (current_curator_index + 1) % len(curators)
1541
 
1542
-
1543
-
1544
  return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
1545
  except Exception as e:
1546
  logging.error(f"Error adding user: {e}")
 
1490
  if field not in contact_data:
1491
  contact_data[field] = ''
1492
 
 
 
1493
  cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
1494
  contact = cursor.fetchone()
1495
 
1496
  if contact:
1497
+ update_fields = [f"{field} = ?" for field in fields if contact_data[field] != '']
1498
+ update_values = [contact_data[field] for field in fields if contact_data[field] != '']
1499
+ update_values.append(contact[0])
1500
+ update_query = f"UPDATE contacts SET {', '.join(update_fields)} WHERE id = ?"
1501
+ cursor.execute(update_query, update_values)
1502
  else:
1503
  insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
1504
  cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
 
1506
  conn.commit()
1507
  conn.close()
1508
 
 
 
1509
  @app.route('/add_data_ver_cur', methods=['GET'])
1510
  def add_data_ver_cur():
1511
  global current_curator_index
 
1538
  if curator_on_off == "1":
1539
  current_curator_index = (current_curator_index + 1) % len(curators)
1540
 
 
 
1541
  return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
1542
  except Exception as e:
1543
  logging.error(f"Error adding user: {e}")