allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/4] allura git commit: [#8003] ticket:877 Delete all attachments with equal filename
Date Tue, 05 Jan 2016 23:14:46 GMT
[#8003] ticket:877 Delete all attachments with equal filename


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/f75277cf
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f75277cf
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f75277cf

Branch: refs/heads/master
Commit: f75277cfb80bba0cb95cc3d5acdb4e7b0a0cd82f
Parents: 9e952a6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Dec 24 17:35:15 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Thu Dec 24 17:35:15 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/attachments.py | 31 ++++++++++++++++-----------
 1 file changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f75277cf/Allura/allura/controllers/attachments.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/attachments.py b/Allura/allura/controllers/attachments.py
index a175bf9..6766d02 100644
--- a/Allura/allura/controllers/attachments.py
+++ b/Allura/allura/controllers/attachments.py
@@ -67,12 +67,22 @@ class AttachmentController(BaseController):
         self.filename = filename
         self.artifact = artifact
 
-    @LazyProperty
-    def attachment(self):
+    @property
+    def attachments_query(self):
         metadata = self.AttachmentClass.metadata_for(self.artifact)
         metadata['type'] = 'attachment'
+        return dict(filename=self.filename, **metadata)
+
+    @property
+    def thumbnails_query(self):
+        metadata = self.AttachmentClass.metadata_for(self.artifact)
+        metadata['type'] = 'thumbnail'
+        return dict(filename=self.filename, **metadata)
+
+    @LazyProperty
+    def attachment(self):
         attachment = self.AttachmentClass.query.find(
-            dict(filename=self.filename, **metadata)
+            self.attachments_query
         ).sort('_id', -1).limit(1).first()
         if attachment is None:
             raise exc.HTTPNotFound
@@ -80,10 +90,8 @@ class AttachmentController(BaseController):
 
     @LazyProperty
     def thumbnail(self):
-        metadata = self.AttachmentClass.metadata_for(self.artifact)
-        metadata['type'] = 'thumbnail'
         attachment = self.AttachmentClass.query.find(
-            dict(filename=self.filename, **metadata)
+            self.thumbnails_query
         ).sort('_id', -1).limit(1).first()
         if attachment is None:
             raise exc.HTTPNotFound
@@ -92,12 +100,11 @@ class AttachmentController(BaseController):
     def handle_post(self, delete, **kw):
         require_access(self.artifact, self.edit_perm)
         if delete:
-            self.attachment.delete()
-            try:
-                if self.thumbnail:
-                    self.thumbnail.delete()
-            except exc.HTTPNotFound:
-                pass
+            # Remove all attachments with such filename. Since we're showing
+            # only the most recent one we don't want previous attachments
+            # with such filename (if there was any) to show up after delete
+            self.AttachmentClass.query.remove(self.attachments_query)
+            self.AttachmentClass.query.remove(self.thumbnails_query)
 
     @expose()
     def index(self, delete=False, **kw):


Mime
View raw message