comparison MoinMoin/action/AttachFile.py @ 1868:64507f46beb2

reduce usage of has_key()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 10 Mar 2007 22:01:07 +0100
parents 0194beaf511e
children 76040d9ab344
comparison
equal deleted inserted replaced
1867:8166b37db555 1868:64507f46beb2
175 175
176 # set mimetype from extension, or from given mimetype 176 # set mimetype from extension, or from given mimetype
177 #type, encoding = wikiutil.guess_type(target) 177 #type, encoding = wikiutil.guess_type(target)
178 #if not type: 178 #if not type:
179 # ext = None 179 # ext = None
180 # if request.form.has_key('mime'): 180 # if 'mime' in request.form:
181 # ext = wikiutil.guess_extension(request.form['mime'][0]) 181 # ext = wikiutil.guess_extension(request.form['mime'][0])
182 # if not ext: 182 # if not ext:
183 # type, encoding = wikiutil.guess_type(filename) 183 # type, encoding = wikiutil.guess_type(filename)
184 # if type: 184 # if type:
185 # ext = wikiutil.guess_extension(type) 185 # ext = wikiutil.guess_extension(type)
527 _ = request.getText 527 _ = request.getText
528 528
529 msg = None 529 msg = None
530 if action_name in request.cfg.actions_excluded: 530 if action_name in request.cfg.actions_excluded:
531 msg = _('File attachments are not allowed in this wiki!') 531 msg = _('File attachments are not allowed in this wiki!')
532 elif not request.form.has_key('do'): 532 elif 'do' not in request.form:
533 upload_form(pagename, request) 533 upload_form(pagename, request)
534 elif request.form['do'][0] == 'savedrawing': 534 elif request.form['do'][0] == 'savedrawing':
535 if request.user.may.write(pagename): 535 if request.user.may.write(pagename):
536 save_drawing(pagename, request) 536 save_drawing(pagename, request)
537 request.emit_http_headers() 537 request.emit_http_headers()
538 request.write("OK") 538 request.write("OK")
539 else: 539 else:
540 msg = _('You are not allowed to save a drawing on this page.') 540 msg = _('You are not allowed to save a drawing on this page.')
541 elif request.form['do'][0] == 'upload': 541 elif request.form['do'][0] == 'upload':
542 if request.user.may.write(pagename): 542 if request.user.may.write(pagename):
543 if request.form.has_key('file'): 543 if 'file' in request.form:
544 do_upload(pagename, request) 544 do_upload(pagename, request)
545 else: 545 else:
546 # This might happen when trying to upload file names 546 # This might happen when trying to upload file names
547 # with non-ascii characters on Safari. 547 # with non-ascii characters on Safari.
548 msg = _("No file content. Delete non ASCII characters from the file name and try again.") 548 msg = _("No file content. Delete non ASCII characters from the file name and try again.")
557 if request.user.may.delete(pagename): 557 if request.user.may.delete(pagename):
558 send_moveform(pagename, request) 558 send_moveform(pagename, request)
559 else: 559 else:
560 msg = _('You are not allowed to move attachments from this page.') 560 msg = _('You are not allowed to move attachments from this page.')
561 elif request.form['do'][0] == 'attachment_move': 561 elif request.form['do'][0] == 'attachment_move':
562 if request.form.has_key('cancel'): 562 if 'cancel' in request.form:
563 msg = _('Move aborted!') 563 msg = _('Move aborted!')
564 error_msg(pagename, request, msg) 564 error_msg(pagename, request, msg)
565 return 565 return
566 if not wikiutil.checkTicket(request, request.form['ticket'][0]): 566 if not wikiutil.checkTicket(request, request.form['ticket'][0]):
567 msg = _('Please use the interactive user interface to move attachments!') 567 msg = _('Please use the interactive user interface to move attachments!')
613 def do_upload(pagename, request): 613 def do_upload(pagename, request):
614 _ = request.getText 614 _ = request.getText
615 615
616 # make filename 616 # make filename
617 filename = None 617 filename = None
618 if request.form.has_key('file__filename__'): 618 if 'file__filename__' in request.form:
619 filename = request.form['file__filename__'] 619 filename = request.form['file__filename__']
620 rename = None 620 rename = None
621 if request.form.has_key('rename'): 621 if 'rename' in request.form:
622 rename = request.form['rename'][0].strip() 622 rename = request.form['rename'][0].strip()
623 overwrite = 0 623 overwrite = 0
624 if request.form.has_key('overwrite'): 624 if 'overwrite' in request.form:
625 try: 625 try:
626 overwrite = int(request.form['overwrite'][0]) 626 overwrite = int(request.form['overwrite'][0])
627 except: 627 except:
628 pass 628 pass
629 629
742 upload_form(pagename, request, msg=_("Page %(newpagename)s does not exists or you don't have enough rights.") % { 742 upload_form(pagename, request, msg=_("Page %(newpagename)s does not exists or you don't have enough rights.") % {
743 'newpagename': new_pagename}) 743 'newpagename': new_pagename})
744 744
745 def attachment_move(pagename, request): 745 def attachment_move(pagename, request):
746 _ = request.getText 746 _ = request.getText
747 if request.form.has_key('newpagename'): 747 if 'newpagename' in request.form:
748 new_pagename = request.form.get('newpagename')[0] 748 new_pagename = request.form.get('newpagename')[0]
749 else: 749 else:
750 upload_form(pagename, request, msg=_("Move aborted because empty page name")) 750 upload_form(pagename, request, msg=_("Move aborted because empty page name"))
751 if request.form.has_key('newattachmentname'): 751 if 'newattachmentname' in request.form:
752 new_attachment = request.form.get('newattachmentname')[0] 752 new_attachment = request.form.get('newattachmentname')[0]
753 if new_attachment != wikiutil.taintfilename(new_attachment): 753 if new_attachment != wikiutil.taintfilename(new_attachment):
754 upload_form(pagename, request, msg=_("Please use a valid filename for attachment '%(filename)s'.") % { 754 upload_form(pagename, request, msg=_("Please use a valid filename for attachment '%(filename)s'.") % {
755 'filename': new_attachment}) 755 'filename': new_attachment})
756 return 756 return