diff options
| -rw-r--r-- | ishtar_common/tests.py | 12 | ||||
| -rw-r--r-- | ishtar_common/utils.py | 18 | 
2 files changed, 14 insertions, 16 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 9770d4b48..7443c271e 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1684,12 +1684,12 @@ class CleanMedia(TestCase):      def test_rename(self):          test_names = [ -            (u"éofficier2-12-02-04.93_gvK3hAr-1_2m7zZPn-1_nKhh2S2-1_"\ -             u"ONmUhfD-1_ymA3gGJ-1_XzJyRx3-1_PhvRcO8-1-thumb_ZwWMKBd.jpg", -             u"éofficier2-12-02-04.93-thumb.jpg"), -            (u"a_ZwWMKBd.jpg", False),  # no rename because too short -            (u"hoplala_gvK3hAr_2m7zZPn_nKhh2S2_ZwWMKBd.jpg", -             u"hoplala_gvK3hAr_2m7zZPn_nKhh2S2.jpg",),  # stop before because +            ("éofficier2-12-02-04.93_gvK3hAr-1_2m7zZPn-1_nKhh2S2-1_"\ +             "ONmUhfD-1_ymA3gGJ-1_XzJyRx3-1_PhvRcO8-1-thumb_ZwWMKBd.jpg", +             "éofficier2-12-02-04.93-thumb.jpg"), +            ("a_ZwWMKBd.jpg", False),  # no rename because too short +            ("hoplala_gvK3hAr_2m7zZPn_nKhh2S2_ZwWMKBd.jpg", +             "hoplala_gvK3hAr_2m7zZPn_nKhh2S2.jpg",),  # stop before because              # another file exists          ]          base_dir = os.sep.join([settings.ROOT_PATH, u"..", u"ishtar_common", diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 33d1f5bec..d0bfee02a 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1194,7 +1194,11 @@ def simplify_name(full_path_name, check_existing=False):              if match:                  new_name = name.replace(match.group(), '')                  full_new_name = os.sep.join([path, new_name + ext]) -                if not check_existing or not os.path.isfile(full_new_name): +                try: +                    is_file = os.path.isfile(full_new_name) +                except UnicodeEncodeError: +                    is_file = os.path.isfile(full_new_name.encode('utf-8')) +                if not check_existing or not is_file:                      # do not take the place of another file                      name = new_name[:]                      break @@ -1211,23 +1215,17 @@ def rename_and_simplify_media_name(full_path_name, rename=True):      :return: new full path name (or old if not changed), modified      """      try: -        is_str = False          exists = os.path.exists(full_path_name)          is_file = os.path.isfile(full_path_name)      except UnicodeEncodeError: -        is_str = True -        full_path_name = full_path_name.encode('utf-8') -        exists = os.path.exists(full_path_name) -        is_file = os.path.isfile(full_path_name) +        full_path_name_unicode = full_path_name.encode('utf-8') +        exists = os.path.exists(full_path_name_unicode) +        is_file = os.path.isfile(full_path_name_unicode)      if not exists or not is_file:          return full_path_name, False      path, current_name, name = simplify_name(full_path_name,                                               check_existing=True) -    if is_str: -        full_path_name = full_path_name.decode('utf-8') -        name = name.decode('utf-8') -        path = path.decode('utf-8')      if current_name == name:          return full_path_name, False | 
