# HG changeset patch # User Riwad Salim # Date 1530022013 -7200 # Node ID 907d5bfef8d66e18cb3faea88fdabf3c722be654 # Parent 6c095de7228dfdaafb024466c83e51e2fb2f6e09 fixing indexation problem and add method for natural key in model diff -r 6c095de7228d -r 907d5bfef8d6 src/iconolab/management/commands/importimages.py --- a/src/iconolab/management/commands/importimages.py Sun Jun 24 02:24:02 2018 +0200 +++ b/src/iconolab/management/commands/importimages.py Tue Jun 26 16:06:53 2018 +0200 @@ -22,7 +22,7 @@ metadata_dict, image_files, options, - source_dir + source_dir, ): target_dir = os.path.join(settings.MEDIA_ROOT, Image.media.field.upload_to) @@ -47,9 +47,9 @@ print('##### Copying file '+str(image)+' without converting') image_path = os.path.join(target_dir, image) new_image_name = image - shutil.copy(os.path.join(source_dir, image), target_dir) + shutil.copy(os.path.join(source_dir, image), image_path) try: - im = ImagePIL.open(os.path.join(target_dir, image)) + im = ImagePIL.open(image_path) im_width, im_height = im.size except Exception as e: print(e) diff -r 6c095de7228d -r 907d5bfef8d6 src/iconolab/models.py --- a/src/iconolab/models.py Sun Jun 24 02:24:02 2018 +0200 +++ b/src/iconolab/models.py Tue Jun 26 16:06:53 2018 +0200 @@ -134,6 +134,10 @@ """ metadata = models.TextField(default="", null=False) + @staticmethod + def get_natural_key(collection, raw_natural_key): + return '%s|%s' % (collection.name, raw_natural_key) + def __init__(self, *args, **kwargs): self.__metadata_obj = None self.__raw_natural_key = None diff -r 6c095de7228d -r 907d5bfef8d6 src/iconolab/search_indexes/urls.py --- a/src/iconolab/search_indexes/urls.py Sun Jun 24 02:24:02 2018 +0200 +++ b/src/iconolab/search_indexes/urls.py Tue Jun 26 16:06:53 2018 +0200 @@ -5,8 +5,8 @@ app_name = "iconolab-search_indexes" urlpatterns = [ - url(r'collection/(?P[a-z0-9\-]+)/model/(?P[a-z0-9\-]+)', views.IconolabSearchView.as_view(), name="collection_with_model_search"), - url(r'collection/(?P[a-z0-9\-]+)', views.IconolabSearchView.as_view(), name="collection_search"), + url(r'collection/(?P[a-zA-Z0-9\-]+)/model/(?P[a-z0-9\-]+)', views.IconolabSearchView.as_view(), name="collection_with_model_search"), + url(r'collection/(?P[a-zA-Z0-9\-]+)', views.IconolabSearchView.as_view(), name="collection_search"), url(r'^model/(?P[a-z0-9\-]+)', views.IconolabSearchView.as_view(), name="model_search"), url(r'^global/$', views.IconolabSearchView.as_view(), name="global_search"), ]