Revision a196eb7e astakos/im/admin/forms.py
b/astakos/im/admin/forms.py | ||
---|---|---|
51 | 51 |
The class defines a save method which sets ``is_verified`` to True so as the user |
52 | 52 |
during the next login will not to be redirected to profile page. |
53 | 53 |
""" |
54 |
quota = forms.CharField(label=_('Quota (GiB)')) |
|
55 |
|
|
54 | 56 |
class Meta: |
55 | 57 |
model = AstakosUser |
56 |
exclude = ('groups', 'user_permissions') |
|
58 |
fields = ('email', 'first_name', 'last_name', 'is_superuser', |
|
59 |
'affiliation', 'is_active', 'invitations', 'quota', |
|
60 |
'auth_token', 'auth_token_created', 'auth_token_expires', |
|
61 |
'date_joined', 'updated') |
|
57 | 62 |
|
58 | 63 |
def __init__(self, *args, **kwargs): |
59 | 64 |
super(AdminProfileForm, self).__init__(*args, **kwargs) |
60 | 65 |
instance = getattr(self, 'instance', None) |
61 |
ro_fields = ('username','date_joined', 'auth_token', 'last_login', 'email') |
|
66 |
ro_fields = ('date_joined', 'auth_token', 'auth_token_created', |
|
67 |
'auth_token_expires', 'updated', 'email') |
|
62 | 68 |
if instance and instance.id: |
63 | 69 |
for field in ro_fields: |
64 | 70 |
self.fields[field].widget.attrs['readonly'] = True |
71 |
user = kwargs['instance'] |
|
72 |
if user: |
|
73 |
quota = lambda x: int(x) / 1024 ** 3 |
|
74 |
self.fields['quota'].widget.attrs['value'] = quota(user.quota) |
|
75 |
|
|
76 |
def save(self, commit=True): |
|
77 |
user = super(AdminProfileForm, self).save(commit=False) |
|
78 |
quota = lambda x: int(x or 0) * (1024 ** 3) |
|
79 |
user.quota = quota(self.cleaned_data['quota']) |
|
80 |
user.save() |
|
65 | 81 |
|
66 | 82 |
class AdminUserCreationForm(LocalUserCreationForm): |
67 | 83 |
class Meta: |
Also available in: Unified diff