• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

allura


Commit MetaInfo

Revisióne928c104fc7e74c5812b61030414a6248d9528c9 (tree)
Tiempo2012-05-17 23:22:03
AutorDave Brondsema <dbrondsema@geek...>
CommiterYaroslav Luzin

Log Message

show attachment details on its own line, more readable

Cambiar Resumen

Diferencia incremental

--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -589,3 +589,35 @@ def render_any_markup(name, text, code_mode=False, linenumbers_style=TABLE):
589589 else:
590590 text = '<pre>%s</pre>' % text
591591 return Markup(text)
592+
593+# copied from jinja2 dev
594+# latest release, 2.6, implements this incorrectly
595+# can remove and use jinja2 implementation after upgrading to 2.7
596+def do_filesizeformat(value, binary=False):
597+ """Format the value like a 'human-readable' file size (i.e. 13 kB,
598+4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,
599+Giga, etc.), if the second parameter is set to `True` the binary
600+prefixes are used (Mebi, Gibi).
601+"""
602+ bytes = float(value)
603+ base = binary and 1024 or 1000
604+ prefixes = [
605+ (binary and 'KiB' or 'kB'),
606+ (binary and 'MiB' or 'MB'),
607+ (binary and 'GiB' or 'GB'),
608+ (binary and 'TiB' or 'TB'),
609+ (binary and 'PiB' or 'PB'),
610+ (binary and 'EiB' or 'EB'),
611+ (binary and 'ZiB' or 'ZB'),
612+ (binary and 'YiB' or 'YB')
613+ ]
614+ if bytes == 1:
615+ return '1 Byte'
616+ elif bytes < base:
617+ return '%d Bytes' % bytes
618+ else:
619+ for i, prefix in enumerate(prefixes):
620+ unit = base ** (i + 2)
621+ if bytes < unit:
622+ return '%.1f %s' % ((base * bytes / unit), prefix)
623+ return '%.1f %s' % ((base * bytes / unit), prefix)
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -121,7 +121,7 @@ class Notification(MappedClass):
121121 file_info.file.seek(0, 2)
122122 bytecount = file_info.file.tell()
123123 file_info.file.seek(0)
124- text = "%s\n%s (%s bytes in %s)" % (text, file_info.filename, bytecount, file_info.type)
124+ text = "%s\n\n\nAttachment: %s (%s; %s)" % (text, file_info.filename, h.do_filesizeformat(bytecount), file_info.type)
125125
126126 subject = post.subject or ''
127127 if post.parent_id and not subject.lower().startswith('re:'):
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -167,7 +167,7 @@ def test_attachment_methods():
167167 p = t.post(text=u'test message', forum= None, subject= '', file_info=fs)
168168 ThreadLocalORMSession.flush_all()
169169 n = M.Notification.query.get(subject=u'[test:wiki] Test comment notification')
170- assert u'test message\nfake.txt (37 bytes in text/plain)'==n.text
170+ assert_equals(u'test message\n\n\nAttachment: fake.txt (37 Bytes; text/plain)', n.text)
171171
172172 @with_setup(setUp, tearDown)
173173 def test_discussion_delete():