Exemple #1
0
def delete_model(instance, db, table, imutable, soft_delete):
    modelname = str(instance._meta)
    if imutable == True:
        return
    filters = {"model": modelname, "pk": instance.pk}
    document_exists_in_db, document = document_exists(db, table, modelname,
                                                      instance.pk)
    if soft_delete is False:
        if document_exists_in_db:
            R.delete_filtered(db, table, filters)
    else:
        document["deleted"] = True
        R.update(db, table, document, filters)
    return
Exemple #2
0
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
Exemple #3
0
 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