Skip to content
Snippets Groups Projects
Commit 3aa3624f authored by Restyled.io's avatar Restyled.io
Browse files

Restyled by yapf

parent 8ae94b8c
No related branches found
No related tags found
No related merge requests found
...@@ -26,9 +26,8 @@ class CeleryHaystackSignalHandler(Task): ...@@ -26,9 +26,8 @@ class CeleryHaystackSignalHandler(Task):
bits = identifier.split(".") bits = identifier.split(".")
if len(bits) < 2: if len(bits) < 2:
logger.error( logger.error("Unable to parse object "
"Unable to parse object " "identifer '%s'. Moving on..." % identifier "identifer '%s'. Moving on..." % identifier)
)
return (None, None) return (None, None)
pk = bits[-1] pk = bits[-1]
...@@ -46,7 +45,8 @@ class CeleryHaystackSignalHandler(Task): ...@@ -46,7 +45,8 @@ class CeleryHaystackSignalHandler(Task):
model_class = apps.get_model(app_name, classname) model_class = apps.get_model(app_name, classname)
if model_class is None: if model_class is None:
raise ImproperlyConfigured("Could not load model '%s'." % object_path) raise ImproperlyConfigured("Could not load model '%s'." %
object_path)
return model_class return model_class
def get_instance(self, model_class, pk, **kwargs): def get_instance(self, model_class, pk, **kwargs):
...@@ -57,14 +57,11 @@ class CeleryHaystackSignalHandler(Task): ...@@ -57,14 +57,11 @@ class CeleryHaystackSignalHandler(Task):
try: try:
instance = model_class._default_manager.get(pk=pk) instance = model_class._default_manager.get(pk=pk)
except model_class.DoesNotExist: except model_class.DoesNotExist:
logger.error( logger.error("Couldn't load %s.%s.%s. Somehow it went missing?" % (
"Couldn't load %s.%s.%s. Somehow it went missing?" model_class._meta.app_label.lower(),
% ( model_class._meta.object_name.lower(),
model_class._meta.app_label.lower(), pk,
model_class._meta.object_name.lower(), ))
pk,
)
)
except model_class.MultipleObjectsReturned: except model_class.MultipleObjectsReturned:
logger.error("More than one object with pk %s. Oops?" % pk) logger.error("More than one object with pk %s. Oops?" % pk)
return instance return instance
...@@ -74,14 +71,14 @@ class CeleryHaystackSignalHandler(Task): ...@@ -74,14 +71,14 @@ class CeleryHaystackSignalHandler(Task):
Fetch the model's registered ``SearchIndex`` in a standarized way. Fetch the model's registered ``SearchIndex`` in a standarized way.
""" """
try: try:
using_backends = connection_router.for_write(**{"models": [model_class]}) using_backends = connection_router.for_write(
**{"models": [model_class]})
for using in using_backends: for using in using_backends:
index_holder = connections[using].get_unified_index() index_holder = connections[using].get_unified_index()
yield index_holder.get_index(model_class), using yield index_holder.get_index(model_class), using
except IndexNotFoundException: except IndexNotFoundException:
raise ImproperlyConfigured( raise ImproperlyConfigured("Couldn't find a SearchIndex for %s." %
"Couldn't find a SearchIndex for %s." % model_class model_class)
)
def run(self, action, identifier, **kwargs): def run(self, action, identifier, **kwargs):
""" """
...@@ -98,9 +95,10 @@ class CeleryHaystackSignalHandler(Task): ...@@ -98,9 +95,10 @@ class CeleryHaystackSignalHandler(Task):
# Then get the model class for the object path # Then get the model class for the object path
model_class = self.get_model_class(object_path, **kwargs) model_class = self.get_model_class(object_path, **kwargs)
for current_index, using in self.get_indexes(model_class, **kwargs): for current_index, using in self.get_indexes(model_class, **kwargs):
current_index_name = ".".join( current_index_name = ".".join([
[current_index.__class__.__module__, current_index.__class__.__name__] current_index.__class__.__module__,
) current_index.__class__.__name__
])
if action == "delete": if action == "delete":
# If the object is gone, we'll use just the identifier # If the object is gone, we'll use just the identifier
...@@ -111,16 +109,15 @@ class CeleryHaystackSignalHandler(Task): ...@@ -111,16 +109,15 @@ class CeleryHaystackSignalHandler(Task):
logger.exception(exc) logger.exception(exc)
self.retry(exc=exc) self.retry(exc=exc)
else: else:
msg = "Deleted '%s' (with %s)" % (identifier, current_index_name) msg = "Deleted '%s' (with %s)" % (identifier,
current_index_name)
logger.debug(msg) logger.debug(msg)
elif action == "update": elif action == "update":
# and the instance of the model class with the pk # and the instance of the model class with the pk
instance = self.get_instance(model_class, pk, **kwargs) instance = self.get_instance(model_class, pk, **kwargs)
if instance is None: if instance is None:
logger.debug( logger.debug("Failed updating '%s' (with %s)" %
"Failed updating '%s' (with %s)" (identifier, current_index_name))
% (identifier, current_index_name)
)
raise ValueError("Couldn't load object '%s'" % identifier) raise ValueError("Couldn't load object '%s'" % identifier)
# Call the appropriate handler of the current index and # Call the appropriate handler of the current index and
...@@ -131,7 +128,8 @@ class CeleryHaystackSignalHandler(Task): ...@@ -131,7 +128,8 @@ class CeleryHaystackSignalHandler(Task):
logger.exception(exc) logger.exception(exc)
self.retry(exc=exc) self.retry(exc=exc)
else: else:
msg = "Updated '%s' (with %s)" % (identifier, current_index_name) msg = "Updated '%s' (with %s)" % (identifier,
current_index_name)
logger.debug(msg) logger.debug(msg)
else: else:
logger.error("Unrecognized action '%s'. Moving on..." % action) logger.error("Unrecognized action '%s'. Moving on..." % action)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment