Example #1
0
def upload_file(request):
    """
    View that is displayed for uploading a study/submission
    """
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                submission = form.save()
                email = EmailMessage(
                    submission.get_email_subject(),
                    submission.get_email_text(),
                    settings.EMAIL_ADDRESS,
                    [submission.email],
                    [settings.EMAIL_ADDRESS],
                    reply_to=[settings.EMAIL_ADDRESS]
                )
                email.send(True)
                return HttpResponseRedirect('/submission/%s/' % submission.id)
            except Accession.DoesNotExist as err:
                form.add_error(None, 'Unknown accession with ID: %s' % err.args[-1])
            except Exception as err:
                form.add_error(None, str(err))
    else:
        form = UploadFileForm()
    context = { 'form': form }
    context.update(base_context(request))
    return render(request, 'home/upload.html', context)
Example #2
0
def upload_file(request):
    """
    View that is displayed for uploading a study/submission
    """
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                submission = form.save()
                email = EmailMessage(submission.get_email_subject(),
                                     submission.get_email_text(),
                                     '*****@*****.**',
                                     [submission.email],
                                     [settings.ADMINS[0][1]],
                                     reply_to=['*****@*****.**'])
                email.send(True)
                return HttpResponseRedirect('/submission/%s/' % submission.id)
            except Accession.DoesNotExist as err:
                form.add_error(None,
                               'Unknown accession with ID: %s' % err.args[-1])
            except Exception as err:
                form.add_error(None, str(err))
    else:
        form = UploadFileForm()
    return render(request, 'home/upload.html', {'form': form})
Example #3
0
def submit_study(request, format=None):
    """
    Submit a study
    ---

    serializer: SubmissionDetailSerializer
    omit_serializer: false

    produces:
        - application/json
    """
    if request.method == "POST":
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                submission = form.save()
                email = EmailMessage('Study submitted to AraPheno',
                                     submission.get_email_text(),
                                     '*****@*****.**',
                                     [submission.email],
                                     [settings.ADMINS[0][1]],
                                     reply_to=['*****@*****.**'])
                email.send(True)
                serializer = SubmissionDetailSerializer(
                    submission, many=False, context={'request': request})

                return Response(serializer.data, status.HTTP_201_CREATED)
            except Accession.DoesNotExist as err:
                return Response('Unknown accession with ID: %s' % err.args[-1],
                                status.HTTP_400_BAD_REQUEST)
            except Exception as err:
                return Response(str(err), status.HTTP_400_BAD_REQUEST)
        else:
            return Response('Some fields are missing',
                            status.HTTP_400_BAD_REQUEST)