def saveResaddr(self, vurl, vlevel, vuid='', vtitle=''): doc = Documents.objects.filter(url=vurl) if (len(doc) == 0): doc = Documents(url=vurl, uid=vuid, title=vtitle, level=vlevel) doc.save() #print 'create\n' else: if vuid != '': doc[0].uid = vuid doc[0].title = vtitle # doc.update() doc[0].save() doc = doc[0] #print 'update\n' return doc.id
def saveResaddr(self, vurl, vlevel, vuid="", vtitle=""): doc = Documents.objects.filter(url=vurl) if len(doc) == 0: doc = Documents(url=vurl, uid=vuid, title=vtitle, level=vlevel) doc.save() # print 'create\n' else: if vuid != "": doc[0].uid = vuid doc[0].title = vtitle # doc.update() doc[0].save() doc = doc[0] # print 'update\n' return doc.id
def main(): engine = create_engine(DB_CONNECTION) Session = sessionmaker(bind=engine) session = Session() for filename in os.listdir(RAW_DATA): print('Opening document: {}'.format(filename)) path = os.path.join(RAW_DATA, filename) doc = Document(path) # create an instance (database row) for a annual report document = Documents( path=doc.path , document_text=doc.text , table_text=doc.table_text , last_modified_by=doc.last_modified_by , author=doc.author , created=doc.created , last_printed=doc.last_printed , revision=doc.revision , num_tables=doc.num_tables ) session.add(document) for section_name, section_text in doc.sections.items(): section = Sections( document_name=doc.path , section_name=section_name , section_text=section_text ) session.add(section) session.commit()
def save(self): try: urlRecord = Documents.objects.filter( url=self.url) #self.documents.url) if urlRecord.count() == 0: Documents(url=self.url).save() print 'documents is added' return self.getIdByURL(self.url) except Documents.DoesNotExist: print 'does not exist' print 'documents already exist'
def entities(index, doc_id): response = {"success": False} doc = (Documents.objects.filter( getattr(Documents, index) == doc_id).first()) if doc is None: new = {'id': uuid.uuid4(), index: doc_id} doc = Documents.create(**new) if request.method == 'GET': if doc is not None: ne = doc.entities response["entities"] = ne response["success"] = True return jsonify(response) if request.method == 'POST': r = request.get_json() ne = json.loads(r.get('entities', [])) update = {'entities': ne} doc.update(**update) response["success"] = True return jsonify(response)
def add_doc(user, data): return Documents().add_doc(user, data)
def documents(cases_rol_rit_ruc): if request.method == 'GET': list = [] if cases_rol_rit_ruc == "17.402.744-7" or cases_rol_rit_ruc == "20.968.696-1": resp = db.session.query(Documents).all( ) #DEPURAR ESTO, TOMAR RESP Y QUE EL MODEL ARROJE UN OBJ DE TODOS LOS CAMPOS for item in resp: list.append({ "documents_type": item.documents_type, "documents_date": item.documents_date, "documents_cases_id": item.documents_cases_id }) return jsonify({"resp": list}), 200 else: if "-" in cases_rol_rit_ruc or "°" in cases_rol_rit_ruc: resp = db.session.query(Cases).filter_by( cases_rol_rit_ruc=cases_rol_rit_ruc).first() cases_id = resp.cases_id documents = db.session.query(Documents).filter_by( documents_cases_id=cases_id).all() for item in documents: list.append({ "documents_type": item.documents_type, "documents_date": item.documents_date, "documents_id": item.documents_id }) if "-" not in cases_rol_rit_ruc and "°" not in cases_rol_rit_ruc: documents = db.session.query(Documents).filter_by( documents_cases_id=cases_rol_rit_ruc).all() for item in documents: list.append({ "documents_type": item.documents_type, "documents_date": item.documents_date, "documents_id": item.documents_id }) return jsonify({"resp": list}) if request.method == 'POST': incomingDataJSON = request.get_json() insertedData = Documents( documents_type=str(incomingDataJSON['documents_type']), documents_cases_id=incomingDataJSON['documents_cases_id']) db.session.add(insertedData) lastId = db.session.query(Documents).order_by( Documents.documents_id.desc()).limit(1) list = [] for item in lastId: print(item.documents_id) list.append(item.documents_id) db.session.commit() return jsonify({"resp": list[0]}), 200 #DEVUELVE EL ULTIMO ID if request.method == 'PUT': incomingData = request.get_json() updateData = Cases.query.filter_by( cases_rol_rit_ruc=incomingData["cases_rol_rit_ruc"]) listOfNotEmptyStrings = [] for item in incomingData: if incomingData[item] != "": listOfNotEmptyStrings.append(item) for item2 in listOfNotEmptyStrings: print(incomingData[item2], item2) updateData.update({item2: incomingData[item2]}) db.session.commit() return "updated" if request.method == 'DELETE': incomingData = request.get_json() deletedRow = Cases.query.filter_by( cases_rol_rit_ruc=incomingData["cases_rol_rit_ruc"]).first() db.session.delete(deletedRow) db.session.commit() return "data deleted", 200
def saveReponseCode(self, code, url): print 'saveresponsecode,', url, ',code,', code Documents(url=self.url, error_code=code).save()
def saveNewResaddr(self, vurl, vlevel): doc = Documents.objects.filter(url=vurl) if (len(doc) == 0): doc = Documents(url=vurl, level=vlevel) doc.save() return doc.id
def saveNewResaddr(self, vurl, vlevel): doc = Documents.objects.filter(url=vurl) if len(doc) == 0: doc = Documents(url=vurl, level=vlevel) doc.save() return doc.id