diff --git a/djangomaat/__init__.py b/djangomaat/__init__.py index 536e064..a5d9101 100644 --- a/djangomaat/__init__.py +++ b/djangomaat/__init__.py @@ -2,7 +2,7 @@ Application that optimizes large ordered data set retrieving when using MySql. """ -VERSION = (1, 4) +VERSION = (1, 4, 1) def get_version(): diff --git a/djangomaat/handlers.py b/djangomaat/handlers.py index 4822ecb..b38c281 100644 --- a/djangomaat/handlers.py +++ b/djangomaat/handlers.py @@ -9,11 +9,9 @@ from django.db.transaction import commit_on_success as atomic from django.contrib.contenttypes.models import ContentType -from django.utils.six import next from djangomaat.models import MaatRanking from djangomaat.exceptions import ManagerDoesNotExist, TypologyNotImplemented -from djangomaat.utils import auto_increment from djangomaat.settings import FLUSH_BATCH_SIZE GETTER_PREFIX = 'get_pk_list_for_' @@ -134,7 +132,7 @@ def flush_ordered_objects(self, logger=None, simulate=False): attached to. This method gets called by the management command. """ - if logger: + if logger is not None: if simulate: logger.write('Simulating flushing...\n') else: @@ -142,35 +140,33 @@ def flush_ordered_objects(self, logger=None, simulate=False): for typology, getter in self._typology_getters_iterator(): - if logger: + if logger is not None: logger.write('Handler: {} - Typology: {}\n'.format(self, typology)) if not simulate: with atomic(): # First, insert the new values, all set as not usable - if logger: + if logger is not None: logger.write('Insert...') start = time() - current_position = auto_increment(1) - objects = (MaatRanking( content_type_id=self._get_content_type().pk, object_id=object_id, typology=typology, usable=False, - position=next(current_position) - ) for object_id in getter()) + position=index + ) for index, object_id in enumerate(getter())) MaatRanking.objects.bulk_create(objects, FLUSH_BATCH_SIZE) - if logger: + if logger is not None: end = time() duration = end - start logger.write(' done ({:.3f} sec)\n'.format(duration)) # ...then delete the old values... - if logger: + if logger is not None: logger.write('Delete...') start = time() @@ -179,13 +175,13 @@ def flush_ordered_objects(self, logger=None, simulate=False): typology=typology, usable=True).delete() - if logger: + if logger is not None: end = time() duration = end - start logger.write(' done ({:.3f} sec)\n'.format(duration)) # ...and lastly update the inserted values as usable - if logger: + if logger is not None: logger.write('Update...') start = time() @@ -194,7 +190,7 @@ def flush_ordered_objects(self, logger=None, simulate=False): typology=typology, usable=False).update(usable=True) - if logger: + if logger is not None: end = time() duration = end - start logger.write(' done ({:.3f} sec)\n'.format(duration)) @@ -231,6 +227,6 @@ def __init__(self, handler): self.handler = handler def __get__(self, instance, type=None): - if instance != None: + if instance is not None: raise AttributeError("Handler isn't accessible via {} instances".format(type.__name__)) return self.handler diff --git a/djangomaat/utils.py b/djangomaat/utils.py deleted file mode 100644 index 66aaf8f..0000000 --- a/djangomaat/utils.py +++ /dev/null @@ -1,6 +0,0 @@ -def auto_increment(start_value=0): - """Returns an iterator over an auto increment value.""" - value = start_value - 1 - while True: - value += 1 - yield value diff --git a/docs/changelog.rst b/docs/changelog.rst index 2a5e14c..a34f791 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,10 +2,16 @@ Changelog ========= -Version 1.4 +Version 1.4.1 ============= +* More idiomatic syntax + + +Version 1.4 +=========== * Added migrations files for Django 1.7+ + Version 1.3 =========== * Added support for Python >= 3.2 diff --git a/setup.py b/setup.py index 6290f31..c7098b1 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name=APP_NAME, - version="{0[0]}.{0[1]}".format(__import__(APP_NAME).VERSION[:2]), + version=".".join(map(str, __import__(APP_NAME).VERSION)), packages=find_packages(), include_package_data=True, description = 'Fast MySQL ordering',