file_path = 'core/templates/core/settings.html' with open(file_path, 'r') as f: content = f.read() # 1. Add Nav Tab if 'id="devices-tab"' not in content: whatsapp_tab_end = 'id="whatsapp-tab" data-bs-toggle="pill" data-bs-target="#whatsapp" type="button" role="tab">\n {% trans "WhatsApp Gateway" %}\n \n li>' insert_str = """ " if whatsapp_tab_end in content: content = content.replace(whatsapp_tab_end, whatsapp_tab_end + insert_str) print("Added Devices Tab Nav.") else: # Fallback search if exact string match fails due to whitespace print("Could not find exact match for Nav Tab insertion. Trying simpler match.") simple_search = '{% trans "WhatsApp Gateway" %}' parts = content.split(simple_search) if len(parts) > 1: # Reconstruct slightly differently but risky pass # 2. Add Tab Content if 'id="devices" role="tabpanel"' not in content: devices_pane = """
{% trans "Connected Devices" %}
{% for device in devices %} {% empty %} {% endfor %}
{% trans "Device Name" %} {% trans "Type" %} {% trans "Connection" %} {% trans "IP / Port" %} {% trans "Status" %} {% trans "Actions" %}
{{ device.name }} {{ device.get_device_type_display }} {{ device.get_connection_type_display }} {% if device.ip_address %} {{ device.ip_address }}{% if device.port %}:{{ device.port }}{% endif %} {% else %} - {% endif %} {% if device.is_active %} {% trans "Active" %} {% else %} {% trans "Inactive" %} {% endif %}
{% trans "No devices configured." %}
" parts = content.split('') if len(parts) > 1: last_div = parts[0].rfind('') second_last_div = parts[0].rfind('', 0, last_div) if second_last_div != -1: new_part0 = parts[0][:second_last_div] + devices_pane + parts[0][second_last_div:] content = new_part0 + '' + parts[1] print("Added Devices Tab Pane.") else: print("Could not find insertion point for Devices Pane.") # 3. Add Add Device Modal if 'id="addDeviceModal"' not in content: modal_content = """ " content = content.replace('{% endblock %}', modal_content + '\n{% endblock %}') print("Added Add Device Modal.") with open(file_path, 'w') as f: f.write(content)