示例#1
0
def createDocument():
	data = json.loads(request.data)
	c = DocumentModel()
	result = c.createDocument(data)
	
	if data['doc_link'] and data['doc_link'].strip():
		c.updateDocumentFile(result['id_doc'], data['doc_link'])

	return jsonify({'id_doc': result['id_doc']})
示例#2
0
def upateDocument(id):
	data = json.loads(request.data)
	c = DocumentModel()
	result = c.updateDocument(id,data)

	if data['doc_link'] and data['doc_link'].strip():
		c.updateDocumentFile(id, data['doc_link'])

		for file in os.listdir(app.config['DOCUMENT_FILE_FOLDER']):
			if str(id) == file.split('.')[0]:
				try:
					os.remove(app.config['DOCUMENT_FILE_FOLDER'] + file)
				except OSError:
					pass
				break;


	return jsonify({'id_doc': id})
示例#3
0
def createFile():
	file = request.files['document']
	id_doc = request.form['id_doc']
	filename = id_doc + '.' + file.filename.rsplit('.', 1)[1]
	
	# try:
	# 	os.remove(app.config['DOCUMENT_FILE_FOLDER'] + filename)
	# except OSError:
	# 	pass

	for fileAux in os.listdir(app.config['DOCUMENT_FILE_FOLDER']):
		if id_doc == fileAux.split('.')[0]:
			try:
				os.remove(app.config['DOCUMENT_FILE_FOLDER'] + fileAux)
			except OSError:
				pass

	file.save(os.path.join(app.config['DOCUMENT_FILE_FOLDER'], filename))
	c = DocumentModel()
	c.updateDocumentFile(id_doc, '/documents/' + filename)
	return jsonify({'result': True})