From a6150cc91c199f29d42839bbc004eaeaa6779135 Mon Sep 17 00:00:00 2001 From: emile Date: Thu, 10 Apr 2025 16:40:45 +0300 Subject: [PATCH] new --- osinaweb/db.sqlite3 | Bin 2142208 -> 2142208 bytes osinaweb/osinacore/add/views.py | 4 ++++ osinaweb/osinacore/edit/views.py | 5 +++++ .../add_templates/add-addressbook.html | 10 ++++++++++ .../addressbook-details.html | 13 ++++++++++++- .../edit_templates/edit-addressbook.html | 14 +++++++++++++- .../templates/listing_pages/adressbooks.html | 11 +++++++++-- osinaweb/osinacore/views.py | 8 +++++++- 8 files changed, 60 insertions(+), 5 deletions(-) diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 5c4f60360b4f50165ea6dac26225fad5df51f4e0..3fb067762e92be7df2aa980954713eed824361e9 100644 GIT binary patch delta 665 zcmZwEO=}ZT6b9gX=iHfb#-?wo)|e(Skx)t(O{uz2R4Awv+{S&aO-Mv*ViWgC6uQ*n zA{z@`=uU(ZXg2|Wfz(|Wf&{dIB2=x4__6Sv#7)4(b3e|Ud(NGiTBo6F^f;!otMSV^ zyK&=LQm(n7CvIxhxHE33HB!6hIH&5DWKK8ByM7{RkJc~Bv|h;Nmh+X$%~I+1d||nC zzieXl^Kzk=6mcb1KNoC1KaWOQ4=3I`I{cuRSt({TStMl0CWl-)MBY|0<3H6y25p5; zc!$?$^A0a?1xD2P^?aq8nhV;c&O!zQXJ8EmPD2j{W;SPi6ZQlz6+U7I&H8#`s+Fo$ zF*zZQN~hCaHosW9n@a_K{=aPQ%==TmU{B#EzF?1+dy8?$HcD$Tj_J*oEu1~^l~RHO zg+KU#1EzjJ+=$0S4wi`L^)m*Gxkd-I?EY-AsOFJ>#r73`;T!f@tb=Cxkuk$!+tND_ zjIvpae?`*tVwUN33-KB@8Vb93gErRC;OR1A(Xg!|lltn?!mT@1zVU1!SY;MVOVV6> z^6wI!+NfK~Wl` P7{w_;C%3xW$+6B~{E*5| delta 319 zcmWm8y)VRY9LMqg9EeCMCIrSR@wy3N{`62|Xk?NgP8Lov@Qex?FZK>kZ#pxN!=Mue3^)joPyrnbFu}^gKwYwX>2fF2x7070 zoN|rcDNo(#nc{p;tz5~%F*to`^h4RABi3wu&=X1ui*X?=OQo#%TRnf2wxmR(0liR< z5)7PDoII!l4P;8t;7Q diff --git a/osinaweb/osinacore/add/views.py b/osinaweb/osinacore/add/views.py index ec961b5e..f6f0f102 100644 --- a/osinaweb/osinacore/add/views.py +++ b/osinaweb/osinacore/add/views.py @@ -909,6 +909,7 @@ def add_addressbook(request): country_id = request.POST.get('country') # Optional for now contact_types = request.POST.getlist('contact_type[]') contact_values = request.POST.getlist('contact_value[]') + selected_groups = request.POST.getlist('groups') # Create AddressBook instance address_book = AddressBook.objects.create( @@ -918,6 +919,9 @@ def add_addressbook(request): country_id=country_id if country_id else None, ) + if selected_groups: + address_book.group.set(selected_groups) + for type_, value in zip(contact_types, contact_values): if value: Contact.objects.create(type=type_, contact=value, addressbook=address_book) diff --git a/osinaweb/osinacore/edit/views.py b/osinaweb/osinacore/edit/views.py index 13af6839..51e0179b 100644 --- a/osinaweb/osinacore/edit/views.py +++ b/osinaweb/osinacore/edit/views.py @@ -667,6 +667,7 @@ def mark_point_completed_task_page(request, point_id, task_id): def edit_addressbook(request, addressbook_id): address = get_object_or_404(AddressBook, id=addressbook_id) countries = Country.objects.all() + groups = Group.objects.all() if request.method == 'POST': address.first_name = request.POST.get('first_name') @@ -674,6 +675,9 @@ def edit_addressbook(request, addressbook_id): address.last_name = request.POST.get('last_name') address.country_id = request.POST.get('country') address.save() + selected_groups = request.POST.getlist('groups') + selected_groups_ids = [int(gid) for gid in selected_groups if gid.isdigit()] + address.group.set(selected_groups_ids) # Delete old contacts address.contact_set.all().delete() @@ -690,5 +694,6 @@ def edit_addressbook(request, addressbook_id): return render(request, 'edit_templates/edit-addressbook.html', { "address": address, "countries": countries, + "groups": groups, }) diff --git a/osinaweb/osinacore/templates/add_templates/add-addressbook.html b/osinaweb/osinacore/templates/add_templates/add-addressbook.html index bffe8104..89834f08 100644 --- a/osinaweb/osinacore/templates/add_templates/add-addressbook.html +++ b/osinaweb/osinacore/templates/add_templates/add-addressbook.html @@ -36,6 +36,16 @@ {% endfor %} +
+ + +

