def CreateCategory(request): if request.method == 'POST': forms = CategoriaForm(request.POST) if forms.is_valid(): forms.save() return HttpResponse("200") else: forms = CategoriaForm() return render(request, 'documentos/CreateCategory.html', {'form': forms})
def CreateDocumento(request): Usuario = Documento(Usuario=request.user) if request.method == 'POST': forms = DocumentoForm(request.POST, request.FILES, instance=Usuario) if forms.is_valid(): datos = forms.save(commit=False) datos.save() return HttpResponse(int(datos.id)) else: forms = DocumentoForm(instance=Usuario) return render(request, 'documentos/CreateDocumento.html', {'form': forms})
def editShear(request, id_share, id_document): dato = Compartir.objects.get(id=int(id_share)) if request.method == 'POST': forms = CompartirForm(request.POST, instance=dato) if forms.is_valid(): forms.save() return HttpResponse('200') forms = CompartirForm(instance=dato) return render(request, 'documentos/editShear.html', { 'form': forms, 'dato': dato })
def UpdateDocuments(request, id): dato = Documento.objects.get(id=int(id)) if request.method == 'POST': forms = DocumentoForm(request.POST, request.FILES, instance=dato) if forms.is_valid(): forms.save() return HttpResponse('200') forms = DocumentoForm(instance=dato) return render(request, 'documentos/UpdateDocuments.html', { 'form': forms, 'dato': dato })
def generateBakup(request): if request.method == 'POST': forms = formDB(request.POST, request.FILES) if forms.is_valid(): dato = str(request.FILES['Base_de_datos']) command = "mysql -h localhost -u root agronomia" + "<" + dato + "" #command = command+"<"+str(request.FILES['base']) os.system(command) return HttpResponse("Base de Datos Restaurada Correctamente.") else: return HttpResponse("Error al Interar Restaurar la Base de Datos") forms = formDB() return render(request, 'documentos/generateBakup.html', {'forms': forms})
def CreateComents(request, id_document): Usuario = Comentar(Usuario=request.user) if request.method == 'POST': forms = ComentForm(request.POST, instance=Usuario) if forms.is_valid(): datos = forms.save(commit=False) datos.documento_id = int(id_document) datos.save() return HttpResponse("200") else: forms = ComentForm(instance=Usuario) return render(request, 'documentos/CreateComents.html', { 'form': forms, 'id_document': id_document })
def sharedFile(request, pk): Usuario = Compartir(Usuario=request.user) if request.method == 'POST': forms = CompartirForm(request.POST, instance=Usuario) if forms.is_valid(): datos = forms.save(commit=False) datos.Correo_origen = settings.EMAIL_HOST_USER datos.Correo_Destino = request.POST['Correo_Destino'] datos.documento_id = int(pk) body = render_to_string( 'documentos/dato_compartido.html', { 'documento': getDocumento(pk), 'date_today': datetime.now(), 'usuario': User.objects.get(id=int(request.user.id)) }, ) #a = request.FILES["Archivo"] email_message = EmailMessage(subject=f'Documento Compartido {pk}', body=body, from_email=settings.EMAIL_HOST_USER, to=[request.POST['Correo_Destino']]) #email.attach(a.name, a.read(), a.content_type) #a.close() email_message.content_subtype = 'html' email_message.send() datos.save() return HttpResponse("200") else: forms = CompartirForm(instance=Usuario) return render(request, 'documentos/sharedFile.html', { 'form': forms, 'pk': pk })