Ticket #22557: 22557.diff

File 22557.diff, 3.0 KB (added by Ted, 11 years ago)

proposed patch in diff form

  • django/contrib/staticfiles/management/commands/collectstatic.py

    diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
    index 0a14634..5a7d810 100644
    a b class Command(NoArgsCommand):  
    8787
    8888        if self.clear:
    8989            self.clear_dir('')
     90           
     91        if hasattr(self.storage, "on_collectstatic"):
     92            self.storage.on_collectstatic(self)           
    9093
    9194        if self.symlink:
    9295            handler = self.link_file
  • django/contrib/staticfiles/storage.py

    diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
    index fd114e4..9a7e25d 100644
    a b class ManifestFilesMixin(HashedFilesMixin):  
    316316                                   self).post_process(*args, **kwargs)
    317317        for post_processed in all_post_processed:
    318318            yield post_processed
     319        self.save_manifest()
     320   
     321    def save_manifest(self):
    319322        payload = {'paths': self.hashed_files, 'version': self.manifest_version}
    320323        if self.exists(self.manifest_name):
    321324            self.delete(self.manifest_name)
    322325        contents = json.dumps(payload).encode('utf-8')
    323326        self._save(self.manifest_name, ContentFile(contents))
    324327
     328    def on_collectstatic(self, command):
     329        self.hashed_files = OrderedDict()
     330
    325331
    326332class _MappingCache(object):
    327333    """
  • tests/staticfiles_tests/tests.py

    diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
    index dec38e2..33fd8b3 100644
    a b class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,  
    669669        manifest = storage.staticfiles_storage.load_manifest()
    670670        self.assertEqual(hashed_files, manifest)
    671671
     672    def test_manifest_on_collectstatic(self):
     673        '''
     674        staticfiles.json manifest doesn't persist stale/deleted records, see #22557
     675        '''
     676        self.assertNotIn("old_deleted_file", storage.staticfiles_storage.hashed_files)
     677        storage.staticfiles_storage.hashed_files["old_deleted_file"] = "record"
     678        if hasattr(storage, "save_manifest"):
     679            storage.staticfiles_storage.save_manifest()
     680        else:
     681            #Test will run correctly without previous version of ManifestFilesMixin
     682            #That did post-processing and saving in one method
     683            found_files = {}
     684            for p in storage.staticfiles_storage.post_process(found_files):
     685                pass
     686        storage.staticfiles_storage.load_manifest()
     687        self.assertEqual(
     688            storage.staticfiles_storage.hashed_files["old_deleted_file"],
     689            "record")
     690        self.run_collectstatic()
     691        self.assertNotIn("old_deleted_file", storage.staticfiles_storage.hashed_files)
     692
    672693
    673694# we set DEBUG to False here since the template tag wouldn't work otherwise
    674695@override_settings(**dict(
Back to Top