Hold down Ctrl (Windows) or Command (Mac) to select multiple groups.

+
diff --git a/osinaweb/osinacore/templates/details_templates/addressbook-details.html b/osinaweb/osinacore/templates/details_templates/addressbook-details.html index f06b1e0c..edcca914 100644 --- a/osinaweb/osinacore/templates/details_templates/addressbook-details.html +++ b/osinaweb/osinacore/templates/details_templates/addressbook-details.html @@ -21,7 +21,18 @@

Country: {{ address.country.name }}

- + {% if address.group.all %} +
+

Groups:

+
    + {% for group in address.group.all %} +
  • + {{ group.name }} +
  • + {% endfor %} +
+
+ {% endif %} {% if address.contact_set.all %}

Contacts:

diff --git a/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html b/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html index 089c91f9..4490aaf4 100644 --- a/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html +++ b/osinaweb/osinacore/templates/edit_templates/edit-addressbook.html @@ -43,7 +43,19 @@ {% endfor %}
- +
+ + +

Hold down Ctrl (Windows) or Cmd (Mac) to select multiple groups.

+
diff --git a/osinaweb/osinacore/templates/listing_pages/adressbooks.html b/osinaweb/osinacore/templates/listing_pages/adressbooks.html index 4399587d..8691b2f8 100644 --- a/osinaweb/osinacore/templates/listing_pages/adressbooks.html +++ b/osinaweb/osinacore/templates/listing_pages/adressbooks.html @@ -48,6 +48,10 @@ class="px-6 py-3 text-sm font-medium text-gray-500 uppercase border-r border-gray-300 whitespace-nowrap"> Contact + + Groups + Actions @@ -76,8 +80,11 @@ {% endfor %} - - + + {% for g in address.group.all %} +

{{g.name}}

+ {% endfor %} +
diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index 1b1ee5a2..3a47cc8d 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, Country +from addressbook.models import AddressBook, Country, Group from .models import * from django.contrib.auth import authenticate, login, logout from django.contrib.auth import login as auth_login @@ -860,7 +860,13 @@ def fetch_projects_by_status(request, status=None): @staff_login_required def addressbook(request): Country.objects.get_or_create(name='Lebanon') + Group.objects.get_or_create(name='Test Group 1') + Group.objects.get_or_create(name='Test Group 2') + Group.objects.get_or_create(name='Test Group 3') + Group.objects.get_or_create(name='Test Group 4') + addresses = AddressBook.objects.all() + context = { 'addresses' : addresses,