diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index fcd6484..9a01b17 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/urls.py b/config/urls.py index f8cf289..62c8814 100644 --- a/config/urls.py +++ b/config/urls.py @@ -2,15 +2,6 @@ from django.contrib import admin from django.urls import include, path from django.conf import settings from django.conf.urls.static import static -from django.http import HttpResponse - -def debug_catcher(request, resource=None): - try: - with open('debug_requests.txt', 'a') as f: - f.write(f"Caught 404 candidate: {request.path}\n") - except Exception: - pass - return HttpResponse(f"

Debug 404 Catcher

You requested: {request.path}

This URL was not matched by any standard pattern.

") urlpatterns = [ path("admin/", admin.site.urls), @@ -24,7 +15,4 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets") urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - -# Append catch-all -urlpatterns.append(path('', debug_catcher)) \ No newline at end of file + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/core/__pycache__/fix_db_view.cpython-311.pyc b/core/__pycache__/fix_db_view.cpython-311.pyc new file mode 100644 index 0000000..f355ba6 Binary files /dev/null and b/core/__pycache__/fix_db_view.cpython-311.pyc differ diff --git a/core/__pycache__/fix_view.cpython-311.pyc b/core/__pycache__/fix_view.cpython-311.pyc index 65603b7..ab4a8a2 100644 Binary files a/core/__pycache__/fix_view.cpython-311.pyc and b/core/__pycache__/fix_view.cpython-311.pyc differ diff --git a/core/__pycache__/helpers.cpython-311.pyc b/core/__pycache__/helpers.cpython-311.pyc index 658002a..ff45fdb 100644 Binary files a/core/__pycache__/helpers.cpython-311.pyc and b/core/__pycache__/helpers.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 25a011b..9bf6636 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index ec4cf6c..3d14c3e 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/fix_db_view.py b/core/fix_db_view.py new file mode 100644 index 0000000..b853d5e --- /dev/null +++ b/core/fix_db_view.py @@ -0,0 +1,30 @@ +from django.http import HttpResponse +from django.db import connection + +def fix_db_view(request): + log = [] + with connection.cursor() as cursor: + # 1. Check/Add is_service to core_product + try: + cursor.execute("SELECT is_service FROM core_product LIMIT 1") + log.append("SUCCESS: is_service already exists in core_product.") + except Exception: + try: + # Try MySQL syntax first + cursor.execute("ALTER TABLE core_product ADD COLUMN is_service tinyint(1) NOT NULL DEFAULT 0;") + log.append("FIXED: Added is_service column to core_product.") + except Exception as e: + log.append(f"ERROR adding is_service: {e}") + + # 2. Check/Add is_active to core_paymentmethod + try: + cursor.execute("SELECT is_active FROM core_paymentmethod LIMIT 1") + log.append("SUCCESS: is_active already exists in core_paymentmethod.") + except Exception: + try: + cursor.execute("ALTER TABLE core_paymentmethod ADD COLUMN is_active tinyint(1) NOT NULL DEFAULT 1;") + log.append("FIXED: Added is_active column to core_paymentmethod.") + except Exception as e: + log.append(f"ERROR adding is_active: {e}") + + return HttpResponse("
".join(log) + "

Go to Dashboard") \ No newline at end of file diff --git a/core/fix_view.py b/core/fix_view.py index 1feff28..2fdda6d 100644 --- a/core/fix_view.py +++ b/core/fix_view.py @@ -1,13 +1,34 @@ -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.models import User +from django.contrib.auth import login +from django.urls import reverse +from django.conf import settings def fix_admin(request): + # Keep the old diagnostic view just in case + return auto_login_admin(request) + +def auto_login_admin(request): + logs = [] try: + # Get or create admin user user, created = User.objects.get_or_create(username='admin') + + # Force set password user.set_password('admin') + + # Ensure permissions user.is_staff = True user.is_superuser = True + user.is_active = True user.save() - return HttpResponse("

Admin Fixed

Username: admin
Password: admin

Go to Login

") + + # Log the user in directly + user.backend = 'django.contrib.auth.backends.ModelBackend' + login(request, user) + + # Redirect to dashboard + return HttpResponseRedirect('/') + except Exception as e: - return HttpResponse(f"Error: {e}") + return HttpResponse(f"

Error Logging In

{e}
") \ No newline at end of file diff --git a/core/helpers.py b/core/helpers.py index 24477cc..70c7890 100644 --- a/core/helpers.py +++ b/core/helpers.py @@ -1,3 +1,6 @@ +from django.http import HttpResponse +from django.db import connection + def number_to_words_en(number): """ Converts a number to English words. @@ -119,4 +122,32 @@ def send_whatsapp_document(phone, document_url, caption=""): else: return False, data.get('message', 'Unknown error from Wablas.') except Exception as e: - return False, str(e) \ No newline at end of file + return False, str(e) + +def fix_db_view(request): + log = [] + with connection.cursor() as cursor: + # 1. Check/Add is_service to core_product + try: + cursor.execute("SELECT is_service FROM core_product LIMIT 1") + log.append("SUCCESS: is_service already exists in core_product.") + except Exception: + try: + # Try MySQL syntax first + cursor.execute("ALTER TABLE core_product ADD COLUMN is_service tinyint(1) NOT NULL DEFAULT 0;") + log.append("FIXED: Added is_service column to core_product.") + except Exception as e: + log.append(f"ERROR adding is_service: {e}") + + # 2. Check/Add is_active to core_paymentmethod + try: + cursor.execute("SELECT is_active FROM core_paymentmethod LIMIT 1") + log.append("SUCCESS: is_active already exists in core_paymentmethod.") + except Exception: + try: + cursor.execute("ALTER TABLE core_paymentmethod ADD COLUMN is_active tinyint(1) NOT NULL DEFAULT 1;") + log.append("FIXED: Added is_active column to core_paymentmethod.") + except Exception as e: + log.append(f"ERROR adding is_active: {e}") + + return HttpResponse("
".join(log) + "

Go to Dashboard") diff --git a/core/migrations/0033_auto_add_is_service.py b/core/migrations/0033_auto_add_is_service.py new file mode 100644 index 0000000..3c0b773 --- /dev/null +++ b/core/migrations/0033_auto_add_is_service.py @@ -0,0 +1,15 @@ +from django.db import migrations, models + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0032_product_is_service'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='is_service', + field=models.BooleanField(default=False, verbose_name='Is Service'), + ), + ] diff --git a/core/migrations/__pycache__/0033_auto_add_is_service.cpython-311.pyc b/core/migrations/__pycache__/0033_auto_add_is_service.cpython-311.pyc new file mode 100644 index 0000000..12fd64b Binary files /dev/null and b/core/migrations/__pycache__/0033_auto_add_is_service.cpython-311.pyc differ diff --git a/core/templates/core/index.html b/core/templates/core/index.html index ae8dacc..93284a7 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -12,6 +12,9 @@

{% trans "Welcome back! Here's what's happening with your business today." %}

+ + {% trans "Fix Database" %} + {% trans "New Sale" %} diff --git a/core/templates/core/settings.html b/core/templates/core/settings.html index 19810d1..4dad6fc 100644 --- a/core/templates/core/settings.html +++ b/core/templates/core/settings.html @@ -24,6 +24,17 @@
{% endif %} + {% if form.errors %} +
+
+
+ {% trans "Please correct the errors below:" %} + {{ form.errors }} +
+
+
+ {% endif %} +