def addTemplateset(self,name,version): ''' add a (already downloaded) template set to the database. @param name: the Templateset name @type name: String @param version: the Templateset version @type version: String ''' if self.hasTemplateset(name,version) == False: print "DOESNT HAVE TEMPLATESET" configf = open(settings.TEMPLATESETS_PATH+name+'/'+version+'/config.json') config = simplejson.load(configf) tsid = self.db.templateset.insert(name=name,version=version) for each in config['files']: efile = open(settings.TEMPLATESETS_PATH+name+'/'+version+'/templates/'+each['name'],'r') print name+'/'+each['name'] template = simplejson.load(efile) if self.hasTemplate(name,each['name'],version) == False: tid = self.db.template.insert(name=each['name'],templateset=tsid) self.db.template_response.insert(template=0,responsetemplate=tid,templateset=tsid) if each.__contains__('responses'): for res in each['responses']: print name+'/'+res['name'] resid = self.hasTemplate(name,res['name'],version) if resid == False: resid = self.db.template.insert(name=res['name'],templateset=tsid,towho=res['to'],use=res['use']) self.db.template_response.insert(template=tid,templateset=tsid,responsetemplate=resid) #except IOError: # raise IOError, "Config file not found" self.db.commit()
def validateTemplateset(self,templatesetdir): ''' validate ALL files of a template set: config.json & all templates @param templatesetdir: name of the templateset directory containing config.json file for the templateset @type templatesetdir: string ''' configschemafile = open(settings.CONFIG_SCHEMA_PATH,'r') configschema = simplejson.load(configschemafile) try: configfile = open(settings.TEMPLATESETS_PATH+templatesetdir+'/config.json','r') except IOError: raise IOError,"Templateset directory has no config.json." try: configdata = simplejson.load(configfile) except JSONDecodeError, e: print "config.json JSON Decoding error: ",e raise TemplatesetError("simplejson.load( config.json ) raised JSONDecodeError")
def readTemplate(self,setname,name,version=None): ''' read a template and return it in data form ''' if version is None: version = self.getNewestTemplatesetVersion(setname) tfile = open(settings.TEMPLATESETS_PATH+setname+'/'+str(version)+'/templates/'+name) #try: tdata = simplejson.load(tfile,object_pairs_hook=ordereddict.OrderedDict) print "TEMPLATE READ",tdata return tdata #except: print "Template file "+settings.TEMPLATESETS_PATH+setname+'/'+str(version)+'/templates/'+name+' is not properly formed JSON' return None
def validateTemplate(self,templatepath): ''' validate a single template @returns: tuple of setname/name,version @param templatepath: path to the template @type templatepath: string ''' # Open & Load template-schema file templateschemafile = open(settings.TEMPLATE_SCHEMA_PATH,'r') templateschema = simplejson.load(templateschemafile) # Open & load template file try: templatefile = open(templatepath,'r') except IOError, e: raise IOError, e
def getEvmailTemplate(self, setname, name, version): """ Get schema data of particular template file within a particular template set. @param setname: Name of the templateset @type setname: string @param name: Name of the template @type name: string @param version: Version of the templateset @type version: string @returns: dict with template schema data """ try: templatefile = open(settings.TEMPLATESETS_PATH + setname + "/" + version + "/templates/" + name, "r") except IOError: raise IOError, "Template not found (" + tspath + "templates/" + name + ")" try: templatedata = simplejson.load(templatefile) except JSONDecodeError, e: raise EvmailError("simplejson.load( " + tspath + "templates/" + name + " ) raised JSONDecodeError")
@returns: tuple of setname/name,version @param templatepath: path to the template @type templatepath: string ''' # Open & Load template-schema file templateschemafile = open(settings.TEMPLATE_SCHEMA_PATH,'r') templateschema = simplejson.load(templateschemafile) # Open & load template file try: templatefile = open(templatepath,'r') except IOError, e: raise IOError, e try: templatedata = simplejson.load(templatefile) except simplejson.JSONDecodeError, e: raise simplejson.JSONDecodeError, e # Validate template file try: validictory.validate(templatedata,templateschema) except SchemaError, error: raise SchemaError, error tname = str(templatedata['setname'])+"/"+str(templatedata['name']) return tname,templatedata['version'] def generateFormView(self,panel,template,responseid=None,responsedata=None): ''' Read template and generate a form view from it