コード例 #1
0
def index(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            file = request.FILES['file']
            # Check the upload logs to make sure we haven't already loaded this file
            if (UploadLog.objects.filter(file_name=file.name).count() > 0):
                raise Exception('File Already Loaded')
            if request.user.is_authenticated():
                UploadLog.objects.create(user=request.user, file_name=file.name, file_size=file.size)
            else:
                UploadLog.objects.create(file_name=file.name, file_size=file.size)
            arp.import_file(file)
            # return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render(request, 'arpwatch/index.html', {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: hullabaloo707/nadine
def home(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            file = request.FILES['file']
            # Check the upload logs to make sure we haven't already loaded this file
            if (UploadLog.objects.filter(file_name=file.name).count() > 0):
                raise Exception('File Already Loaded')
            if request.user.is_authenticated():
                UploadLog.objects.create(user=request.user, file_name=file.name, file_size=file.size)
            else:
                UploadLog.objects.create(file_name=file.name, file_size=file.size)
            arp.import_file(file)
            # return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render(request, 'arpwatch/home.html', {'form': form})