diff --git a/osinaweb/addressbook/__pycache__/models.cpython-313.pyc b/osinaweb/addressbook/__pycache__/models.cpython-313.pyc index 09b88c35..6a4ee100 100644 Binary files a/osinaweb/addressbook/__pycache__/models.cpython-313.pyc and b/osinaweb/addressbook/__pycache__/models.cpython-313.pyc differ diff --git a/osinaweb/addressbook/migrations/0007_prospectinglistitem_comments.py b/osinaweb/addressbook/migrations/0007_prospectinglistitem_comments.py new file mode 100644 index 00000000..244a8530 --- /dev/null +++ b/osinaweb/addressbook/migrations/0007_prospectinglistitem_comments.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2 on 2025-04-14 12:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('addressbook', '0006_comment_prospectinglist_prospectinglistitem'), + ] + + operations = [ + migrations.AddField( + model_name='prospectinglistitem', + name='comments', + field=models.ManyToManyField(blank=True, to='addressbook.comment'), + ), + ] diff --git a/osinaweb/addressbook/migrations/__pycache__/0007_prospectinglistitem_comments.cpython-313.pyc b/osinaweb/addressbook/migrations/__pycache__/0007_prospectinglistitem_comments.cpython-313.pyc new file mode 100644 index 00000000..2e6aa757 Binary files /dev/null and b/osinaweb/addressbook/migrations/__pycache__/0007_prospectinglistitem_comments.cpython-313.pyc differ diff --git a/osinaweb/addressbook/models.py b/osinaweb/addressbook/models.py index 36ce2db1..07ca58e4 100644 --- a/osinaweb/addressbook/models.py +++ b/osinaweb/addressbook/models.py @@ -29,11 +29,18 @@ class AddressBook(models.Model): group = models.ManyToManyField(Group, blank=True) +class Comment(models.Model): + content = models.TextField() + date_added = models.DateTimeField(auto_now_add=True) + added_by = models.ForeignKey(User, on_delete=models.CASCADE) + + class ProspectingListItem(models.Model): prospecting_list = models.ForeignKey(ProspectingList, on_delete=models.CASCADE) addressbook = models.ForeignKey(AddressBook, on_delete=models.CASCADE) date_added = models.DateTimeField(auto_now_add=True) attention = models.BooleanField(default=False) + comments = models.ManyToManyField(Comment, blank=True) class Contact(models.Model): @@ -61,9 +68,3 @@ class SocialMedia(models.Model): username = models.CharField(max_length=50, blank=True) link = models.URLField(blank=True) addressbook = models.ForeignKey(AddressBook, on_delete=models.CASCADE, null=True) - - -class Comment(models.Model): - content = models.TextField() - date_added = models.DateTimeField(auto_now_add=True) - added_by = models.ForeignKey(User, on_delete=models.CASCADE) diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 5e66e607..d41890e5 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/edit/__pycache__/views.cpython-313.pyc b/osinaweb/osinacore/edit/__pycache__/views.cpython-313.pyc index 5e1b8420..fea503de 100644 Binary files a/osinaweb/osinacore/edit/__pycache__/views.cpython-313.pyc and b/osinaweb/osinacore/edit/__pycache__/views.cpython-313.pyc differ diff --git a/osinaweb/osinacore/edit/views.py b/osinaweb/osinacore/edit/views.py index 21993dd8..d501cd7e 100644 --- a/osinaweb/osinacore/edit/views.py +++ b/osinaweb/osinacore/edit/views.py @@ -1,4 +1,4 @@ -from addressbook.models import AddressBook, Country, Contact, Group, ProspectingList, ProspectingListItem +from addressbook.models import AddressBook, Country, Contact, Group, ProspectingList, ProspectingListItem, Comment from osinacore.models import * from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponseRedirect @@ -696,7 +696,6 @@ def edit_addressbook(request, addressbook_id): "countries": countries, "groups": groups, }) - @staff_login_required def edit_prospecting_list(request, list_id): prospecting_list = get_object_or_404(ProspectingList, id=list_id) @@ -704,26 +703,27 @@ def edit_prospecting_list(request, list_id): list_items = prospecting_list.prospectinglistitem_set.all() if request.method == 'POST': + # Update basic list fields prospecting_list.name = request.POST.get('name') prospecting_list.description = request.POST.get('description') prospecting_list.save() - # --- Update existing items --- + + # --- Update existing items (update "attention" checkbox) --- existing_ids = request.POST.getlist('list_item_id[]') - for id in existing_ids: + for item_id in existing_ids: try: - item = ProspectingListItem.objects.get(id=id, prospecting_list=prospecting_list) - # Checkbox will only be present in POST if checked. - item.attention = True if request.POST.get(f'attention_existing_{id}') == 'on' else False + item = ProspectingListItem.objects.get(id=item_id, prospecting_list=prospecting_list) + # Checkbox is only present if checked. + item.attention = True if request.POST.get(f'attention_existing_{item_id}') == 'on' else False item.save() except ProspectingListItem.DoesNotExist: pass # --- Add new inline item if provided --- - new_addressbook = request.POST.get('new_addressbook') - # Only process if user selected a value (it may be empty if no new item is desired) + new_addressbook = request.POST.get('new_addressbook') # can be an existing contact id or the string "new" if new_addressbook: if new_addressbook == 'new': - # Create new AddressBook entry from inline form fields. + # Create a new AddressBook entry from inline fields. new_first_name = request.POST.get('new_first_name') new_last_name = request.POST.get('new_last_name') if new_first_name and new_last_name: @@ -732,7 +732,7 @@ def edit_prospecting_list(request, list_id): last_name=new_last_name ) else: - addressbook = None # Or handle errors as needed. + addressbook = None # Optionally, handle error here. else: try: addressbook = AddressBook.objects.get(id=new_addressbook) @@ -741,11 +741,22 @@ def edit_prospecting_list(request, list_id): if addressbook: new_attention = True if request.POST.get('new_attention') == 'on' else False - ProspectingListItem.objects.create( + new_item = ProspectingListItem.objects.create( prospecting_list=prospecting_list, addressbook=addressbook, attention=new_attention ) + # Process new comments if provided. + new_comments = request.POST.get('new_comments', '') + # Split comments on newline and create individual Comment objects. + for line in new_comments.splitlines(): + comment_text = line.strip() + if comment_text: + comment = Comment.objects.create( + content=comment_text, + added_by=request.user # assuming current user is adding the comment + ) + new_item.comments.add(comment) return redirect('editprospecting-list', list_id=prospecting_list.id) diff --git a/osinaweb/osinacore/templates/edit_templates/edit-prospecting-list.html b/osinaweb/osinacore/templates/edit_templates/edit-prospecting-list.html index 0e0ba634..b7ce391c 100644 --- a/osinaweb/osinacore/templates/edit_templates/edit-prospecting-list.html +++ b/osinaweb/osinacore/templates/edit_templates/edit-prospecting-list.html @@ -8,83 +8,97 @@ Edit Prospecting List - +
{% csrf_token %}
-
- - -
+ +
+ + +
+
+ + +
-
- - -
-
- - - - - - - - - - - {% for item in list_items %} - - - - - {% empty %} - - - - {% endfor %} + +
+ +
ContactAttention
- {{ item.addressbook.first_name }} {{ item.addressbook.last_name }} - - - - -
- No contacts yet. -
+ + + + + + + + + + {% for item in list_items %} + + + + + + {% empty %} + + + + {% endfor %} - - - - - - -
ContactAttentionComments
+ {{ item.addressbook.first_name }} {{ item.addressbook.last_name }} + + + + + {% if item.comments.all %} +
    + {% for comment in item.comments.all %} +
  • {{ comment.content }}
  • + {% endfor %} +
+ {% else %} + No comments + {% endif %} +
+ No contacts yet. +
- - - - - - -
- -
-
-
- -
+ + + + + + + + + + + + + + + + + + + +
+ +
+ +
@@ -94,7 +108,6 @@ // Toggle the new-contact fields when "Add new contact" is selected. const newSelect = document.getElementById('new-addressbook-select'); const newContactFields = document.getElementById('new-contact-fields'); - newSelect.addEventListener('change', function() { if (this.value === 'new') { newContactFields.classList.remove('hidden');