Created
December 11, 2011 05:29
-
-
Save madzak/1458584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActUserForm(forms.ModelForm): | |
user_status = ReadOnlyField() | |
activation_date = ReadOnlyField() | |
def __init__(self, *args, **kwargs): | |
super(ActUserForm, self).__init__(*args, **kwargs) | |
instance = getattr(self, 'instance', None) | |
if instance and instance.id: | |
self.fields['user_status'].initial = instance.get_user_status_display() | |
if instance.activation_date != None: | |
if instance.user_status != 'I': | |
self.fields['activation_date'].initial = instance.activation_date.strftime("%B %d %Y %I:%M %p") | |
else: | |
self.fields['activation_date'].initial = None | |
class Meta: | |
model = ActUser | |
fields = ( | |
'database_contact_name', | |
'database_username', | |
'database_password', | |
'security_level', | |
'excel_export', | |
'delete_records', | |
'calendar_access', | |
'dual_access', | |
'setup_assistance', | |
) | |
def save(self, commit=True): | |
model = super(ActUserForm, self).save(commit=False) | |
hosting = self.cleaned_data['hosting'] | |
if hosting.status == 'AC' or hosting.status == 'CO': | |
if model.user_status == 'A' or model.user_status == 'C': | |
model.user_status = 'C' | |
hosting.status = 'CO' | |
hosting.save() | |
if commit: | |
if model.user_status != 'I': | |
model.save() | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment