Ticket #7078: trac-0.11.0-get-attachments-as-zipfile.patch
| File trac-0.11.0-get-attachments-as-zipfile.patch, 2.9 KB (added by mark@…, 4 years ago) |
|---|
-
trac/attachment.py
22 22 import shutil 23 23 import time 24 24 import unicodedata 25 import zipfile 26 import tempfile 25 27 26 28 from genshi.builder import tag 27 29 … … 375 377 376 378 parent = parent_realm(id=parent_id) 377 379 380 if action == 'getzip': 381 self._do_getzip(req, parent) 382 return 'attachment.html', data, None 383 378 384 # Link the attachment page to parent resource 379 385 parent_name = get_resource_name(self.env, parent) 380 386 parent_url = get_resource_url(self.env, parent, req.href) … … 517 523 518 524 # Internal methods 519 525 526 def _do_getzip(self, req, parent): 527 db = self.env.get_db_cnx() 528 529 p_id = parent.id 530 p_type = parent.realm 531 532 zfname = 'Ticket%s.zip' % p_id 533 534 zfpath = os.path.join(tempfile.gettempdir(), zfname) 535 536 zf = zipfile.ZipFile(zfpath, 'w') 537 for attachment in Attachment.select(self.env, p_type, p_id, db): 538 # name = attachment.filename.encode('utf8') 539 name = attachment.filename.encode('cp437') 540 zf.write(attachment.path, name) 541 info = zf.getinfo(name) 542 # Set bit 11 indicate that filename and comment are in UTF-8, see http://www.pkware.com/documents/casestudies/APPNOTE.TXT 543 # info.flag_bits |= 1 << 11 544 zf.close() 545 546 req.send_header('Content-Disposition', 'attachment; filename=%s' % zfname) 547 mime_type = 'application/octet-stream' 548 549 req.send_file(zfpath, mime_type) 550 551 os.remove(zfpath) 552 520 553 def _do_save(self, req, attachment): 521 554 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 522 555 -
trac/templates/macros.html
208 208 - 'alist' is an AttachmentList object (see attachment.py) 209 209 --> 210 210 <py:def function="attach_file_form(alist)"> 211 < form py:if="alist.can_create" method="get" action="${alist.attach_href}" id="attachfile">212 <div>211 <div> 212 <form py:if="alist.can_create" method="get" action="${alist.attach_href}" id="attachfile" style="display:inline;"> 213 213 <input type="hidden" name="action" value="new" /> 214 214 <input type="submit" name="attachfilebutton" value="${_('Attach file')}" /> 215 </div>216 215 </form> 216 <form py:if="alist.attachments" method="get" action="${alist.attach_href}" id="getattachmentsaszip" style="display:inline;"> 217 <input type="hidden" name="action" value="getzip" /> 218 <input type="submit" name="getattachmentsaszipbutton" value="${_('Save all as ZIP-file')}" /> 219 </form> 220 </div> 217 221 </py:def> 218 222 219 223 <!--! Display a generic "progress bar", for use in roadmap and milestone.
