Lead Management Usability Upgrade
Dieser Commit ist enthalten in:
@@ -27,82 +27,21 @@ def get_lead_service():
|
||||
def lead_management():
|
||||
"""Lead Management Dashboard"""
|
||||
try:
|
||||
# Get current user
|
||||
current_user = flask_session.get('username', 'System')
|
||||
other_user = 'w@rh@mm3r' if current_user == 'rac00n' else 'rac00n'
|
||||
# Get institutions with contact counts
|
||||
institutions = get_lead_service().list_institutions()
|
||||
|
||||
# Initialize defaults
|
||||
total_institutions = 0
|
||||
total_contacts = 0
|
||||
my_entries = 0
|
||||
other_entries = 0
|
||||
activities = []
|
||||
# Get all contacts with institution names
|
||||
all_contacts = get_lead_service().list_all_contacts()
|
||||
|
||||
with get_db_connection() as conn:
|
||||
cur = conn.cursor()
|
||||
|
||||
# Get statistics
|
||||
cur.execute("SELECT COUNT(*) FROM lead_institutions")
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
total_institutions = result[0]
|
||||
|
||||
cur.execute("SELECT COUNT(*) FROM lead_contacts")
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
total_contacts = result[0]
|
||||
|
||||
# Count entries by current user
|
||||
cur.execute("""
|
||||
SELECT COUNT(*) FROM audit_log
|
||||
WHERE username = %s
|
||||
AND entity_type IN ('lead_institution', 'lead_contact')
|
||||
AND action = 'CREATE'
|
||||
""", (current_user,))
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
my_entries = result[0]
|
||||
|
||||
# Count entries by other user
|
||||
cur.execute("""
|
||||
SELECT COUNT(*) FROM audit_log
|
||||
WHERE username = %s
|
||||
AND entity_type IN ('lead_institution', 'lead_contact')
|
||||
AND action = 'CREATE'
|
||||
""", (other_user,))
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
other_entries = result[0]
|
||||
|
||||
# Get recent activities
|
||||
cur.execute("""
|
||||
SELECT timestamp, username, action, entity_type, additional_info
|
||||
FROM audit_log
|
||||
WHERE entity_type IN ('lead_institution', 'lead_contact')
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 10
|
||||
""")
|
||||
rows = cur.fetchall()
|
||||
if rows:
|
||||
for row in rows:
|
||||
activities.append({
|
||||
'timestamp': row[0],
|
||||
'username': row[1],
|
||||
'action': row[2],
|
||||
'entity_type': row[3].replace('lead_', ''),
|
||||
'additional_info': row[4]
|
||||
})
|
||||
|
||||
cur.close()
|
||||
# Calculate totals
|
||||
total_institutions = len(institutions)
|
||||
total_contacts = len(all_contacts)
|
||||
|
||||
return render_template('leads/lead_management.html',
|
||||
total_institutions=total_institutions,
|
||||
total_contacts=total_contacts,
|
||||
my_entries=my_entries,
|
||||
other_entries=other_entries,
|
||||
other_user=other_user,
|
||||
current_user=current_user,
|
||||
recent_activities=activities)
|
||||
institutions=institutions,
|
||||
all_contacts=all_contacts)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"Error in lead_management: {str(e)}")
|
||||
@@ -112,11 +51,8 @@ def lead_management():
|
||||
return render_template('leads/lead_management.html',
|
||||
total_institutions=0,
|
||||
total_contacts=0,
|
||||
my_entries=0,
|
||||
other_entries=0,
|
||||
other_user='',
|
||||
current_user=current_user,
|
||||
recent_activities=[])
|
||||
institutions=[],
|
||||
all_contacts=[])
|
||||
|
||||
@leads_bp.route('/')
|
||||
@login_required
|
||||
@@ -147,12 +83,50 @@ def add_institution():
|
||||
|
||||
return redirect(url_for('leads.lead_management'))
|
||||
|
||||
@leads_bp.route('/contact/add', methods=['POST'])
|
||||
@login_required
|
||||
def add_contact():
|
||||
"""Add new contact from form"""
|
||||
try:
|
||||
data = {
|
||||
'institution_id': request.form.get('institution_id'),
|
||||
'first_name': request.form.get('first_name'),
|
||||
'last_name': request.form.get('last_name'),
|
||||
'position': request.form.get('position')
|
||||
}
|
||||
|
||||
# Validate required fields
|
||||
if not data['institution_id'] or not data['first_name'] or not data['last_name']:
|
||||
flash('Institution, Vorname und Nachname sind erforderlich', 'error')
|
||||
return redirect(url_for('leads.lead_management'))
|
||||
|
||||
# Create contact
|
||||
contact = get_lead_service().create_contact(data, flask_session.get('username', 'System'))
|
||||
|
||||
# Add email if provided
|
||||
email = request.form.get('email')
|
||||
if email:
|
||||
get_lead_service().add_email(contact['id'], email, 'Primär', flask_session.get('username', 'System'))
|
||||
|
||||
# Add phone if provided
|
||||
phone = request.form.get('phone')
|
||||
if phone:
|
||||
get_lead_service().add_phone(contact['id'], phone, 'Primär', flask_session.get('username', 'System'))
|
||||
|
||||
flash(f'Kontakt "{data["first_name"]} {data["last_name"]}" wurde erfolgreich hinzugefügt', 'success')
|
||||
except Exception as e:
|
||||
flash(f'Fehler beim Hinzufügen des Kontakts: {str(e)}', 'error')
|
||||
|
||||
return redirect(url_for('leads.lead_management'))
|
||||
|
||||
@leads_bp.route('/institution/<uuid:institution_id>')
|
||||
@login_required
|
||||
def institution_detail(institution_id):
|
||||
"""Show institution with all contacts"""
|
||||
try:
|
||||
institution = lead_repository.get_institution_by_id(institution_id)
|
||||
# Get institution through repository
|
||||
service = get_lead_service()
|
||||
institution = service.repo.get_institution_by_id(institution_id)
|
||||
if not institution:
|
||||
flash('Institution nicht gefunden', 'error')
|
||||
return redirect(url_for('leads.institutions'))
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren