예제 #1
0
파일: views.py 프로젝트: niekas/DAMIS
def upload_file_form_view(request):
    '''Handles Ajax request to update the uploaded file component.

    request - Ajax request. Fields:
        dataset_url - url of the uploaded data file, currently used by the component.
    '''
    context = csrf(request)
    if request.method == 'POST':
        dataset_url = request.POST.get("dataset_url")
        form = DatasetForm(data=request.POST, files=request.FILES, user=request.user)
        if form.is_valid():
            dataset = form.save()
            context['file_path'] = dataset.file.url
            context['file_name'] = dataset.title
            context['new_file_path'] = dataset.file.url

            # clear the form
            form = DatasetForm(user=request.user)
        else:
            context['file_path'] = dataset_url
    else:
        context['GET'] = True
        dataset_url = request.GET.get("dataset_url")
        if dataset_url:
            context['file_path'] = dataset_url
            file_name = split(dataset_url)[1]
            file_pattern = "{0}/datasets/{1}".format(request.user.username, file_name)
            dataset = Dataset.objects.get(file=file_pattern)
            context['file_name'] = dataset.title
        form = DatasetForm(user=request.user)
    context['form'] = form

    return render_to_response('damis/_dataset_form.html', context)
예제 #2
0
파일: views.py 프로젝트: niekas/DAMIS
def dataset_update_view(request, pk):
    context = csrf(request)
    if request.method == 'POST':
        form = DatasetForm(data=request.POST, files=request.FILES, user=request.user)
        form.instance = Dataset.objects.get(pk=pk)
        if form.is_valid():
            form.save()
    else:
        form = DatasetForm(instance=Dataset.objects.get(pk=pk), user=request.user)
    context['form'] = form

    return render_to_response('damis/_dataset_update.html', context)
예제 #3
0
파일: views.py 프로젝트: niekas/DAMIS
def dataset_create_view(request):
    context = csrf(request)
    if request.method == 'POST':
        form = DatasetForm(data=request.POST, files=request.FILES, user=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse_lazy('dataset-list'))
    else:
        form = DatasetForm(user=request.user)
    context['form'] = form
    context['user'] = request.user
    return render_to_response('damis/dataset_new.html', context)