parameters: (request, bookid, version=None)
docstring: Uploades attachments. Used from Upload dialog.
  
      @param request: Django Request
      @param bookid: Book ID
      @param version: Book version or None
docstring_summary: Uploades attachments. Used from Upload dialog.
docstring_tokens: Uploades attachments . Used from Upload dialog .
function: def upload_attachment(request, bookid, version=None):
      """
      Uploades attachments. Used from Upload dialog.
  
      @param request: Django Request
      @param bookid: Book ID
      @param version: Book version or None
      """
  
      import datetime
  
      try:
          book = models.Book.objects.get(url_title__iexact=bookid)
      except models.Book.DoesNotExist:
          return views.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid})
  
      book_version = book.getVersion(version)
  
      stat = models.BookStatus.objects.filter(book = book)[0]
  
      operationResult = True
  
      # check this for transactions
      try:
          for name, fileData in request.FILES.items():
  
              from booki.utils import log
  
              log.logBookHistory(book = book,
                                 version = book_version,
                                 args = {'filename': request.FILES[name].name},
                                 user = request.user,
                                 kind = 'attachment_upload'
                                 )
  
              att = models.Attachment(version = book_version,
                                      # must remove this reference
                                      created = datetime.datetime.now(),
                                      book = book,
                                      status = stat)
              att.save()
  
              att.attachment.save(request.FILES[name].name, fileData, save = False)
              att.save()
  
          # TODO:
          # must write info about this to log!
      except IOError:
          operationResult = False
      except:
          oprerationResult = False
  
      if request.POST.get("attachmenttab", "") == "":
          return HttpResponse('<html><body><script> parent.closeAttachmentUpload();  </script></body></html>')
  
      if request.POST.get("attachmenttab", "") == "2":
          return HttpResponse('<html><body><script>  parent.FileBrowserDialogue.loadAttachments(); parent.FileBrowserDialogue.displayBrowseTab();  parent.FileBrowserDialogue.showUpload(); </script></body></html>')
  
      # should not call showAttachmentsTab, but it works for now
      if operationResult:
          return HttpResponse('<html><body><script> parent.jQuery.booki.editor.showAttachmentsTab(); parent.jQuery("#tabattachments FORM")[0].reset(); </script></body></html>')
      else:
          return HttpResponse('<html><body><script> parent.jQuery.booki.editor.showAttachmentsTab(); parent.jQuery("#tabattachments FORM")[0].reset(); alert(parent.jQuery.booki._("errorupload", "Error while uploading file!"));</script></body></html>')
function_tokens: def upload_attachment ( request , bookid , version = None ) : import datetime try : book = models . Book . objects . get ( url_title__iexact = bookid ) except models . Book . DoesNotExist : return views . ErrorPage ( request , "errors/book_does_not_exist.html" , { "book_name" : bookid } ) book_version = book . getVersion ( version ) stat = models . BookStatus . objects . filter ( book = book ) [ 0 ] operationResult = True # check this for transactions try : for name , fileData in request . FILES . items ( ) : from booki . utils import log log . logBookHistory ( book = book , version = book_version , args = { 'filename' : request . FILES [ name ] . name } , user = request . user , kind = 'attachment_upload' ) att = models . Attachment ( version = book_version , # must remove this reference created = datetime . datetime . now ( ) , book = book , status = stat ) att . save ( ) att . attachment . save ( request . FILES [ name ] . name , fileData , save = False ) att . save ( ) # TODO: # must write info about this to log! except IOError : operationResult = False except : oprerationResult = False if request . POST . get ( "attachmenttab" , "" ) == "" : return HttpResponse ( '<html><body><script> parent.closeAttachmentUpload();  </script></body></html>' ) if request . POST . get ( "attachmenttab" , "" ) == "2" : return HttpResponse ( '<html><body><script>  parent.FileBrowserDialogue.loadAttachments(); parent.FileBrowserDialogue.displayBrowseTab();  parent.FileBrowserDialogue.showUpload(); </script></body></html>' ) # should not call showAttachmentsTab, but it works for now if operationResult : return HttpResponse ( '<html><body><script> parent.jQuery.booki.editor.showAttachmentsTab(); parent.jQuery("#tabattachments FORM")[0].reset(); </script></body></html>' ) else : return HttpResponse ( '<html><body><script> parent.jQuery.booki.editor.showAttachmentsTab(); parent.jQuery("#tabattachments FORM")[0].reset(); alert(parent.jQuery.booki._("errorupload", "Error while uploading file!"));</script></body></html>' )