From ce99bc27742f4324bc8764021d4c61574e658926 Mon Sep 17 00:00:00 2001 From: emile Date: Thu, 10 Apr 2025 16:23:18 +0300 Subject: [PATCH] new --- osinaweb/db.sqlite3 | Bin 2142208 -> 2142208 bytes osinaweb/osinacore/add/views.py | 65 ++++----- osinaweb/osinacore/edit/urls.py | 2 +- osinaweb/osinacore/edit/views.py | 30 ++++ .../add_templates/add-addressbook.html | 134 +++++++++--------- .../addressbook-details.html | 53 +++++++ .../edit_templates/edit-addressbook.html | 106 ++++++++++++++ .../templates/listing_pages/adressbooks.html | 20 ++- osinaweb/osinacore/urls.py | 2 +- osinaweb/osinacore/views.py | 15 +- 10 files changed, 303 insertions(+), 124 deletions(-) create mode 100644 osinaweb/osinacore/templates/details_templates/addressbook-details.html create mode 100644 osinaweb/osinacore/templates/edit_templates/edit-addressbook.html diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 690ac211ef892df7f10feaa8860d1f793f6d1c81..5c4f60360b4f50165ea6dac26225fad5df51f4e0 100644 GIT binary patch delta 604 zcmZ9IO=uHA6vt~Smb(7|!C(%M|$e~Glu%QSB)RTAJq`@pESxF+;UfigR z2PvpQa09-FX0Sji zcvN_7B!}gEJZTJ;NfG}WI4um^Y3A=W^H?AWh=2-Yfg(@^0f9Dd=Jh8LirH5*4lgF& zvtiE7m@}B7ROo!8W_6rS2q7e~J;V;#o)>Z7v6E3rLGgH8yVU6Q{}96pGK5=eSzW8r zvaQPIru}L{!>Yu-BleSx=fh+%DAu$?bV@WV5u$0jhbO;IKYBxhlx-un&w%Z)ZSl(% zyOj>e$SB~mZOd-8?e2!vUUhnQzwWg20x7D>$TaZ>nDp=Q((W!x`kgAmQJG*Y1*W&^OPPbt wVTMDHLx{sH2gV`HA;KZbA;#ethd74>2ZO_L4km{rhZKi74rvaV=a8NJ2GSz5X8-^I delta 273 zcmZp8(8SmP#1o_$RVKczS7{(&%{cwT zQc3a6E$Y2YOtKIT8@p@;vpwVVi+6Y>H+yRBU}p7WkaXmjZa7t3m`$!xo7s^O#FmSE44X8uRTML5r~<9m>Gy!fS47C*?^cG zh&h0mb9;s!*BrskEF1pFZ#uv%u$lS6Uwa5+!(aKf2V89rxZ57^v_0T$d%)NBfWPg5 zK-&Yswg*CO4}{wuh_pQrZF?Zr_CUPtfkfK_$+iblZ4ac|9>}ykkZpS)x9oxZ1pq2U BV~PL( diff --git a/osinaweb/osinacore/add/views.py b/osinaweb/osinacore/add/views.py index 8efa1c79..ec961b5e 100644 --- a/osinaweb/osinacore/add/views.py +++ b/osinaweb/osinacore/add/views.py @@ -1,4 +1,6 @@ from django.shortcuts import render, redirect, get_object_or_404 + +from addressbook.models import AddressBook, Country, Group, Contact from osinacore.models import * from django.contrib.auth.decorators import login_required from django.http import HttpResponse @@ -897,48 +899,33 @@ def add_ticket_update(request, ticket_id): @staff_login_required def add_addressbook(request): - customers = CustomerProfile.objects.all().order_by('-id') - business_types = BusinessType.objects.all().order_by('-id') - if request.method == 'POST': - - customer_id = request.POST.get('customer') - customer = get_object_or_404(CustomerProfile, id=customer_id) - - name = request.POST.get('name') - email = request.POST.get('email') - financial_number = request.POST.get('financial_number') - phone_number = request.POST.get('phone_number') - vat = request.POST.get('vat') - if vat: - vat = True - else: - vat = False - commercial_registration = request.POST.get('commercial_registration') - website = request.POST.get('website') - logo = request.FILES.get('logo') - - business_type_id = request.POST.get('type') - business_type = get_object_or_404(BusinessType, id=business_type_id) + countries = Country.objects.all().order_by('name') + groups = Group.objects.all() - business = Business( - customer=customer, - name=name, - email=email, - financial_number=financial_number, - vat=vat, - commercial_registration=commercial_registration, - website=website, - type=business_type, - logo=logo, - phone_number=phone_number, + if request.method == 'POST': + first_name = request.POST.get('first_name') + middle_name = request.POST.get('middle_name') + last_name = request.POST.get('last_name') + country_id = request.POST.get('country') # Optional for now + contact_types = request.POST.getlist('contact_type[]') + contact_values = request.POST.getlist('contact_value[]') + + # Create AddressBook instance + address_book = AddressBook.objects.create( + first_name=first_name, + middle_name=middle_name, + last_name=last_name, + country_id=country_id if country_id else None, ) - business.save() - return redirect('businesses') + for type_, value in zip(contact_types, contact_values): + if value: + Contact.objects.create(type=type_, contact=value, addressbook=address_book) + + return redirect('addressbook') context = { - 'customers': customers, - 'business_types': business_types, + "countries": countries, + "groups": groups, } - - return render(request, 'add_templates/add-business.html', context) + return render(request, 'add_templates/add-addressbook.html', context) diff --git a/osinaweb/osinacore/edit/urls.py b/osinaweb/osinacore/edit/urls.py index 90b5fba9..ff966fd5 100644 --- a/osinaweb/osinacore/edit/urls.py +++ b/osinaweb/osinacore/edit/urls.py @@ -23,7 +23,7 @@ urlpatterns = [ path('tag//', views.edit_tag, name='edittag'), path('ticket//status/', views.edit_ticket_status_modal, name='edit-ticket-status-modal'), - + path('addressbook//', views.edit_addressbook, name='editaddressbook'), #Mark Points path('mark_point_working_on///', views.mark_point_working_on, name='mark_point_working_on'), diff --git a/osinaweb/osinacore/edit/views.py b/osinaweb/osinacore/edit/views.py index 4b0cd6a7..13af6839 100644 --- a/osinaweb/osinacore/edit/views.py +++ b/osinaweb/osinacore/edit/views.py @@ -1,3 +1,4 @@ +from addressbook.models import AddressBook, Country, Contact, Group from osinacore.models import * from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponseRedirect @@ -662,3 +663,32 @@ def mark_point_completed_task_page(request, point_id, task_id): return redirect('detailed-task', task_id=task.task_id) +@staff_login_required +def edit_addressbook(request, addressbook_id): + address = get_object_or_404(AddressBook, id=addressbook_id) + countries = Country.objects.all() + + if request.method == 'POST': + address.first_name = request.POST.get('first_name') + address.middle_name = request.POST.get('middle_name') + address.last_name = request.POST.get('last_name') + address.country_id = request.POST.get('country') + address.save() + + # Delete old contacts + address.contact_set.all().delete() + + contact_types = request.POST.getlist('contact_type[]') + contact_values = request.POST.getlist('contact_value[]') + + for type_, value in zip(contact_types, contact_values): + if value: + Contact.objects.create(type=type_, contact=value, addressbook=address) + + return redirect('addressbook') + + return render(request, 'edit_templates/edit-addressbook.html', { + "address": address, + "countries": countries, + }) + diff --git a/osinaweb/osinacore/templates/add_templates/add-addressbook.html b/osinaweb/osinacore/templates/add_templates/add-addressbook.html index 9d9e0474..bffe8104 100644 --- a/osinaweb/osinacore/templates/add_templates/add-addressbook.html +++ b/osinaweb/osinacore/templates/add_templates/add-addressbook.html @@ -1,102 +1,68 @@ -{% extends "add-edit-main.html" %} +{% extends "main.html" %} {%load static%} {% block content %} -
+

- Add Business + Add Contact

-
+ {% csrf_token %} -
+
- -
-
- - Upload - Logo - -
-
-
- -
- - -
- - -
- - -
- -
- - First Name: +
- -
- - -
-
- - Middle Name: +
- -
- - Last Name: +
-
- - + +
- - + +
+ +
+ + + +
+ +
-
- - -
+ class="w-fit py-1 px-3 bg-osiblue rounded-md outline-none text-white border border-osiblue text-xl cursor-pointer hover:bg-white hover:text-osiblue duration-300">Save
@@ -106,5 +72,33 @@ + + {% endblock content %} \ No newline at end of file diff --git a/osinaweb/osinacore/templates/details_templates/addressbook-details.html b/osinaweb/osinacore/templates/details_templates/addressbook-details.html new file mode 100644 index 00000000..f06b1e0c --- /dev/null +++ b/osinaweb/osinacore/templates/details_templates/addressbook-details.html @@ -0,0 +1,53 @@ +{% extends "main.html" %} +{% load static %} +{% block title %}My Projects{% endblock %} +{% block content %} + +
+
+
+

First Name: {{ address.first_name }}

+
+
+

Middle Name: {{ address.middle_name }}

+
+
+

Last Name: {{ address.last_name }}

+
+
+

Country: {{ address.country.name }}

+
+ + {% if address.contact_set.all %} +
+

Contacts:

+
    + {% for contact in address.contact_set.all %} +
  • + {{ contact.type }}: {{ contact.contact }} +
  • + {% endfor %} +
+
+ {% endif %} +
+ + + + + + +
+ +{% endblock content %} diff --git a/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html b/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html new file mode 100644 index 00000000..089c91f9 --- /dev/null +++ b/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html @@ -0,0 +1,106 @@ +{% extends "main.html" %} +{% load static %} +{% block content %} + +
+
+

+ Edit Contact +

+ +
+ {% csrf_token %} +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+ {% for contact in address.contact_set.all %} +
+ + + +
+ {% endfor %} +
+ +
+ +
+ +
+ +
+
+
+
+ + + +{% endblock content %} diff --git a/osinaweb/osinacore/templates/listing_pages/adressbooks.html b/osinaweb/osinacore/templates/listing_pages/adressbooks.html index 7155de01..4399587d 100644 --- a/osinaweb/osinacore/templates/listing_pages/adressbooks.html +++ b/osinaweb/osinacore/templates/listing_pages/adressbooks.html @@ -22,7 +22,7 @@
- + @@ -61,29 +61,27 @@
-
- Business Logo -
+

{{ address.first_name }} {{ address.middle_name }} {{ address.last_name }}

+ +

{{address.country.name}}

+ + {% for c in address.contact_set.all %}

{{c.type}}: {{c.contact}}

{% endfor %} - -

{{address.type.name}}

-
- +
@@ -91,7 +89,7 @@
- +
@@ -99,7 +97,7 @@
+ data-modal-url=""> diff --git a/osinaweb/osinacore/urls.py b/osinaweb/osinacore/urls.py index 011302bf..3538d464 100644 --- a/osinaweb/osinacore/urls.py +++ b/osinaweb/osinacore/urls.py @@ -69,7 +69,7 @@ urlpatterns = [ path('show-points//', views.show_points_modal, name='showpoints'), path('timeline//', views.timeline_modal, name='timeline'), path('reaction-details-modal/', views.reaction_details_modal, name='reactiondetailsmodal'), - + path('addressbooks//', views.addressbookdetails, name='addressbookdetails'), #ADMIN CHAT path('chat-rooms//', views.chat_room, name='adminchatroom'), diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index dd423cb1..1b1ee5a2 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render, redirect, get_object_or_404 -from addressbook.models import AddressBook +from addressbook.models import AddressBook, Country from .models import * from django.contrib.auth import authenticate, login, logout from django.contrib.auth import login as auth_login @@ -859,9 +859,20 @@ def fetch_projects_by_status(request, status=None): @staff_login_required def addressbook(request): + Country.objects.get_or_create(name='Lebanon') addresses = AddressBook.objects.all() context = { 'addresses' : addresses, } - return render(request, 'listing_pages/adressbooks.html', context) \ No newline at end of file + return render(request, 'listing_pages/adressbooks.html', context) + +@staff_login_required +def addressbookdetails(request, addressbook_id): + address = get_object_or_404(AddressBook, id=addressbook_id) + + context = { + 'address' : address, + } + + return render(request, 'details_templates/addressbook-details.html', context)