def upload(request):
    upload_form = UploadLocationsForm()
    if request.method == 'POST':
        upload_form = UploadLocationsForm(request.POST, request.FILES)
        if upload_form.is_valid():
            upload_task.delay(upload_form)
            messages.warning(request, "Upload in progress. This could take a while.")
            return HttpResponseRedirect('/locations/upload/')
        messages.error(request, 'Locations not uploaded. %s'%upload_form.errors['__all__'].as_text().replace('*',''))

    context = {'button_label': 'Save', 'id': 'upload-locations-form',
             'country_name': '', 'upload_form': upload_form,'range':range(3)}

    details = LocationTypeDetails.objects.all()
    if not details.exists():
        messages.error(request, "No location hierarchy added yet.")
        return render(request, 'location_hierarchy/upload.html', context)

    country_with_location_details_objects = details[0].country
    context = {'button_label': 'Save', 'id': 'upload-locations-form',
             'country_name': country_with_location_details_objects.name, 'upload_form': upload_form,'range':range(3)}
    location_types = LocationTypeDetails.objects.order_by('order') #get_ordered_types().exclude(name__iexact='country')
    if location_types.exists():
        context.update({'location_types_details':location_types})
    return render(request, 'location_hierarchy/upload.html', context)
Beispiel #2
0
def upload(request):
    upload_form = UploadWeightsForm()
    if request.method == 'POST':
        upload_form = UploadWeightsForm(request.POST, request.FILES)
        if upload_form.is_valid():
            upload_task.delay(upload_form)
            messages.warning(request, "Upload in progress. This could take a while.")
            return HttpResponseRedirect('/locations/weights/upload/')

    context = {'button_label': 'Upload', 'id': 'upload-location-weights-form',
               'upload_form': upload_form, 'location_types': LocationType.objects.all(), 'range': range(3)}

    return render(request, 'locations/weights/upload.html', context)
Beispiel #3
0
def upload(request):
    upload_form = UploadEAForm()

    if request.method == 'POST':
        upload_form = UploadEAForm(request.POST, request.FILES)
        if upload_form.is_valid():
            upload_task.delay(upload_form)
            messages.warning(request, "Upload in progress. This could take a while.")
            return HttpResponseRedirect('/locations/enumeration_area/upload/')

    context = {'button_label': 'Upload', 'id': 'upload-location-ea-form', 'upload_form': upload_form,
               'csv_layout': UploadEACSVLayoutHelper()}

    return render(request, 'locations/enumeration_area/upload.html', context)
Beispiel #4
0
 def test_should_call_upload_on_upload_form(self, mock_upload):
     mock_upload.return_value = (True, 'some message')
     upload_form = UploadWeightsForm()
     task_result = upload_task.delay(upload_form)
     status, message = task_result.get()
     self.assertTrue(status)
     self.assertEqual('some message', message)
     self.assertTrue(task_result.successful())
Beispiel #5
0
 def test_should_call_upload_on_upload_form(self, mock_upload):
     mock_upload.return_value =(True, 'some message')
     upload_form = UploadWeightsForm()
     task_result = upload_task.delay(upload_form)
     status, message = task_result.get()
     self.assertTrue(status)
     self.assertEqual('some message', message)
     self.assertTrue(task_result.successful())
Beispiel #6
0
def upload(request):
    upload_form = UploadLocationsForm()
    if request.method == 'POST':
        upload_form = UploadLocationsForm(request.POST, request.FILES)
        if upload_form.is_valid():
            upload_task.delay(upload_form)
            messages.warning(request,
                             "Upload in progress. This could take a while.")
            return HttpResponseRedirect('/locations/upload/')
        messages.error(
            request, 'Locations not uploaded. %s' %
            upload_form.errors['__all__'].as_text().replace('*', ''))

    context = {
        'button_label': 'Save',
        'id': 'upload-locations-form',
        'country_name': '',
        'upload_form': upload_form,
        'range': range(3)
    }

    details = LocationTypeDetails.objects.all()
    if not details.exists():
        messages.error(request, "No location hierarchy added yet.")
        return render(request, 'location_hierarchy/upload.html', context)

    country_with_location_details_objects = details[0].country
    context = {
        'button_label': 'Save',
        'id': 'upload-locations-form',
        'country_name': country_with_location_details_objects.name,
        'upload_form': upload_form,
        'range': range(3)
    }
    location_types = LocationTypeDetails.objects.order_by(
        'order')  #get_ordered_types().exclude(name__iexact='country')
    if location_types.exists():
        context.update({'location_types_details': location_types})
    return render(request, 'location_hierarchy/upload.html', context)