mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Preload settings in the model, makes cleaner code
This commit is contained in:
@@ -136,7 +136,9 @@ class Service(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def api_class(self):
|
def api_class(self):
|
||||||
return get_api(self.api)
|
api = get_api(self.api)
|
||||||
|
api.settings = self.settings
|
||||||
|
return api
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -163,7 +165,7 @@ class Service(models.Model):
|
|||||||
|
|
||||||
# Load defaults from the module's settings dict
|
# Load defaults from the module's settings dict
|
||||||
if self.api:
|
if self.api:
|
||||||
modset = self.api_class.settings
|
modset = get_api(self.api).settings
|
||||||
for k in modset:
|
for k in modset:
|
||||||
if not k in setdict:
|
if not k in setdict:
|
||||||
setdict[k] = modset[k]
|
setdict[k] = modset[k]
|
||||||
@@ -191,7 +193,6 @@ class ServiceAccount(models.Model):
|
|||||||
|
|
||||||
# Grab the API class and load the settings
|
# Grab the API class and load the settings
|
||||||
api = self.service.api_class
|
api = self.service.api_class
|
||||||
api.settings = self.service.settings
|
|
||||||
|
|
||||||
if not self.service_uid:
|
if not self.service_uid:
|
||||||
# Create a account if we've not got a UID
|
# Create a account if we've not got a UID
|
||||||
@@ -229,7 +230,6 @@ class ServiceAccount(models.Model):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def pre_delete_listener( **kwargs ):
|
def pre_delete_listener( **kwargs ):
|
||||||
api = kwargs['instance'].service.api_class
|
api = kwargs['instance'].service.api_class
|
||||||
api.settings = kwargs['instance'].service.settings
|
|
||||||
if not api.delete_user(kwargs['instance'].service_uid):
|
if not api.delete_user(kwargs['instance'].service_uid):
|
||||||
raise ServiceError('Unable to delete account on related service')
|
raise ServiceError('Unable to delete account on related service')
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ def service_reset(request, serviceid=0):
|
|||||||
passwd = form.cleaned_data['password']
|
passwd = form.cleaned_data['password']
|
||||||
|
|
||||||
api = acc.service.api_class
|
api = acc.service.api_class
|
||||||
api.settings = acc.service.settings
|
|
||||||
if not api.reset_password(acc.service_uid, passwd):
|
if not api.reset_password(acc.service_uid, passwd):
|
||||||
error = True
|
error = True
|
||||||
return render_to_response('sso/serviceaccount/resetcomplete.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('sso/serviceaccount/resetcomplete.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|||||||
Reference in New Issue
Block a user