def document_exists(db, table, modelname, pk): q = r.db(db).table(table).filter({ "pk": pk, "model": modelname }).order_by("timestamp").pluck("pk", "model") existing_documents = R.run_query(q) json_document_exists = False if len(existing_documents) > 0: json_document_exists = True return json_document_exists, existing_documents[0] return json_document_exists, None
def document_exists(self): domain = self.server.domain q = r.db(self.server.domain).table("pages").get_all( [self.url, domain], index="uri").count() #existing_documents = order_documents(R.run_query(q)) #print modelname+" | "+str(pk)+" _> "+str(existing_documents) existing_documents = R.run_query(q) json_document_exists = False if existing_documents > 0: json_document_exists = True return json_document_exists
def dispatch(self, request, *args, **kwargs): if self.request.user.is_superuser is False or not self.request.method == "POST": raise Http404 q = json.loads(self.request.POST['q']) self.time = None if "$delete" in q: self.results = R.delete(q['$db'], q["$table"], q["$delete"]) else: if not '$table' in q: query = r.db(q['$db']).table_list() self.results = R.run_query(query) else: self.results, profile = R.run_json(q, profile=True) self.time = profile[0]['duration(ms)'] if isinstance(self.results, r.Cursor): self.results = list(self.results) return super(RpostView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs): context = super(RView, self).get_context_data(**kwargs) if self.request.user.is_superuser is False: raise Http404 context['dbs'] = R.run_query(r.db_list()) return context