Пример #1
0
    def testArchiveConferenceFile(self):
        """Makes sure a file wich is attached to a conference gets stored in
            the right path: basePath/year/C0/0/test.txt
        """

        with self._context('database'):
            #first we create a dummy user which will be the conf creator
            from MaKaC.user import Avatar
            av = Avatar()
            #Now we create a dummy conference and set its id to 0
            from MaKaC.conference import Conference
            c = Conference(av)
            c.setId("0")
            #Now we create the material (id=0) and attach it to the conference
            from MaKaC.conference import Material
            m = Material()
            c.addMaterial(m)
            #Now we create a dummy file and attach it to the material
            filePath = os.path.join(os.getcwd(), "test.txt")
            fh = open(filePath, "w")
            fh.write("hola")
            fh.close()
            from MaKaC.conference import LocalFile
            f = LocalFile()
            f.setFilePath(filePath)
            f.setFileName("test.txt")
            m.addResource(f)
Пример #2
0
 def testArchiveConferenceFile( self ):
     """Makes sure a file wich is attached to a conference gets stored in
         the right path: basePath/year/C0/0/test.txt
     """
     #first we create a dummy user which will be the conf creator
     from MaKaC.user import Avatar
     av = Avatar()
     #Now we create a dummy conference and set its id to 0
     from MaKaC.conference import Conference
     c = Conference( av )
     c.setId( "0" )
     #Now we create the material (id=0) and attach it to the conference
     from MaKaC.conference import Material
     m = Material()
     c.addMaterial( m )
     #Now we create a dummy file and attach it to the material
     filePath = os.path.join( os.getcwd(), "test.txt" )
     fh = open(filePath, "w")
     fh.write("hola")
     fh.close()
     from MaKaC.conference import LocalFile
     f = LocalFile()
     f.setFilePath( filePath )
     f.setFileName( "test.txt" )
     m.addResource( f )
Пример #3
0
    def _process(self, rh, params):
        
        # We will need to pickle the data back into JSON
        from MaKaC.common.PickleJar import DictPickler
        
        errorList=[]
        user = rh.getAW().getUser()
        try:
            owner = self._target
            title = owner.getTitle()
            if type(owner) == Conference:
                ownerType = "event"
            elif type(owner) == Session:
                ownerType = "session"
            elif type(owner) == Contribution:
                ownerType = "contribution"
            elif type(owner) == SubContribution:
                ownerType = "subcontribution"
            else:
                ownerType = ""
            text = " in %s %s" % (ownerType,title)
        except:
            owner = None
            text = ""

        errorList=self._getErrorList()
        file = self._file
        link = self._link        
        resource = None
        
        if self._uploadType == "file":
            if len(errorList)==0:
                mat = self._getMaterial()
                
                if mat == None:
                    errorList.append("Unknown material");
                else:
                    resource = LocalFile()
                    resource.setFileName(file["fileName"])
                    resource.setName(resource.getFileName())
                    resource.setFilePath(file["filePath"])
                    resource.setDescription(self._description)
                    mat.addResource(resource)
                    #apply conversion
                    if self._topdf and fileConverter.CDSConvFileConverter.hasAvailableConversionsFor(os.path.splitext(resource.getFileName())[1].strip().lower()):
                        fileConverter.CDSConvFileConverter.convert(resource.getFilePath(), "pdf", mat)
                    if not type(self._target) is Category:
                        self._target.getConference().getLogHandler().logAction({"subject":"Added file %s%s" % (file["fileName"],text)},"Files",user)
                    # in case of db conflict we do not want to send the file to conversion again
                    self._topdf = False
    
            if len(errorList) > 0:
                status = "ERROR"
                info = errorList
            else:
                status = "OK"
                info = DictPickler.pickle(resource)
                info['material'] = mat.getId();
        
        elif self._uploadType == "link":
            if len(errorList)==0:
                mat = self._getMaterial()
                if mat == None:
                    mat = Material()
                    mat.setTitle(link["matType"])
                    self._target.addMaterial( mat )
                resource = Link()
                resource.setURL(link["url"])
                resource.setName(resource.getURL())
                resource.setDescription(self._description)
                mat.addResource(resource)
                if not type(self._target) is Category:
                    self._target.getConference().getLogHandler().logAction({"subject":"Added link %s%s" % (resource.getURL(),text)},"Files",user)
            
                status = "OK"
                info = DictPickler.pickle(resource)
                info['material'] = mat.getId();
            else:
                status = "ERROR"
                info = errorList
        
        else:
            status = "ERROR"
            info = "Unknown upload type"
          
        # hackish, because of mime types. Konqueror, for instance, would assume text if there were no tags,
        # and would try to open it
        from MaKaC.services.interface.rpc import json
        return "<html><head></head><body>"+json.encode({'status': status, 'info': info})+"</body></html>"