From 7345b77a8eb7e038c239e1759a7ad7b74f56775b Mon Sep 17 00:00:00 2001 From: VARUN Date: Thu, 4 Apr 2024 14:17:00 +0530 Subject: [PATCH] initial commit --- skyonnweb/skyonnadmin/urls.py | 2 + skyonnweb/skyonnadmin/views.py | 28 ++++++- .../skyonnadmin/admin_dashboard.html | 11 ++- .../skyonnadmin/existing_client.html | 74 ------------------- 4 files changed, 38 insertions(+), 77 deletions(-) diff --git a/skyonnweb/skyonnadmin/urls.py b/skyonnweb/skyonnadmin/urls.py index b1ecb97..f8d3c3f 100644 --- a/skyonnweb/skyonnadmin/urls.py +++ b/skyonnweb/skyonnadmin/urls.py @@ -21,5 +21,7 @@ urlpatterns = [ path('save-details-subcompany/', views.save_details_subcompany, name='save-details-subcompany'), path('api/get_subcompanies/', views.get_locations, name='get_subcompanies'), path('get_subcompany_details/', views.get_combined_details, name='get_subcompany_details'), + path('add_contact/', views.add_contact, name='add_contact'), + ] diff --git a/skyonnweb/skyonnadmin/views.py b/skyonnweb/skyonnadmin/views.py index 10731d1..8da3288 100644 --- a/skyonnweb/skyonnadmin/views.py +++ b/skyonnweb/skyonnadmin/views.py @@ -10,7 +10,7 @@ from django.http import JsonResponse import json from django.core.serializers.json import DjangoJSONEncoder from django.views.decorators.csrf import csrf_exempt - +from django.views.decorators.http import require_http_methods def home(request): return render(request, 'skyonnadmin/home.html') @@ -332,3 +332,29 @@ def get_contacts(request): } for contact in contacts] return JsonResponse({"contacts": contacts_data}) + +@csrf_exempt +@require_http_methods(["POST"]) +def add_contact(request): + print("hii") + # Extract information from the request + department = request.POST.get('department') + # Assume 'sub_company_id' is passed to identify which SubcompanyDetails to update + sub_company_id = request.POST.get('sub_company_id') + # Create the Contact instance (simplified, add validation and error handling) + contact = Contact( + first_name=request.POST.get('first_name'), + last_name=request.POST.get('last_name'), + # Add other fields as necessary + ) + contact.save() + + # Add the contact to the appropriate department of the SubcompanyDetails instance + sub_company = SubcompanyDetails.objects.get(id=sub_company_id) + if department == 'HR': + sub_company.hr_contacts.add(contact) + elif department == 'Accounts': + sub_company.accounts_contacts.add(contact) + # Add conditions for other departments as needed + + return JsonResponse({"success": True, "message": "Contact added successfully."}) \ No newline at end of file diff --git a/skyonnweb/templates/skyonnadmin/admin_dashboard.html b/skyonnweb/templates/skyonnadmin/admin_dashboard.html index 5ce330c..fa83e17 100644 --- a/skyonnweb/templates/skyonnadmin/admin_dashboard.html +++ b/skyonnweb/templates/skyonnadmin/admin_dashboard.html @@ -210,12 +210,12 @@ a {