allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/7] git commit: [#5666] ticket:261 set app_config_id to thumbnail attach when moving the ticket.
Date Tue, 05 Feb 2013 17:26:28 GMT
[#5666] ticket:261 set app_config_id to thumbnail attach when moving the ticket.


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

Branch: refs/heads/master
Commit: 4db3639f574398d49fdcf9211db4e59bc5b5cf98
Parents: fe7ef06
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Fri Feb 1 13:27:35 2013 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Feb 5 17:26:04 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py          |   20 ++++++++++++---
 .../forgetracker/tests/functional/test_root.py     |   13 ++++++---
 2 files changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4db3639f/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 36e55a9..292d241 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -526,13 +526,20 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 attachment.filename, attachment.file,
                 content_type=attachment.type)
 
+    def _move_attach(self,attachments,attach_metadata,app_config_id):
+        for attach in attachments:
+            attach.app_config_id = app_config_id
+            attach_thumb = BaseAttachment.query.get(filename=attach.filename, **attach_metadata)
+            if attach_thumb:
+                attach_thumb.app_config_id = app_config_id
+
     def move(self, app_config):
         '''Move ticket from current tickets app to tickets app with given app_config'''
         app = app_config.project.app_instance(app_config)
         prior_url = self.url()
         prior_app = self.app
-        for attach in self.attachments:
-            attach.app_config_id = app_config._id
+        attachments = self.attachments
+        attach_metadata = BaseAttachment.metadata_for(self)
         prior_cfs = [
             (cf['name'], cf['type'], cf['label'])
             for cf in prior_app.globals.custom_fields or []]
@@ -588,14 +595,19 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                     log.warning('Try to create duplicate ticket %s when moving from %s' %
(self.url(), prior_url))
                     session(self).expunge(self)
                     continue
+
+        attach_metadata['type'] = 'thumbnail'
+        self._move_attach(attachments,attach_metadata,app_config._id)
+
         # move ticket's discussion thread, thus all new commnets will go to a new ticket's
feed
         self.discussion_thread.app_config_id = app_config._id
         self.discussion_thread.discussion_id = app_config.discussion_id
         for post in self.discussion_thread.posts:
+            attach_metadata = BaseAttachment.metadata_for(post)
+            attach_metadata['type'] = 'thumbnail'
             post.app_config_id = app_config._id
             post.app_id = app_config._id
-            for attach in post.attachments:
-                attach.app_config_id = app_config._id
+            self._move_attach(post.attachments,attach_metadata,app_config._id)
 
         session(self.discussion_thread).flush(self.discussion_thread)
         # need this to reset app_config RelationProperty on ticket to a new one

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4db3639f/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 61ac34c..a6f4661 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1279,8 +1279,9 @@ class TestFunctionalController(TrackerTestController):
 
     @td.with_tool('test2', 'Tickets', 'bugs2')
     def test_move_attachment(self):
-        file_name = 'test_root.py'
-        file_data = file(__file__).read()
+        file_name = 'neo-icon-set-454545-256x350.png'
+        file_path = os.path.join(allura.__path__[0],'nf','allura','images',file_name)
+        file_data = file(file_path).read()
         upload = ('attachment', file_name, file_data)
         ticket_view = self.new_ticket(summary='test move attachment').follow()
         self.app.post('/bugs/1/update_ticket',
@@ -1289,17 +1290,21 @@ class TestFunctionalController(TrackerTestController):
         r =self.app.get('/p/test/bugs/1/')
         post_link = str(r.html.find('div', {'class': 'edit_post_form reply'}).find('form')['action'])
         r = self.app.post(post_link + 'attach',
-                          upload_files=[('file_info', 'test.txt', 'This is a textfile')])
+                          upload_files=[('file_info', 'test.txt', 'test')])
         p = M.Project.query.get(shortname='test2')
         ac_id = p.app_instance('bugs2').config._id
         r = self.app.post('/p/test/bugs/1/move/',
                           params={'tracker': str(ac_id)}).follow()
 
         app_config_id = tm.Ticket.query.find().first().app_config_id
-        assert 'test_root.py' in r
+        assert 'neo-icon-set-454545-256x350.png' in r
         assert 'test.txt' in r
+        assert '/attachment/neo-icon-set-454545-256x350.png/thumb' in r
+
         for attach in M.BaseAttachment.query.find():
             assert attach.app_config_id == app_config_id
+            assert attach.url() in r
+
 
 
 class TestMilestoneAdmin(TrackerTestController):


Mime
View raw message