|
7 | 7 | from django.utils.html import mark_safe |
8 | 8 | from django.core.urlresolvers import reverse as urlreverse |
9 | 9 |
|
| 10 | +import debug # pyflakes:ignore |
| 11 | + |
10 | 12 | from ietf.person.models import Person, Email |
11 | 13 |
|
12 | 14 |
|
@@ -43,16 +45,30 @@ def ascii_cleaner(supposedly_ascii): |
43 | 45 | raise forms.ValidationError("Please only enter ASCII characters.") |
44 | 46 | return supposedly_ascii |
45 | 47 |
|
46 | | -class PersonForm(ModelForm): |
47 | | - class Meta: |
48 | | - model = Person |
49 | | - exclude = ('time', 'user') |
| 48 | +def get_person_form(*args, **kwargs): |
| 49 | + |
| 50 | + exclude_list = ['time', 'user', 'photo_thumb', ] |
| 51 | + |
| 52 | + person = kwargs['instance'] |
| 53 | + roles = person.role_set.all() |
| 54 | + if not roles: |
| 55 | + exclude_list += ['biography', 'photo', ] |
| 56 | + |
| 57 | + class PersonForm(ModelForm): |
| 58 | + class Meta: |
| 59 | + model = Person |
| 60 | + exclude = exclude_list |
| 61 | + |
| 62 | + def __init__(self, *args, **kwargs): |
| 63 | + super(ModelForm, self).__init__(*args, **kwargs) |
| 64 | + |
| 65 | + def clean_ascii(self): |
| 66 | + return ascii_cleaner(self.cleaned_data.get("ascii") or u"") |
50 | 67 |
|
51 | | - def clean_ascii(self): |
52 | | - return ascii_cleaner(self.cleaned_data.get("ascii") or u"") |
| 68 | + def clean_ascii_short(self): |
| 69 | + return ascii_cleaner(self.cleaned_data.get("ascii_short") or u"") |
53 | 70 |
|
54 | | - def clean_ascii_short(self): |
55 | | - return ascii_cleaner(self.cleaned_data.get("ascii_short") or u"") |
| 71 | + return PersonForm(*args, **kwargs) |
56 | 72 |
|
57 | 73 |
|
58 | 74 | class NewEmailForm(forms.Form): |
|
0 commit comments