From 09dcc74588cbae51c83aa6b2b9c234bef103367e Mon Sep 17 00:00:00 2001 From: soheilnazari2001 Date: Fri, 2 Feb 2024 14:30:34 +0330 Subject: [PATCH 1/5] Add a command to create Member and Participants and Teams from CSV data --- .../commands/create_participants.py | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/accounts/management/commands/create_participants.py b/accounts/management/commands/create_participants.py index 1b27d2c..369c5c8 100644 --- a/accounts/management/commands/create_participants.py +++ b/accounts/management/commands/create_participants.py @@ -10,45 +10,51 @@ class Command(BaseCommand): - help = 'Create participants from csv' + help = 'Create participants, members, and teams from csv' - def __init__(self, *args, **kwargs): + def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False): + super().__init__(stdout, stderr, no_color, force_color) + self.base_dir = None + self.participants_file = None + + def init(self, *args, **kwargs): self.base_dir = os.path.join(settings.BASE_DIR, 'accounts/initial_data') self.participants_file = os.path.join(self.base_dir, 'participants.csv') - super(Command, self).__init__(*args, **kwargs) + super().init(*args, **kwargs) def add_arguments(self, parser): pass - @transaction.atomic def handle(self, *args, **options): with open(self.participants_file, newline='') as csvfile: - start_count = Participant.objects.count() - self.stdout.write('Participant currently has %s records' % start_count) reader = csv.reader(csvfile, delimiter=',', quotechar='|') - for i, row in enumerate(reader): - if not i: - self.stdout.write('Headers: ' + ', '.join(row)) - else: - member = Member.objects.create( - username=row[1], - email=row[1]+"@gmail.com", - first_name=row[0] - ) - member.set_password(row[2]) - team, create = Team.objects.get_or_create(group_name=row[3]) - if create: - team.chat_room_link = row[4] + start_count = Participant.objects.count() + self.stdout.write(f'Participant currently has {start_count} records') + headers = next(reader) + self.stdout.write('Headers: ' + ', '.join(headers)) + for row in reader: + member, _ = Member.objects.get_or_create( + username=row[1], + email=row[1] + "@gmail.com", + first_name=row[0] + ) + member.set_password(row[2]) + member.save() + + team, created = Team.objects.get_or_create(group_name=row[3]) + if created: + team.chat_room_link = row[4] team.active = True team.save() - participant = Participant.objects.create( - member=member, - document_status='Verified', - is_activated=True, - team=team, - ) - member.save() - participant.save() - self.stdout.write('Created %s new Participants' % (Participant.objects.count() - start_count)) - self.stdout.write('Participant currently has %s records' % Participant.objects.count()) + + Participant.objects.get_or_create( + member=member, + document_status='Verified', + is_activated=True, + team=team, + ) + + new_count = Participant.objects.count() - start_count + self.stdout.write(f'Created {new_count} new Participants') + self.stdout.write(f'Participant currently has {Participant.objects.count()} records') From dbc4319f2d8d9d3984a7d3af06e182ad7ba32ed4 Mon Sep 17 00:00:00 2001 From: soheilnazari2001 Date: Fri, 2 Feb 2024 14:47:12 +0330 Subject: [PATCH 2/5] enhancing admin panel --- kabaramadalapeste/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kabaramadalapeste/admin.py b/kabaramadalapeste/admin.py index 83922ac..90db80b 100644 --- a/kabaramadalapeste/admin.py +++ b/kabaramadalapeste/admin.py @@ -93,7 +93,8 @@ class Media: 'scripts/admin-confirm.js', ) list_display = ('get_username', 'submitted_at', 'get_challenge_name', 'get_question_title',) - search_fields = ('submit_status', ) + search_fields = ('pis__participant__member__username', 'pis__judgeable_question__title',) + list_filter = ('submit_status', 'pis__judgeable_question__challenge',) ordering = ('submitted_at',) exclude = ('judged_at', 'pis', 'judged_by') readonly_fields = ( @@ -181,7 +182,7 @@ class TradeOfferRequestedItemInline(admin.StackedInline): @admin.register(TradeOffer) class TradeOfferAdmin(admin.ModelAdmin): list_display = ('creator_participant', 'status', 'creation_datetime', 'close_datetime', 'accepted_participant') - list_filter = ('status', ) + list_filter = ('status',) search_fields = ('creator_participant__member__username', 'accepted_participant__member__username') inlines = [TradeOfferRequestedItemInline, TradeOfferSuggestedItemInline] From b58b1e741a9682b63c44db47c14ef69a707033d5 Mon Sep 17 00:00:00 2001 From: soheilnazari2001 Date: Fri, 2 Feb 2024 14:49:41 +0330 Subject: [PATCH 3/5] enhancing admin panel --- .../commands/create_participants.py | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/accounts/management/commands/create_participants.py b/accounts/management/commands/create_participants.py index 369c5c8..20138b3 100644 --- a/accounts/management/commands/create_participants.py +++ b/accounts/management/commands/create_participants.py @@ -10,51 +10,45 @@ class Command(BaseCommand): - help = 'Create participants, members, and teams from csv' + help = 'Create participants from csv' - def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False): - super().__init__(stdout, stderr, no_color, force_color) - self.base_dir = None - self.participants_file = None - - def init(self, *args, **kwargs): + def __init__(self, *args, **kwargs): self.base_dir = os.path.join(settings.BASE_DIR, 'accounts/initial_data') self.participants_file = os.path.join(self.base_dir, 'participants.csv') - super().init(*args, **kwargs) + super(Command, self).__init__(*args, **kwargs) def add_arguments(self, parser): pass + @transaction.atomic def handle(self, *args, **options): with open(self.participants_file, newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') start_count = Participant.objects.count() - self.stdout.write(f'Participant currently has {start_count} records') - headers = next(reader) - self.stdout.write('Headers: ' + ', '.join(headers)) - for row in reader: - member, _ = Member.objects.get_or_create( - username=row[1], - email=row[1] + "@gmail.com", - first_name=row[0] - ) - member.set_password(row[2]) - member.save() - - team, created = Team.objects.get_or_create(group_name=row[3]) - if created: - team.chat_room_link = row[4] + self.stdout.write('Participant currently has %s records' % start_count) + reader = csv.reader(csvfile, delimiter=',', quotechar='|') + for i, row in enumerate(reader): + if not i: + self.stdout.write('Headers: ' + ', '.join(row)) + else: + member = Member.objects.create( + username=row[1], + email=row[1]+"@gmail.com", + first_name=row[0] + ) + member.set_password(row[2]) + team, create = Team.objects.get_or_create(group_name=row[3]) + if create: + team.chat_room_link = row[4] team.active = True team.save() - - Participant.objects.get_or_create( - member=member, - document_status='Verified', - is_activated=True, - team=team, - ) - - new_count = Participant.objects.count() - start_count - self.stdout.write(f'Created {new_count} new Participants') - self.stdout.write(f'Participant currently has {Participant.objects.count()} records') + participant = Participant.objects.create( + member=member, + document_status='Verified', + is_activated=True, + team=team, + ) + member.save() + participant.save() + self.stdout.write('Created %s new Participants' % (Participant.objects.count() - start_count)) + self.stdout.write('Participant currently has %s records' % Participant.objects.count()) \ No newline at end of file From f26be1c97a29a5f2866e3248abf357ff33f084cd Mon Sep 17 00:00:00 2001 From: soheilnazari2001 Date: Fri, 2 Feb 2024 14:50:32 +0330 Subject: [PATCH 4/5] Revert "enhancing admin panel" This reverts commit b58b1e741a9682b63c44db47c14ef69a707033d5. --- .../commands/create_participants.py | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/accounts/management/commands/create_participants.py b/accounts/management/commands/create_participants.py index 20138b3..369c5c8 100644 --- a/accounts/management/commands/create_participants.py +++ b/accounts/management/commands/create_participants.py @@ -10,45 +10,51 @@ class Command(BaseCommand): - help = 'Create participants from csv' + help = 'Create participants, members, and teams from csv' - def __init__(self, *args, **kwargs): + def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False): + super().__init__(stdout, stderr, no_color, force_color) + self.base_dir = None + self.participants_file = None + + def init(self, *args, **kwargs): self.base_dir = os.path.join(settings.BASE_DIR, 'accounts/initial_data') self.participants_file = os.path.join(self.base_dir, 'participants.csv') - super(Command, self).__init__(*args, **kwargs) + super().init(*args, **kwargs) def add_arguments(self, parser): pass - @transaction.atomic def handle(self, *args, **options): with open(self.participants_file, newline='') as csvfile: - start_count = Participant.objects.count() - self.stdout.write('Participant currently has %s records' % start_count) reader = csv.reader(csvfile, delimiter=',', quotechar='|') - for i, row in enumerate(reader): - if not i: - self.stdout.write('Headers: ' + ', '.join(row)) - else: - member = Member.objects.create( - username=row[1], - email=row[1]+"@gmail.com", - first_name=row[0] - ) - member.set_password(row[2]) - team, create = Team.objects.get_or_create(group_name=row[3]) - if create: - team.chat_room_link = row[4] + start_count = Participant.objects.count() + self.stdout.write(f'Participant currently has {start_count} records') + headers = next(reader) + self.stdout.write('Headers: ' + ', '.join(headers)) + for row in reader: + member, _ = Member.objects.get_or_create( + username=row[1], + email=row[1] + "@gmail.com", + first_name=row[0] + ) + member.set_password(row[2]) + member.save() + + team, created = Team.objects.get_or_create(group_name=row[3]) + if created: + team.chat_room_link = row[4] team.active = True team.save() - participant = Participant.objects.create( - member=member, - document_status='Verified', - is_activated=True, - team=team, - ) - member.save() - participant.save() - self.stdout.write('Created %s new Participants' % (Participant.objects.count() - start_count)) - self.stdout.write('Participant currently has %s records' % Participant.objects.count()) \ No newline at end of file + + Participant.objects.get_or_create( + member=member, + document_status='Verified', + is_activated=True, + team=team, + ) + + new_count = Participant.objects.count() - start_count + self.stdout.write(f'Created {new_count} new Participants') + self.stdout.write(f'Participant currently has {Participant.objects.count()} records') From a8930871017d62f05308838f5323522c11e4b7c7 Mon Sep 17 00:00:00 2001 From: soheilnazari2001 Date: Fri, 2 Feb 2024 14:51:20 +0330 Subject: [PATCH 5/5] enhancing admin panel --- .../commands/create_participants.py | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/accounts/management/commands/create_participants.py b/accounts/management/commands/create_participants.py index 369c5c8..20138b3 100644 --- a/accounts/management/commands/create_participants.py +++ b/accounts/management/commands/create_participants.py @@ -10,51 +10,45 @@ class Command(BaseCommand): - help = 'Create participants, members, and teams from csv' + help = 'Create participants from csv' - def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False): - super().__init__(stdout, stderr, no_color, force_color) - self.base_dir = None - self.participants_file = None - - def init(self, *args, **kwargs): + def __init__(self, *args, **kwargs): self.base_dir = os.path.join(settings.BASE_DIR, 'accounts/initial_data') self.participants_file = os.path.join(self.base_dir, 'participants.csv') - super().init(*args, **kwargs) + super(Command, self).__init__(*args, **kwargs) def add_arguments(self, parser): pass + @transaction.atomic def handle(self, *args, **options): with open(self.participants_file, newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') start_count = Participant.objects.count() - self.stdout.write(f'Participant currently has {start_count} records') - headers = next(reader) - self.stdout.write('Headers: ' + ', '.join(headers)) - for row in reader: - member, _ = Member.objects.get_or_create( - username=row[1], - email=row[1] + "@gmail.com", - first_name=row[0] - ) - member.set_password(row[2]) - member.save() - - team, created = Team.objects.get_or_create(group_name=row[3]) - if created: - team.chat_room_link = row[4] + self.stdout.write('Participant currently has %s records' % start_count) + reader = csv.reader(csvfile, delimiter=',', quotechar='|') + for i, row in enumerate(reader): + if not i: + self.stdout.write('Headers: ' + ', '.join(row)) + else: + member = Member.objects.create( + username=row[1], + email=row[1]+"@gmail.com", + first_name=row[0] + ) + member.set_password(row[2]) + team, create = Team.objects.get_or_create(group_name=row[3]) + if create: + team.chat_room_link = row[4] team.active = True team.save() - - Participant.objects.get_or_create( - member=member, - document_status='Verified', - is_activated=True, - team=team, - ) - - new_count = Participant.objects.count() - start_count - self.stdout.write(f'Created {new_count} new Participants') - self.stdout.write(f'Participant currently has {Participant.objects.count()} records') + participant = Participant.objects.create( + member=member, + document_status='Verified', + is_activated=True, + team=team, + ) + member.save() + participant.save() + self.stdout.write('Created %s new Participants' % (Participant.objects.count() - start_count)) + self.stdout.write('Participant currently has %s records' % Participant.objects.count()) \ No newline at end of file