Exemple #1
0
    def render(self, request):
        """Don't actually render, but calls a process which returns a
        deferred.

        Callbacks on the deferred do the rendering, which is actually
        achieved through redirection.

        """
        #natasha convert
        # turn form into simple dictionary, dropping multiple values.  
        reqargs = request.args
        
        self.assignedstages = reqargs.get('assigned')
        form = dict([(k, v[0]) for k,v in request.args.iteritems()])
        # natasha: added prefix value
        prefix = ''
        try:
            self.mediatype = form.pop('type', None)
            if not self.mediatype in self.mediatypes:
                raise UpstageError('Not a real kind of thing: %s' % self.mediatype)
            self.media_dict = self.mediatypes[self.mediatype] #self.media_dict = self.collections
            #change to starswith 'avcontents'
            if self.mediatype == 'avatar':
                prefix = 'av'
                # self.media_dict = self.collection.avatars
            elif self.mediatype == 'prop':
                prefix = 'pr'
            elif self.mediatype == 'backdrop':
                prefix = 'bk'
            elif self.mediatype == 'audio': #remem audio not included as things
                prefix = 'au'
            #imgs = [ (k, v) for k, v in form.iteritems() if k.startswith('contents') and v ]
            contentname = prefix + 'contents'
            imgs = [ (k, v) for k, v in form.iteritems() if k.startswith(prefix + 'contents') and v ]
            imgs.sort()
 
            # save input files in /tmp, also save file names
            tfns = [ save_tempfile(x[1]) for x in imgs ]

            # Alan (12/09/07) ==> Gets the size of image files using the previously created temp filenames.
            #natasha getfilesize
            fileSizes = getFileSizes(tfns)
            
            # imported from misc.py
            swf = new_filename(suffix='.swf')
            thumbnail = swf.replace('.swf', '.jpg')
            swf_full = os.path.join(config.MEDIA_DIR, swf)
            thumbnail_full = os.path.join(config.THUMBNAILS_DIR, thumbnail)

        except UpstageError, e:            
            return errorpage(request, e, 500)
Exemple #2
0
    def render(self, request):
        """Don't actually render, but calls a process which returns a
        deferred.

        Callbacks on the deferred do the rendering, which is actually
        achieved through redirection.

        """
        # natasha convert
        # turn form into simple dictionary, dropping multiple values.  
        reqargs = request.args
        
        self.assignedstages = reqargs.get('assigned')
        form = dict([(k, v[0]) for k,v in request.args.iteritems()])
        
        # DEBUG: print form sent by request
        for key in form.iterkeys():
            if 'contents' in key:
                value = "[ binary data: %s Bytes ]" % len(form[key])
            else:
                value = form[key]
                if(len(value)>256):
                    value = value[:256] + " ... " # limit length to 256 chars
                value = "'" + value + "'"
            log.msg("SwfConversionWrapper render(): form: '%s' = %s" % (key, value))
        
        # FIXME: trim spaces from form values? (#104)
        
        # handle kind of images: upload or library:
        imagetype = form.get('imagetype','unknown')
        
        # handle upload imagetype
        if imagetype == 'upload':
            
            log.msg('SwfConversionWrapper: render(): imagetype UPLOAD')
            
            # natasha: added prefix value
            prefix = ''
            try:
                self.mediatype = form.pop('type', None)
                if not self.mediatype in self.mediatypes:
                    raise UpstageError('Not a real kind of thing: %s' % self.mediatype)
                self.media_dict = self.mediatypes[self.mediatype] #self.media_dict = self.collections
                # change to starswith 'avcontents'
                if self.mediatype == 'avatar':
                    prefix = 'av'
                    # self.media_dict = self.collection.avatars
                elif self.mediatype == 'prop':
                    prefix = 'pr'
                elif self.mediatype == 'backdrop':
                    prefix = 'bk'
                elif self.mediatype == 'audio': # remem audio not included as things
                    prefix = 'au'
                
                # imgs = [ (k, v) for k, v in form.iteritems() if k.startswith('contents') and v ]
                contentname = prefix + 'contents'
                imgs = [ (k, v) for k, v in form.iteritems() if k.startswith(contentname) and v ]
                imgs.sort()
                
                # DEBUG:
                #log.msg("SwfConversionWrapper: imgs = %s" % imgs);
     
                # save input files in /tmp, also save file names
                tfns = [ save_tempfile(x[1]) for x in imgs ]
    
                # Alan (12/09/07) ==> Gets the size of image files using the previously created temp filenames.
                # natasha getfilesize
                fileSizes = getFileSizes(tfns)
                
                swf = unique_custom_string(suffix='.swf')
                if form.get('mode', '') == 'replace':
                    oldfile = form.get('oldfile')
                    try:
                        self.media_dict.deleteFile(oldfile)
                    except KeyError:
                        log.msg('the file does not exist. nothing was deleted.')
                        request.write(errorpage(request, 'The file you want to replace does not exist. Accidentally pressed the back button? Tut, tut..', 'mediaedit'))
                        request.finish()

                thumbnail = swf.replace('.swf', '.jpg')         # FIXME: see #20 (Uploaded media is not converted to JPEG)
                swf_full = os.path.join(config.MEDIA_DIR, swf)
                thumbnail_full = os.path.join(config.THUMBNAILS_DIR, thumbnail)
    
            except UpstageError, e:            
                return errorpage(request, e, 'mediaupload')
    
            """ Alan (13/09/07) ==> Check the file sizes of avatar frame """
            # natasha continue conversion
            if not (fileSizes is None):
                if validSizes(fileSizes, self.player.can_upload_big_file()):
                    # call the process with swf filename and temp image filenames 
                    d = getProcessValue(config.IMG2SWF_SCRIPT, args=[swf_full, thumbnail_full] + tfns)
                    args = (swf, thumbnail, form, request)
                    d.addCallbacks(self.success_upload, self.failure_upload, args, {}, args, {})
                    d.addBoth(self.cleanup_upload, tfns)
                    d.setTimeout(config.MEDIA_TIMEOUT, timeoutFunc=d.errback)
                    d.addErrback(log.err)   # Make sure errors get logged - TODO is this working?
                else:
                    redirect = 'mediaupload'
                    if form.get('mode', '') == 'replace':
                        redirect = 'mediaedit'
                        self.media_dict.restoreOldFile(form.get('oldfile'))
                    ''' Send new avatar page back containing error message '''
                    self.player.set_setError(True)
                    self.cleanup_upload(None, tfns)
                    request.write(errorpage(request, 'You do not have the permission to upload a file over 1MB in size.', redirect))
                    # request.redirect('/admin/new/%s' %(self.mediatype))
                    request.finish()