def mirror_model(instance, data, db, table, created, imutable, verbose=False): res = {"created": 0, "updated": 0} modelname = str(instance._meta) # record data if created is True: res["status"] = R.write(db, table, data) res["created"] += 1 if verbose is True: print("[ " + modelname + " ] Document " + str(instance.pk) + " created in table " + table) else: optype = "write" if imutable is False: document_exists_in_db, document = document_exists( db, table, modelname, instance.pk) if document_exists_in_db: optype = "update" if optype == "update": res["status"] = R.update(db, table, data, {}) res["updated"] += 1 if verbose is True: print("[ " + modelname + " ] Document " + str(instance.pk) + " updated in table " + table) return res res["status"] = R.write(db, table, data) res["created"] += 1 if verbose is True: print("[ " + modelname + " ] Document " + str(instance.pk) + " created in table " + table) return res
def save(self, *args, **kwargs): super(SiteTemplate, self).save(*args, **kwargs) # save template to Microb server filepath = settings.BASE_DIR + "/microb/servers/" + self.server.domain + "/templates/view.html" #~ write the file filex = open(filepath, "w") filex.write(self.content.encode('utf-8')) filex.close() # send command to the Microb server to reparse the templates data = {"Name": "reparse_templates", "Reason": "Template edit"} R.write(self.server.domain, "commands", data) return
def mirror(self, data): #print 'Exists: '+str(self.document_exists()) if self.document_exists() is True: filters = (r.row['domain'] == self.server.domain) & (r.row['uri'] == self.url) res = R.update(self.server.domain, "pages", data, filters) else: res = R.write(self.server.domain, "pages", data) return res