Example #1
0
def demo_example(request):
    ctx = {}
    if request.method == "POST":
        # Get file from request
        email = request.POST.get('email', None)
        job_title = request.POST.get('job_title', None)
        directory = "solo_file/media/"
        process_file_name = "search.faa"

        # Save values in the process table
        process_object = Process.objects.create(
            email=email,
            title=job_title,
            actual_file_name=process_file_name,
            process_file_name=process_file_name,
            created_date=datetime.now(),
            updated_date=datetime.now(),
        )

        # Call background process
        generate_process.delay(
            process_object.id,
            process_object.process_file_name,
            directory,
        )
        msg = ' and check your process in queue'
        if email:
            msg += ' as well as I will send you an email after processing.'
        # msg
        ctx['msg'] = "Test File upload successfully" + msg
        ctx['msg_class'] = 'success'
    return render(request, 'demo_example.html', ctx)
Example #2
0
def file_upload(request):
    ctx = {
        'active': "home",
    }
    if request.method == "POST":
        # Get file from request
        file = request.FILES.get('search_file', '')
        email = request.POST.get('email', None)
        search_name = request.POST.get('search_text', None)
        job_title = request.POST.get('job_title', None)
        e_value_cutoff = request.POST.get('e_value_cutoff', None)
        identity_cutoff = request.POST.get('identity_cutoff', None)
        directory = "solo_file/media/"
        if file:
            file_name = file.name
            file_extension = file_name.split('.')[1]

            # Validate file
            if not allow_file(file_extension):
                ctx['msg'] = "Please provide only .faa file"
                ctx['msg_class'] = 'danger'
                return render(request, 'base.html', ctx)
            file_size = ((file.size / 1024) / 1024)
            if file_size > 95:
                ctx['msg'] = "Please not provide more than 95 mb file."
                ctx['msg_class'] = 'danger'
                return render(request, 'base.html', ctx)

            process_file_name = "search.faa"

            # Save uploaded file
            default_storage.save(directory + process_file_name, file)

            # Save values in the process table
            process_object = Process.objects.create(
                email=email,
                title=job_title,
                actual_file_name=file_name,
                process_file_name=process_file_name,
                created_date=datetime.now(),
                updated_date=datetime.now(),
            )

            # Call background process
            generate_process.delay(
                process_object.id,
                process_object.process_file_name,
                directory,
                identity_cutoff=identity_cutoff,
                e_value_cutoff=e_value_cutoff,
            )
            msg = ' and check your process in queue'
            if email:
                msg += ' as well as I will send you an email after processing.'
            # msg
            ctx['msg'] = "File upload successfully" + msg
            ctx['msg_class'] = 'success'
        else:
            if search_name:
                # Save values in the process table
                process_object = Process.objects.create(
                    email=email,
                    title=job_title,
                    created_date=datetime.now(),
                    updated_date=datetime.now(),
                )
                call_search_process.delay(
                    process_object.id,
                    search_name,
                    directory,
                )
                ctx['msg'] = "File uploaded successfully and your request is processing now"
                ctx['msg_class'] = 'success'
            else:
                ctx['msg'] = "Please provide a valid data"
                ctx['msg_class'] = 'danger'
    return render(request, 'base.html', ctx)