10
10
from django .utils .safestring import mark_safe
11
11
12
12
from app .mixins import BootstrapFormMixin
13
- from app .utils import get_theme
13
+ from app .utils import get_theme , is_instance_on_db
14
14
from user .models import User
15
15
from django .utils .translation import gettext_lazy as _
16
16
@@ -160,15 +160,15 @@ class UserProfileForm(BootstrapFormMixin, forms.ModelForm):
160
160
def __init__ (self , * args , ** kwargs ):
161
161
super ().__init__ (* args , ** kwargs )
162
162
instance = kwargs .get ('instance' , None )
163
- if instance is not None and instance . _state . db is not None : # instance in DB
163
+ if is_instance_on_db ( instance ) : # instance in DB
164
164
email_field = self .fields .get ('email' )
165
165
email_field .widget .attrs ['readonly' ] = True
166
166
email_field .help_text = _ ('This field cannot be modified' )
167
167
168
168
def get_bootstrap_field_info (self ):
169
169
info = super ().get_bootstrap_field_info ()
170
170
instance = getattr (self , 'instance' , None )
171
- if instance is None or instance . _state . db is None : # instance not in DB
171
+ if not is_instance_on_db ( instance ) : # instance not in DB
172
172
fields = info [_ ('Personal Info' )]['fields' ]
173
173
result = []
174
174
for field in fields :
@@ -183,7 +183,7 @@ def get_bootstrap_field_info(self):
183
183
184
184
def clean_email (self ):
185
185
instance = getattr (self , 'instance' , None )
186
- if instance is not None and instance . _state . db is not None : # instance in DB
186
+ if is_instance_on_db ( instance ) : # instance in DB
187
187
return self .instance .email
188
188
return self .cleaned_data .get ('email' )
189
189
0 commit comments