Skip to content

Commit

Permalink
Allow specification of a single club
Browse files Browse the repository at this point in the history
  • Loading branch information
aviupadhyayula committed Jan 24, 2025
1 parent 47f5f35 commit b4e1827
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions backend/clubs/management/commands/merge_duplicate_committees.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"--dry-run",
"--club",
help="Run without making any changes",
)
parser.set_defaults(dry_run=False)

def handle(self, *args, **kwargs):
dry_run = kwargs["dry_run"]
club_id = kwargs["club"]

if dry_run:
self.stdout.write("Running in dry run mode, no changes will be made.")

try:
with transaction.atomic():
# Find committees that have the same name within an application
duplicate_committees = (
ApplicationCommittee.objects.values("name", "application")
.annotate(count=Count("id"))
.filter(count__gt=1)
committees_query = ApplicationCommittee.objects.values(
"name", "application"
)
if club_id:
committees_query = committees_query.filter(
application__club_id=club_id
)

duplicate_committees = committees_query.annotate(
count=Count("id")
).filter(count__gt=1)

total_merged = 0
for duplicate in duplicate_committees:
Expand Down

0 comments on commit b4e1827

Please sign in to comment.