|
| 1 | +from datetime import date |
| 2 | + |
1 | 3 | import tablib |
2 | 4 | from django.conf import settings |
3 | 5 | from django.contrib import admin |
@@ -209,13 +211,63 @@ def force_verify(self, request, object_id): |
209 | 211 | return redirect("admin:users_customuser_change", object_id) |
210 | 212 |
|
211 | 213 | 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 | + # для старших - специальность, вуз, учебное заведение |
213 | 265 |
|
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]) |
216 | 268 |
|
217 | 269 | binary_data = response_data.export("xlsx") |
218 | | - file_name = "all_users_names_emails" |
| 270 | + file_name = "users" |
219 | 271 | response = HttpResponse( |
220 | 272 | content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", |
221 | 273 | headers={"Content-Disposition": f'attachment; filename="{file_name}.xlsx"'}, |
|
0 commit comments