def document_edit(request, pk): log.debug('editing document', post=request.POST) document = get_object_or_404(Document, pk=pk) if request.method == 'POST': form = DocumentForm(request.POST, request.FILES, instance=document) if form.is_valid(): # data = form.cleaned_data form.save() messages.add_message(request, messages.SUCCESS, "Document updated") redirecturl = document.content_type.name return redirect(to=redirecturl, pk=document.object_id) else: return JsonResponse( { 'error': { 'type': 'Edit error', 'messages': [str(e) for e in form.errors] } }, status=405) else: form = DocumentForm(instance=document) log.debug(submit_url=request.get_full_path()) return render(request, 'modal_form.html', { 'form': form, 'submit_url': request.get_full_path() })
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})
def model_form_upload(request): id = "" msg = "" if request.method == 'POST': form = DocumentForm(request.POST, request.FILES, request.POST) if form.is_valid(): form.save() email = form.cleaned_data['Email'] document_count = Document.objects.values_list('document').count() document_last = Document.objects.values_list('document')[ document_count - 1] document_name = document_last[0] print(email) t = Document.objects.last() num_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] password1 = "" for i in range(0, 8): password1 = password1 + random.choice(num_list) t.password = password1 print(type(document_name)) document_name1 = document_name.encode('ascii') document_encode = str(base64.b64encode(document_name1)) ax = document_encode[2:-1] t.file_url = ax print(ax) t.save() qr = pyqrcode.create(ax) filename = document_name.rsplit(".") filename1 = filename[0].split("/") filename2 = filename1[1] + ".png" qr.png(filename2, scale=6) """mail=EmailMessage('QR',password1,'*****@*****.**',[email]) #mail.attach(filename2,filename2.content_type) mail.send()""" subject = 'QRcode scanner for license' message = password1 email_from = settings.EMAIL_HOST_USER recipient_list = [ email, ] mail = EmailMessage(subject, message, email_from, recipient_list) BASE_DIR = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) mail.attach_file(os.path.join(BASE_DIR, filename2)) mail.send() msg = "your successfully uploaded" return redirect('model_form_upload') else: form = DocumentForm() return render(request, 'model_form_upload.html', { 'form': form, 'msg': msg })
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): document = form.save(commit=False) document.description = document.image.name document = form.save() return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', { 'form': form })
def upload_document(request, object_id, content_type): log.debug('uploading document', post=request.POST, files=request.FILES) if request.method == 'POST': print(object_id, content_type) if not request.FILES: log.error('Upload failed: no document found.') return JsonResponse( { 'error': { 'type': 'Upload error', 'messages': ['No document to upload.'] } }, status=405) form = DocumentForm(request.POST, request.FILES) if not form.is_valid(): return JsonResponse( { 'error': { 'type': 'Upload error', 'messages': [str(e) for e in form.errors] } }, status=405) document = form.save() messages.add_message(request, messages.SUCCESS, "Document added") redirecturl = document.content_type.name return redirect(to=redirecturl, pk=document.object_id) else: form = DocumentForm(initial={ 'content_type': content_type, 'object_id': object_id }) log.debug(submit_url=request.get_full_path()) return render(request, 'modal_form.html', { 'form': form, 'submit_url': request.get_full_path() })