Browse Source

Kopírujeme emaily z osoby do usera, aby jednoduše fungovalo resetování hesla.

export_seznamu_prednasek
Pavel 'LEdoian' Turinsky 5 years ago
parent
commit
83aa9a1758
  1. 22
      seminar/migrations/0073_copy_osoba_email_to_user_email.py
  2. 11
      seminar/models.py
  3. 4
      seminar/views.py

22
seminar/migrations/0073_copy_osoba_email_to_user_email.py

@ -0,0 +1,22 @@
# Generated by Django 2.2.9 on 2020-01-15 21:28
from django.db import migrations
def copy_mails(apps, schema_editor):
Osoba = apps.get_model('seminar', 'Osoba')
for o in Osoba.objects.all():
if o.user is not None:
u = o.user
u.email = o.email
u.save()
class Migration(migrations.Migration):
dependencies = [
('seminar', '0072_auto_20191204_2257'),
]
operations = [
migrations.RunPython(copy_mails, migrations.RunPython.noop)
]

11
seminar/models.py

@ -130,6 +130,17 @@ class Osoba(SeminarModelBase):
def __str__(self): def __str__(self):
return self.plne_jmeno() return self.plne_jmeno()
# Overridujeme save Osoby, aby když si změní e-mail, aby se projevil i v
# Userovi (a tak se dal poslat mail s resetem hesla)
def save(self, *args, **kwargs):
if self.user is not None:
u = self.user
# U svatého tučňáka, prosím ať tohle funguje.
# (Takhle se kódit asi nemá...)
u.email = self.email
u.save()
super().save()
# #
# Mělo by být částečně vytaženo z Aesopa # Mělo by být částečně vytaženo z Aesopa
# viz https://ovvp.mff.cuni.cz/wiki/aesop/export-skol. # viz https://ovvp.mff.cuni.cz/wiki/aesop/export-skol.

4
seminar/views.py

@ -1296,6 +1296,7 @@ class LogoutView(auth_views.LogoutView):
# Pavel: Vůbec nevím, proč to s _lazy funguje, ale bez toho to bylo rozbité. # Pavel: Vůbec nevím, proč to s _lazy funguje, ale bez toho to bylo rozbité.
next_page = reverse_lazy('titulni_strana') next_page = reverse_lazy('titulni_strana')
# "Chci resetovat heslo"
class PasswordResetView(auth_views.PasswordResetView): class PasswordResetView(auth_views.PasswordResetView):
#template_name = 'seminar/password_reset.html' #template_name = 'seminar/password_reset.html'
# TODO: vlastní email_template_name a subject_template_name a html_email_template_name # TODO: vlastní email_template_name a subject_template_name a html_email_template_name
@ -1303,14 +1304,17 @@ class PasswordResetView(auth_views.PasswordResetView):
from_email = 'login@mam.mff.cuni.cz' from_email = 'login@mam.mff.cuni.cz'
# TODO: přepsat User-a :-( # TODO: přepsat User-a :-(
# "Poslali jsme e-mail (pokud bylo kam))"
class PasswordResetDoneView(auth_views.PasswordResetDoneView): class PasswordResetDoneView(auth_views.PasswordResetDoneView):
#template_name = 'seminar/password_reset_done.html' #template_name = 'seminar/password_reset_done.html'
pass pass
# "Vymysli si heslo"
class PasswordResetConfirmView(auth_views.PasswordResetConfirmView): class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):
#template_name = 'seminar/password_confirm_done.html' #template_name = 'seminar/password_confirm_done.html'
success_url = reverse_lazy('reset_password_complete') success_url = reverse_lazy('reset_password_complete')
# "Heslo se asi změnilo."
class PasswordResetCompleteView(auth_views.PasswordResetCompleteView): class PasswordResetCompleteView(auth_views.PasswordResetCompleteView):
#template_name = 'seminar/password_complete_done.html' #template_name = 'seminar/password_complete_done.html'
pass pass

Loading…
Cancel
Save