|
11 | 11 |
|
12 | 12 | from django.conf import settings |
13 | 13 | from django.contrib.sites.models import Site |
14 | | -from django.core.exceptions import PermissionDenied |
| 14 | +from django.core.exceptions import PermissionDenied, ObjectDoesNotExist |
15 | 15 | from django.core.urlresolvers import reverse |
16 | 16 | from django.template.loader import render_to_string |
17 | 17 | from django.shortcuts import get_object_or_404 |
18 | 18 | from django.utils.encoding import smart_str |
| 19 | +from django.core.validators import email_re |
19 | 20 |
|
20 | 21 | from ietf.dbtemplate.models import DBTemplate |
21 | 22 | from ietf.person.models import Email, Person |
|
24 | 25 | from ietf.utils.mail import send_mail_text, send_mail |
25 | 26 | from ietf.utils.log import log |
26 | 27 |
|
| 28 | +import debug |
| 29 | + |
27 | 30 | MAIN_NOMCOM_TEMPLATE_PATH = '/nomcom/defaults/' |
28 | 31 | QUESTIONNAIRE_TEMPLATE = 'position/questionnaire.txt' |
29 | 32 | HEADER_QUESTIONNAIRE_TEMPLATE = 'position/header_questionnaire.txt' |
@@ -61,14 +64,25 @@ def get_year_by_nomcom(nomcom): |
61 | 64 |
|
62 | 65 |
|
63 | 66 | def get_user_email(user): |
64 | | - emails = user.person.email_set.filter(active=True).order_by('-time') |
65 | | - if emails: |
66 | | - for email in emails: |
67 | | - if email.address == user.username: |
68 | | - return email |
69 | | - return emails[0] |
70 | | - return None |
71 | | - |
| 67 | + # a user object already has an email field, but we don't want to |
| 68 | + # overwrite anything that might be there, and we don't know that |
| 69 | + # what's there is the right thing, so we cache the lookup results in a |
| 70 | + # separate attribute |
| 71 | + if not hasattr(user, "_email_cache"): |
| 72 | + user._email_cache = None |
| 73 | + if hasattr(user, "person"): |
| 74 | + emails = user.person.email_set.filter(active=True).order_by('-time') |
| 75 | + if emails: |
| 76 | + user._email_cache = emails[0] |
| 77 | + for email in emails: |
| 78 | + if email.address == user.username: |
| 79 | + user._email_cache = email |
| 80 | + else: |
| 81 | + try: |
| 82 | + user._email_cache = Email.objects.get(address=user.username) |
| 83 | + except ObjectDoesNotExist: |
| 84 | + pass |
| 85 | + return user._email_cache |
72 | 86 |
|
73 | 87 | def is_nomcom_member(user, nomcom): |
74 | 88 | is_group_member = nomcom.group.is_member(user) |
|
0 commit comments