Skip to content

Commit a920f72

Browse files
committed
uoutload
1 parent 56135a8 commit a920f72

1 file changed

Lines changed: 56 additions & 4 deletions

File tree

users/admin.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import date
2+
13
import tablib
24
from django.conf import settings
35
from django.contrib import admin
@@ -209,13 +211,63 @@ def force_verify(self, request, object_id):
209211
return redirect("admin:users_customuser_change", object_id)
210212

211213
def get_export_users_emails(self, users):
212-
response_data = tablib.Dataset(headers=["ФИО", "Email"])
214+
response_data = tablib.Dataset(
215+
headers=["Имя и фамилия", "Возраст", "Интересы", "ВУЗ", "Специальность"]
216+
)
217+
218+
today = date.today()
219+
220+
date_limit_18 = date(today.year - 18, today.month, today.day)
221+
users = (
222+
CustomUser.objects.all()
223+
.select_related("v2_speciality")
224+
.prefetch_related(
225+
"collaborations__project", "collaborations__project__industry"
226+
)
227+
)
228+
little_mans = users.filter(birthday__lte=date_limit_18)
229+
big_mans = users.exclude(id__in=little_mans.values_list("id", flat=True))
230+
231+
# whole_quality = users.count()
232+
# quantity_little_mans = little_mans.count()
233+
# quantity_big_mans = whole_quality - quantity_little_mans
234+
235+
for baby in little_mans:
236+
projects_names = [
237+
collab.project.industry.name for collab in baby.collaborations.all()
238+
]
239+
response_data.append(
240+
[
241+
baby.first_name + " " + baby.last_name,
242+
today.year - baby.birthday.year,
243+
", ".join(projects_names),
244+
"",
245+
"",
246+
]
247+
)
248+
249+
for big_man in big_mans:
250+
projects_names = [
251+
collab.project.industry.name for collab in big_man.collaborations.all()
252+
]
253+
response_data.append(
254+
[
255+
big_man.first_name + " " + big_man.last_name,
256+
today.year - big_man.birthday.year,
257+
", ".join(projects_names),
258+
big_man.organization,
259+
big_man.speciality,
260+
]
261+
)
262+
263+
# для малолеток указать теги проектов, если нет - навыки
264+
# для старших - специальность, вуз, учебное заведение
213265

214-
for user in users:
215-
response_data.append([user.first_name + " " + user.last_name, user.email])
266+
# for user in users:
267+
# response_data.append([user.first_name + " " + user.last_name, user.email])
216268

217269
binary_data = response_data.export("xlsx")
218-
file_name = "all_users_names_emails"
270+
file_name = "users"
219271
response = HttpResponse(
220272
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
221273
headers={"Content-Disposition": f'attachment; filename="{file_name}.xlsx"'},

0 commit comments

Comments
 (0)