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})
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})