Skip to content

Commit 26e38f7

Browse files
committed
Для действия Подтверждение пользователя добавлено автоматическое выставление даты верификации
1 parent effcae3 commit 26e38f7

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

users/admin.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
import urllib.parse
12
from datetime import date
23

34
import tablib
4-
import urllib.parse
55
from django.conf import settings
66
from django.contrib import admin
77
from django.contrib.auth.models import Permission
88
from django.http import HttpResponse
99
from django.shortcuts import redirect
1010
from django.urls import path
11+
from django.utils.timezone import now
1112

13+
from core.admin import SkillToObjectInline
1214
from core.utils import XlsxFileToExport
1315
from mailing.views import MailingTemplateRender
1416
from users.services.users_activity import UserActivityDataPreparer
15-
from .helpers import send_verification_completed_email, force_verify_user
17+
18+
from .helpers import force_verify_user, send_verification_completed_email
1619
from .models import (
1720
CustomUser,
18-
UserAchievement,
19-
Member,
20-
Mentor,
2121
Expert,
2222
Investor,
23-
UserLink,
23+
Member,
24+
Mentor,
25+
UserAchievement,
2426
UserEducation,
25-
UserWorkExperience,
26-
UserSkillConfirmation,
2727
UserLanguages,
28+
UserLink,
29+
UserSkillConfirmation,
30+
UserWorkExperience,
2831
)
2932

30-
from core.admin import SkillToObjectInline
31-
3233
admin.site.register(Permission)
3334

3435

@@ -55,7 +56,7 @@ class UserLanguagesInline(admin.TabularInline):
5556

5657
@admin.action(description="Сделать выбранных пользователей подтверждёнными")
5758
def make_active(modeladmin, request, queryset):
58-
queryset.update(is_active=True)
59+
queryset.update(is_active=True, verification_date=now().date())
5960

6061

6162
@admin.register(CustomUser)
@@ -268,7 +269,9 @@ def get_users_activity(self, _) -> HttpResponse:
268269
binary_data_to_export,
269270
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
270271
)
271-
response["Content-Disposition"] = f'attachment; filename*=UTF-8\'\'{encoded_file_name}'
272+
response["Content-Disposition"] = (
273+
f"attachment; filename*=UTF-8''{encoded_file_name}"
274+
)
272275

273276
return response
274277

@@ -321,7 +324,9 @@ def get_export_users_emails(self, users):
321324
baby.first_name + " " + baby.last_name,
322325
today.year - baby.birthday.year,
323326
", ".join(interests),
324-
"; ".join(baby.education.values_list("organization_name", flat=True)),
327+
"; ".join(
328+
baby.education.values_list("organization_name", flat=True)
329+
),
325330
baby.v2_speciality if baby.v2_speciality else baby.speciality,
326331
baby.email,
327332
]
@@ -337,7 +342,9 @@ def get_export_users_emails(self, users):
337342
big_man.first_name + " " + big_man.last_name,
338343
today.year - big_man.birthday.year,
339344
", ".join(industry_names),
340-
"; ".join(big_man.education.values_list("organization_name", flat=True)),
345+
"; ".join(
346+
big_man.education.values_list("organization_name", flat=True)
347+
),
341348
big_man.v2_speciality
342349
if big_man.v2_speciality
343350
else big_man.speciality,

users/helpers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from django.conf import settings
2-
from django.core.cache import cache
3-
from django.utils import timezone
42
from django.contrib.auth import get_user_model
5-
from rest_framework_simplejwt.tokens import RefreshToken
63
from django.contrib.sites.shortcuts import get_current_site
4+
from django.core.cache import cache
75
from django.urls import reverse
6+
from django.utils import timezone
7+
from django.utils.timezone import now
8+
from rest_framework_simplejwt.tokens import RefreshToken
89

910
from mailing.utils import send_mail
1011
from users.constants import PROTOCOL
@@ -31,7 +32,8 @@ def verify_email(user, request):
3132

3233
def send_verification_completed_email(user: User):
3334
template_content = open(
34-
settings.BASE_DIR / "templates/email/verification-succeed.html", encoding="utf-8"
35+
settings.BASE_DIR / "templates/email/verification-succeed.html",
36+
encoding="utf-8",
3537
).read()
3638
send_mail(
3739
user=user,
@@ -97,6 +99,8 @@ def force_verify_user(user: User) -> None:
9799

98100
# todo: send email
99101
user.is_active = True
102+
if hasattr(user, "verification_date"):
103+
user.verification_date = now().date()
100104
user.save()
101105

102106

0 commit comments

Comments
 (0)