Exemple #1
0
def new_group_logo(request, group):
    group = Group.objects.get(id=group)
    
    form = DocumentForm(request.POST, request.FILES)
    if form.is_valid():
        group.logo = request.FILES['docfile']
        group.save()

    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
Exemple #2
0
    def post(self, request, *args, **kwargs):
        form = DocumentForm(request.POST, request.FILES)
        pk = request.POST.get('pk')
        token = request.POST.get('token', None)
        data = {'pk': pk, 'token': token}
        employee_id = request.POST.get('employee_id') or None
        documentslist = request.POST.getlist('document')

        documents = EmployeeDocument.objects.select_related().filter(employee_id=pk)
        for documentlist in documentslist:
            uploadfile = request.FILES.get('upload_document_'+documentlist, '')
            if uploadfile != '':
                ed = EmployeeDocument.objects.get(id=documentlist)
                ed.status = 1
                ed.file = uploadfile
                ed.received_date = datetime.now()
                ed.save()
                e = Employee.objects.get(pk=pk)
                e.status = 1
                e.save()
        em = Employee.objects.get(pk=pk)
        em.reported_date = datetime.now()
        em.save()
        # messages.success(request, 'Your documents uploaded successfully')
        return render(request, 'document/verify.html', {'form': form, 'status': "success", 'data': data, 'media_url': MEDIA_URL, 'documents': documents, 'authenticated': 0, 'employee': em})
Exemple #3
0
def avatar(request):
    current_user = get_object_or_404(LyfeUser, pk=request.user.username)
    
    if request.method == 'POST':
		form = DocumentForm(request.POST, request.FILES)
		if form.is_valid():
			current_user.avatar = request.FILES['docfile']
			current_user.save()
			return HttpResponseRedirect(reverse('core.views.avatar'))
    else:
		form = DocumentForm()

    return render_to_response(
		'core/list.html',
		{'form': form, 'current_user': current_user},
		context_instance=RequestContext(request)
	)
Exemple #4
0
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 list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('core:list'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render(request, 'core/list.html', {'documents': documents, 'form': form})
Exemple #6
0
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
    })
Exemple #8
0
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
    })
Exemple #9
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newimage = Image(imagefile=request.FILES['docfile'],
                             user=request.user,
                             status=request.POST['select'])
            newimage.save()

            # Redirect to the images list after POST
            return HttpResponseRedirect('/list')
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    images = Image.objects.filter(user=request.user)

    # Render list page with the images and the form
    return render_to_response('list.html', {
        'images': images,
        'form': form
    },
                              context_instance=RequestContext(request))
Exemple #10
0
    def post(self, request, *args, **kwargs):
        pk = request.POST.get('pk', None)
        token = request.POST.get('token', None)
        data = {'pk': pk, 'token': token}

        form = DocumentForm()
        if (pk is None or pk == '') or (token is None or token == ''):
            messages.error(request, 'Invalid token')
            return render(request, self.template_name, {'pk': pk})
        else:
            is_exist = Employee.objects.filter(pk=pk, token=token, completed=False).exists()
            authenticated = 0
            if is_exist:
                documents = EmployeeDocument.objects.select_related().filter(employee_id=pk)
                employee = Employee.objects.get(pk=pk)
                return render(request, self.template_add, {'form': form, 'data': data, 'media_url': MEDIA_URL, 'documents': documents, 'employee': employee, 'authenticated': authenticated})

            else:
                messages.error(request, 'Invalid token')
                return render(request, self.template_name, {'pk': pk})
Exemple #11
0
    def get(self, request, *args, **kwargs):
        pk = request.GET.get('pk', None)
        token = request.GET.get('token', None)
        data = {'pk': pk, 'token': token}

        form = DocumentForm()
        if pk is None:
            return render(request, self.template_name, {'error': 1})
        else:
            if request.user.is_authenticated():
                is_exist = Employee.objects.filter(pk=pk).exists()
                authenticated = 1
            else:
                is_exist = Employee.objects.filter(pk=pk, token=token).exists()
                authenticated = 0

            if is_exist:
                documents = EmployeeDocument.objects.select_related().filter(employee_id=pk)
                employee = Employee.objects.get(pk=pk)
                return render(request, self.template_name, {'form': form, 'data': data, 'media_url': MEDIA_URL, 'documents': documents, 'employee': employee, 'authenticated': authenticated})
            else:
                return render(request, self.template_name, {'error': 1, 'authenticated': authenticated})
        return render(request, self.template_name, {'form': form, 'data': data, 'authenticated': authenticated})
Exemple #12
0
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()
    })