Skip to content

Commit

Permalink
feat: fix issue removing project contributors by name and email
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-hd committed Nov 14, 2024
1 parent ad3a0ad commit 528753f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,8 @@ def edit_project(request, pk, project_uuid):
instance.project = data
instance.save()

delete_contributors_by_name_and_email(post_query_dict=request.POST)

save_new_contributors_by_name_and_email(
post_query_dict=request.POST,
project=data
Expand Down
27 changes: 27 additions & 0 deletions projects/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from django.http import QueryDict

from researchers.models import Researcher
Expand Down Expand Up @@ -225,3 +226,29 @@ def save_new_contributors_by_name_and_email(post_query_dict: QueryDict, project:
project=project
).save()
i += 1


def delete_contributors_by_name_and_email(post_query_dict: QueryDict):
"""
Removes all additional_contributors by name and email which
are marked for deletion
Args:
post_query_dict: request POST query dict
"""
try:
for key in post_query_dict:
match = re.search("additional_contributors-[0-9]-DELETE$", key)
if not match:
continue

index = re.search("[0-9]+", key)[0]
name = post_query_dict.get(f'additional_contributors-{index}-name')
email = post_query_dict.get(f'additional_contributors-{index}-email')
if name is None or email is None:
return

ProjectPerson.objects.filter(name=name, email=email).delete()

except (KeyError, Exception):
print('Error Deleting Contributors By Name and Email')

0 comments on commit 528753f

Please sign in to comment.