Skip to content

Commit

Permalink
Give the preview_url method of the tempstore access to the stored item.
Browse files Browse the repository at this point in the history
This allows implementations of that method to base the URL generation on
the actual data, i.e. generate different previews depending on the file
type etc.
  • Loading branch information
tomster committed Jun 18, 2012
1 parent 3979b35 commit aed3f21
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes
Next release
------------

- Give the preview_url method of the tempstore access to the stored item. [tomster]
- Fixed remove bug in nested sequences. See
https://github.com/Pylons/deform/pull/89

Expand Down
8 changes: 4 additions & 4 deletions deform/tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def test_deserialize_file_selected_no_previous_file(self):
self.assertEqual(result['filename'], 'filename')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
self.assertEqual(result['preview_url'], 'preview_url')
self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore[uid], result)

def test_deserialize_file_selected_with_previous_file(self):
Expand All @@ -1033,7 +1033,7 @@ def test_deserialize_file_selected_with_previous_file(self):
self.assertEqual(result['filename'], 'filename')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
self.assertEqual(result['preview_url'], 'preview_url')
self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore['uid'], result)

def test_deserialize_file_selected_with_previous_file_IE_whole_path(self):
Expand All @@ -1049,7 +1049,7 @@ def test_deserialize_file_selected_with_previous_file_IE_whole_path(self):
self.assertEqual(result['filename'], 'baz.pt')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
self.assertEqual(result['preview_url'], 'preview_url')
self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore['uid'], result)

class TestDatePartsWidget(unittest.TestCase):
Expand Down Expand Up @@ -1855,7 +1855,7 @@ def translate(self, term):

class DummyTmpStore(dict):
def preview_url(self, uid):
return 'preview_url'
return 'http://localhost/%s' % self[uid]['filename']

class DummyUpload(object):
file = 'fp'
Expand Down
4 changes: 2 additions & 2 deletions deform/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,14 +1275,14 @@ def deserialize(self, field, pstruct):
uid = self.random_id()
if self.tmpstore.get(uid) is None:
data['uid'] = uid
data['preview_url'] = self.tmpstore.preview_url(uid)
self.tmpstore[uid] = data
self.tmpstore[uid]['preview_url'] = self.tmpstore.preview_url(uid)
break
else:
# a previous file exists
data['uid'] = uid
data['preview_url'] = self.tmpstore.preview_url(uid)
self.tmpstore[uid] = data
self.tmpstore[uid]['preview_url'] = self.tmpstore.preview_url(uid)
else:
# the upload control had no file selected
if uid is None:
Expand Down

0 comments on commit aed3f21

Please sign in to comment.