Exemplo n.º 1
0
 def ajax_upload(self, request, folder_id=None):
     """
     receives an upload from the flash uploader and fixes the session
     because of the missing cookie. Receives only one file at the time, 
     althow it may be a zip file, that will be unpacked.
     """
     try:
         # flashcookie-hack (flash does not submit the cookie, so we send the
         # django sessionid over regular post
         engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
         session_key = request.POST.get('jsessionid')
         request.session = engine.SessionStore(session_key)
         request.user = User.objects.get(
             id=request.session['_auth_user_id'])
         # upload and save the file
         if not request.method == 'POST':
             return HttpResponse("must be POST")
         original_filename = request.POST.get('Filename')
         file = request.FILES.get('Filedata')
         # Get clipboad
         clipboard, was_clipboard_created = Clipboard.objects.get_or_create(
             user=request.user)
         files = generic_handle_file(file, original_filename)
         file_items = []
         for ifile, iname in files:
             try:
                 iext = os.path.splitext(iname)[1].lower()
             except:
                 iext = ''
             if iext in ['.jpg', '.jpeg', '.png', '.gif']:
                 uploadform = UploadImageFileForm(
                     {
                         'original_filename': iname,
                         'owner': request.user.pk
                     }, {'file': ifile})
             else:
                 uploadform = UploadFileForm(
                     {
                         'original_filename': iname,
                         'owner': request.user.pk
                     }, {'file': ifile})
             if uploadform.is_valid():
                 try:
                     file = uploadform.save(commit=False)
                     # Enforce the FILER_IS_PUBLIC_DEFAULT
                     file.is_public = filer_settings.FILER_IS_PUBLIC_DEFAULT
                     file.save()
                     file_items.append(file)
                     clipboard_item = ClipboardItem(clipboard=clipboard,
                                                    file=file)
                     clipboard_item.save()
                 except Exception, e:
                     #print e
                     pass
             else:
                 pass  #print uploadform.errors
     except Exception, e:
         #print e
         pass
Exemplo n.º 2
0
    def ajax_upload(self, request, folder_id=None):
        """
        receives an upload from the flash uploader and fixes the session
        because of the missing cookie. Receives only one file at the time,
        althow it may be a zip file, that will be unpacked.
        """
        file_items = []

        try:
            # flashcookie-hack (flash does not submit the cookie, so we send the
            # django sessionid over regular post
            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
            session_key = request.POST.get('jsessionid')
            request.session = engine.SessionStore(session_key)
            request.user = User.objects.get(id=request.session['_auth_user_id'])
            # upload and save the file
            if not request.method == 'POST':
                return HttpResponse("must be POST")
            original_filename = request.POST.get('Filename')
            file = request.FILES.get('Filedata')
            # Get clipboad
            clipboard, was_clipboard_created = Clipboard.objects.get_or_create(user=request.user)
            files = generic_handle_file(file, original_filename)
            for ifile, iname in files:
                try:
                    iext = os.path.splitext(iname)[1].lower()
                except:
                    iext = ''
                if iext in ['.jpg', '.jpeg', '.png', '.gif']:
                    uploadform = UploadImageFileForm({'original_filename':iname,
                                                      'owner': request.user.pk},
                                                    {'file':ifile})
                else:
                    uploadform = UploadFileForm({'original_filename':iname,
                                                 'owner': request.user.pk},
                                                {'file':ifile})
                if uploadform.is_valid():
                    try:
                        file = uploadform.save(commit=False)
                        # Enforce the FILER_IS_PUBLIC_DEFAULT
                        file.is_public = filer_settings.FILER_IS_PUBLIC_DEFAULT
                        file.save()
                        file_items.append(file)
                        clipboard_item = ClipboardItem(clipboard=clipboard, file=file)
                        clipboard_item.save()
                    except Exception:
                        logger.exception("Failed to save clipboard item.")
                else:
                    logger.warn("Upload form not valid. The errors are: %s", uploadform.errors)
        except Exception:
            logger.exception("Failed to process upload:")

        return render_to_response('admin/filer/tools/clipboard/clipboard_item_rows.html',
                                  {'items': file_items },
                                  context_instance=RequestContext(request))
Exemplo n.º 3
0
 def ajax_upload(self, request, folder_id=None):
     """
     receives an upload from the flash uploader and fixes the session
     because of the missing cookie. Receives only one file at the time, 
     althow it may be a zip file, that will be unpacked.
     """
     try:
         #print request.POST
         # flashcookie-hack (flash does not submit the cookie, so we send the
         # django sessionid over regular post
         #print "ajax upload view"
         engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
         #print "imported session store"
         #session_key = request.POST.get('jsessionid')
         session_key = request.POST.get('jsessionid')
         #print "session_key: %s" % session_key
         request.session = engine.SessionStore(session_key)
         #print "got session object"
         request.user = User.objects.get(id=request.session['_auth_user_id'])
         #print "got user"
         #print request.session['_auth_user_id']
         #print session_key
         #print engine
         #print request.user
         #print request.session
         # upload and save the file
         if not request.method == 'POST':
             return HttpResponse("must be POST")
         original_filename = request.POST.get('Filename')
         file = request.FILES.get('Filedata')
         #print request.FILES
         #print original_filename, file
         #print "get clipboad"
         clipboard, was_clipboard_created = Clipboard.objects.get_or_create(user=request.user)
         #print "handle files"
         files = generic_handle_file(file, original_filename)
         file_items = []
         #print "loop files"
         for ifile, iname in files:
             try:
                 iext = os.path.splitext(iname)[1].lower()
             except:
                 iext = ''
             #print "inaem: %s iext: %s" % (iname, iext)
             #print "extension: ", iext
             if iext in ['.jpg','.jpeg','.png','.gif']:
                 uploadform = UploadImageFileForm({'original_filename':iname,'owner': request.user.pk}, {'_file':ifile})
             else:
                 uploadform = UploadFileForm({'original_filename':iname,'owner': request.user.pk}, {'_file':ifile})
             if uploadform.is_valid():
                 #print 'uploadform is valid'
                 try:
                     file = uploadform.save(commit=False)
                     file.save()
                     file_items.append(file)
                     bi = ClipboardItem(clipboard=clipboard, file=file)
                     bi.save()
                 except Exception, e:
                     #print "some exception"
                     #print e
                     pass
                 #print "save %s" % image
                 #sprint image
             else:
                 pass#print uploadform.errors
             #print "what up?"
     except Exception, e:
         #print e
         pass