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>"