Skip to content

Commit

Permalink
Merge pull request #25 from AUTGamecraft/excel
Browse files Browse the repository at this point in the history
skyroom
  • Loading branch information
Javad-Ak authored Sep 19, 2024
2 parents 578d9be + 9e14422 commit 052f35f
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def export_selected_users(self, request, queryset):

return ExcelResponse(data=data, worksheet_name="Users")

def export_selected_class_participants(self, request, queryset):
def export_selected_services(self, request, queryset):
data = []
headers = ['Username (Email)', 'Password (Phone Number)', 'Name', 'Talk / workshop']
data.append(headers)
headers = ['Username / Email', 'Phone Number', 'Name', 'Talk / workshop']

for user in queryset:
for service in user.services.all():
Expand All @@ -28,11 +27,31 @@ def export_selected_class_participants(self, request, queryset):
data.append([service.user.email, service.user.phone_number, service.user.first_name, event.title])

data.sort(key=lambda x: x[3])
data.insert(0, headers)
return ExcelResponse(data=data, worksheet_name="Participants")

def export_selected_online_participants(self, request, queryset):
data = []
headers = ['Username / Email', 'Phone Number', 'Name', 'Classes', 'Access']
data.append(headers)

for user in queryset:
classes = ""
for service in user.services.all():
if service.payment_state == "CM" and service.service_type == "TK":
talk = service.talk
if talk and talk.is_online and talk.presentation_link:
classes += ',' + talk.presentation_link.split('/')[-1]

if classes:
data.append([user.email, user.phone_number, user.first_name, classes[1:], "normal"])

return ExcelResponse(data=data, worksheet_name="Participants")

actions = ['export_selected_users', 'export_selected_class_participants']
actions = ['export_selected_users', 'export_selected_services', 'export_selected_online_participants']
export_selected_users.short_description = 'Export selected site users'
export_selected_class_participants.short_description = "Export selected site users' classes"
export_selected_services.short_description = "Export selected site users' services"
export_selected_online_participants.short_description = "Export selected site users' online classes"

# search by fields
search_fields = (
Expand Down

0 comments on commit 052f35f

Please sign in to comment.