diff --git a/cadasta/organization/forms.py b/cadasta/organization/forms.py index 837a4b0a7..d034b4041 100644 --- a/cadasta/organization/forms.py +++ b/cadasta/organization/forms.py @@ -540,7 +540,6 @@ class SelectDefaultsForm(forms.Form): choices=LOCATION_TYPE_CHOICES, required=True ) geometry_field = forms.CharField(required=False) - geometry_type_field = forms.CharField(required=False) def __init__(self, project, user, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/cadasta/organization/importers/csv.py b/cadasta/organization/importers/csv.py index 7f314ba89..34dbe52d3 100644 --- a/cadasta/organization/importers/csv.py +++ b/cadasta/organization/importers/csv.py @@ -1,6 +1,7 @@ import csv from collections import OrderedDict +from django.contrib.gis.geos import GEOSGeometry from django.db import transaction from django.utils.translation import ugettext as _ from party.models import Party, TenureRelationship, TenureRelationshipType @@ -16,7 +17,6 @@ 'party.tenurerelationship': 'Tenure Relationship', 'party.partyrelationship': 'Party Relationship' } -GEOMETRY_TYPES = ['', 'geopoint', 'geotrace', 'geoshape'] TENURE_TYPE = 'tenure_type' @@ -27,7 +27,7 @@ def __init__(self, project=None, path=None, super(CSVImporter, self).__init__(project=project) self.path = path self.delimiter = ',' if not delimiter else delimiter - self.quotechar = '|' if not quotechar else quotechar + self.quotechar = '"' if not quotechar else quotechar def get_headers(self): headers = [] @@ -77,7 +77,6 @@ def import_data(self, config_dict, **kwargs): party_name_field = config_dict['party_name_field'] party_type = config_dict['party_type'] location_type = config_dict['location_type'] - geometry_type_field = config_dict['geometry_type_field'] geometry_field = config_dict['geometry_field'] path = config_dict['file'] try: @@ -92,10 +91,8 @@ def import_data(self, config_dict, **kwargs): # validate the row (party_name, geometry, tenure_type) = self._validate_row( - row, party_name_field, geometry_field, - geometry_type_field + row, party_name_field, geometry_field ) - # create models content_types['party.party'] = { 'project': self.project, @@ -121,8 +118,7 @@ def import_data(self, config_dict, **kwargs): raise exceptions.DataImportError( line_num=reader.line_num, error=e) - def _validate_row(self, row, party_name_field, geometry_field, - geometry_type_field): + def _validate_row(self, row, party_name_field, geometry_field): if len(self.csv_headers) != len(row): raise ValueError( _("Number of headers and columns " @@ -130,13 +126,14 @@ def _validate_row(self, row, party_name_field, geometry_field, ) party_name = row[self.csv_headers.index(party_name_field)] coords = row[self.csv_headers.index(geometry_field)] - geometry_type = row[self.csv_headers.index( - geometry_type_field)] - if geometry_type not in GEOMETRY_TYPES: - raise ValueError( - _("Invalid geometry type") - ) - geometry = odk_geom_to_wkt(coords) + + # try to parse coords as WKT first + # if that fails try to parse ODK geom string + try: + geometry = GEOSGeometry(coords) + except: + geometry = odk_geom_to_wkt(coords) + try: tenure_type = row[ self.csv_headers.index(TENURE_TYPE)] diff --git a/cadasta/organization/tests/files/invalid_col.csv b/cadasta/organization/tests/files/invalid_col.csv index 4d3a7c8ab..9169813ea 100644 --- a/cadasta/organization/tests/files/invalid_col.csv +++ b/cadasta/organization/tests/files/invalid_col.csv @@ -1,4 +1,4 @@ -name_mouza,j_l,tenure_type,name_of_HH,name_father_hus,present_add,village_name,Mobile_No,Occupation_HH,educational_qualification,amount_agriland,amount_othersland,class_HH,How_aquire_landw,How_aquire_landwh,How_aquire_landm,How_aquire_landd,How_aquire_landt,How_aquire_landp,Land_Calculation,deed_of_land,Khatain_of_land,Mutation_of_land,Everything,female_member,male_member,ownership_conflict,boundary_conflict,others_conflict,conflicts_resoulation,howconflict_resoulation,location_problems,tenure_name,tenure_notes,geo_type,nid_number,location_geometry,_geopoint_hh_latitude,_geopoint_hh_longitude,_geopoint_hh_altitude,_geopoint_hh_precision,image_hh,audio_hh,start,end,today,deviceid,subscriberid,sim_serial,phonenumber,meta/instanceID,_id,_uuid,_submission_time,_index,_parent_table_name,_parent_index,_tags,_notes,_version,_duration,_submitted_by +name_mouza,j_l,tenure_type,name_of_HH,name_father_hus,present_add,village_name,Mobile_No,Occupation_HH,educational_qualification,amount_agriland,amount_othersland,class_HH,How_aquire_landw,How_aquire_landwh,How_aquire_landm,How_aquire_landd,How_aquire_landt,How_aquire_landp,Land_Calculation,deed_of_land,Khatain_of_land,Mutation_of_land,Everything,female_member,male_member,ownership_conflict,boundary_conflict,others_conflict,conflicts_resoulation,howconflict_resoulation,location_problems,tenure_name,tenure_notes,geo_type,nid_number,location_geometry,_geopoint_hh_latitude,_geopoint_hh_longitude,_geopoint_hh_altitude,_geopoint_hh_precision,image_hh,audio_hh,start,end,today,deviceid,subscriberid,sim_serial,phonenumber,meta/instanceID,_id,_uuid,_submission_time,_index,_parent_table_name,_parent_index,_tags,_notes,_version,_duration,_submitted_by, chanderhowara,90,FH,সুরুজ্জামান,"মৃত শাহা,লী মন্ডল",মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৮০.০০ অারঙ্গহাটি ৩৬০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,yes,no,no,4,5,yes,no,কিছু বেখলে অাছে জোর করে দখল করে ভোগ করে অন্য জমির মালক।,yes,local_justice,conflict risk_of_eviction,Freehold,some notes,,3913647224045,,,,,,,,2016-02-08T10:43:19.861+06,2016-02-09T09:03:56.526+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:c2b46f0e-dd3c-4c0b-858e-edd582047f6c,5349241,c2b46f0e-dd3c-4c0b-858e-edd582047f6c,2016-02-09T11:30:07,1,,-1,,,201602060307,80437,arifuttaran chanderhowara,90,FH,অাব্দুল বারেক মন্ডল,মৃত বঙ্গু মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৯৮০৮১৯৯৪,farmer,Illiterate,৩০.০০ আরঙ্গহাটি ১২০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,no,no,5,4,no,no,,,,,Leasehold,some notes on the tenure,,3913647224033,,,,,,,,2016-02-08T11:13:52.453+06,2016-02-09T13:58:53.495+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,5349244,4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,2016-02-09T11:30:17,2,,-1,,,201602060307,96301,arifuttaran chanderhowara,90,FH,হানিফ উদ্দিন,মৃত মুগল মন্ডল,অারঙ্গহাটি,পশ্চিম অারঙ্গহাটি,০১৭৯৮০৮১৯৯৪,farmer,litteracy,১৫.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,yes,no,3,4,no,no,,,,,Customary,some more notes,,3913647225965,,,,,,,,2016-02-08T11:21:20.859+06,2016-02-09T13:58:16.633+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:405a9d1c-3c54-42ca-929d-ab4f261ce59a,5349247,405a9d1c-3c54-42ca-929d-ab4f261ce59a,2016-02-09T11:30:28,3,,-1,,,201602060307,95816,arifuttaran diff --git a/cadasta/organization/tests/files/invalid_geom_type.csv b/cadasta/organization/tests/files/invalid_geom_type.csv deleted file mode 100644 index f837a68aa..000000000 --- a/cadasta/organization/tests/files/invalid_geom_type.csv +++ /dev/null @@ -1,11 +0,0 @@ -name_mouza,j_l,tenure_type,name_of_HH,name_father_hus,present_add,village_name,Mobile_No,Occupation_HH,educational_qualification,amount_agriland,amount_othersland,class_HH,How_aquire_landw,How_aquire_landwh,How_aquire_landm,How_aquire_landd,How_aquire_landt,How_aquire_landp,Land_Calculation,deed_of_land,Khatain_of_land,Mutation_of_land,Dakhal_on_land,Everything,female_member,male_member,ownership_conflict,boundary_conflict,others_conflict,conflicts_resoulation,howconflict_resoulation,location_problems,tenure_name,tenure_notes,geo_type,nid_number,location_geotrace,_geopoint_hh_latitude,_geopoint_hh_longitude,_geopoint_hh_altitude,_geopoint_hh_precision,image_hh,audio_hh,start,end,today,deviceid,subscriberid,sim_serial,phonenumber,meta/instanceID,_id,_uuid,_submission_time,_index,_parent_table_name,_parent_index,_tags,_notes,_version,_duration,_submitted_by -chanderhowara,90,FH,সুরুজ্জামান,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৮০.০০ অারঙ্গহাটি ৩৬০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,yes,no,yes,no,4,5,yes,no,কিছু বেখলে অাছে জোর করে দখল করে ভোগ করে অন্য জমির মালক।,yes,local_justice,conflict risk_of_eviction,Freehold,some notes,,3913647224045,,,,,,,,2016-02-08T10:43:19.861+06,2016-02-09T09:03:56.526+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:c2b46f0e-dd3c-4c0b-858e-edd582047f6c,5349241,c2b46f0e-dd3c-4c0b-858e-edd582047f6c,2016-02-09T11:30:07,1,,-1,,,201602060307,80437,arifuttaran -chanderhowara,90,FH,অাব্দুল বারেক মন্ডল,মৃত বঙ্গু মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৯৮০৮১৯৯৪,farmer,Illiterate,৩০.০০ আরঙ্গহাটি ১২০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,no,yes,no,5,4,no,no,,,,,Leasehold,some notes on the tenure,,3913647224033,,,,,,,,2016-02-08T11:13:52.453+06,2016-02-09T13:58:53.495+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,5349244,4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,2016-02-09T11:30:17,2,,-1,,,201602060307,96301,arifuttaran -chanderhowara,90,FH,হানিফ উদ্দিন,মৃত মুগল মন্ডল,অারঙ্গহাটি,পশ্চিম অারঙ্গহাটি,০১৭৯৮০৮১৯৯৪,farmer,litteracy,১৫.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,yes,yes,no,3,4,no,no,,,,,Customary,some more notes,,3913647225965,,,,,,,,2016-02-08T11:21:20.859+06,2016-02-09T13:58:16.633+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:405a9d1c-3c54-42ca-929d-ab4f261ce59a,5349247,405a9d1c-3c54-42ca-929d-ab4f261ce59a,2016-02-09T11:30:28,3,,-1,,,201602060307,95816,arifuttaran -chanderhowara,90,FH,মো: অামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,service,educated,১৫.০০ অারঙ্গহাটি ৩০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,no,no,yes,no,2,1,no,no,,,,,,,INVALID,3913647224032,45.56342779158167 -122.67650283873081 0.0 0.0;45.56176327330353 -122.67669159919024 0.0 0.0; 45.56151562182025 -122.67490658909082 0.0 0.0; 45.563479432877415 122.67494414001703 0.0 0.0; 45.56176327330353 -122.67669159919024 0.0 0.0;,24.850375,89.832815,17.3,4.8,,,2016-02-08T11:27:32.805+06,2016-02-08T11:55:08.868+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:6925434e-37d3-4f09-b308-1e6e9ccf1d11,5349250,6925434e-37d3-4f09-b308-1e6e9ccf1d11,2016-02-09T11:30:38,4,,-1,,,201602060307,1656,arifuttaran -chanderhowara,90,FH,সোজা মন্ডল,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,৭০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,no,no,yes,no,0,1,no,no,,,,,,,,3913647224043,,,,,,,,2016-02-08T11:32:28.205+06,2016-02-09T13:58:42.516+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:b2cdbeba-1ced-4740-9605-9430d1ed7ead,5349251,b2cdbeba-1ced-4740-9605-9430d1ed7ead,2016-02-09T11:30:40,5,,-1,,,201602060307,95174,arifuttaran -chanderhowara,90,FH,মিজানুর রহমান,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,15,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,3,2,no,no,,,,,,,,3913647224044,,24.8503433333,89.83295,42.3,7.1,,,2016-02-08T11:37:42.708+06,2016-02-08T11:47:20.509+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:d16a03fa-5009-490e-bc4f-c3812e704b46,5349252,d16a03fa-5009-490e-bc4f-c3812e704b46,2016-02-09T11:30:42,6,,-1,,,201602060307,578,arifuttaran -chanderhowara,90,FH, জামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৫.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,2,2,no,no,,no,,,,,,3913647224031,,24.8504283333,89.8329316667,13.2,4.9,,,2016-02-08T11:47:29.749+06,2016-02-08T11:51:46.250+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,5349254,73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,2016-02-09T11:30:50,7,,-1,,,201602060307,257,arifuttaran -chanderhowara,90,FH,মো: গোলজার হোসেন,মৃত মো: শাহাজান অালী,মেম্বার বাড়ি,চান্দের হাওড়া,০১৭৪৩০৪৮৪২৩,doctor,educated,0,১৫.০০,poor,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,4,3,no,no,,,,,,,,3913647224185,,24.84934,89.8324216667,-25.9,4.7,,,2016-02-08T12:14:23.738+06,2016-02-08T12:21:48.113+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:35bb0314-bdc4-4e1d-9994-66bd745d0c0b,5349255,35bb0314-bdc4-4e1d-9994-66bd745d0c0b,2016-02-09T11:30:52,8,,-1,,,201602060307,445,arifuttaran -chanderhowara,90,FH, সুমন টিকাদার,মৃত নওয়াব অালি টিকাদার,টিকাদার বাড়ি,চান্দের হাওড়া,০১৭৩৪২৫১৩৩৮,farmer,litteracy,১০.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,1,4,no,no,,,,,,,,3913647224283,,24.8481066667,89.8323983333,-115.7,5.4,,,2016-02-08T12:41:22.328+06,2016-02-08T12:45:05.345+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:2454181a-4d9a-4797-b908-0c1c82c6b92a,5349256,2454181a-4d9a-4797-b908-0c1c82c6b92a,2016-02-09T11:30:53,9,,-1,,,201602060307,223,arifuttaran -chanderhowara,90,FH,অাব্দুল জলিল মন্ডল ,মৃত কুব্বাত মন্ডল ,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৭২৫৬০১৯১,farmer,Illiterate,২৭.০০,১৫.০০,others,inheritance,inheritance,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,4,8,no,no,,,,,Customary,a few notes,,3913647224167,,24.848365,89.832685,-50.4,4.9,,,2016-02-08T12:45:10.187+06,2016-02-08T12:53:02.738+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:68e07841-0eb3-4960-bb5e-bbfffa0b609d,5349258,68e07841-0eb3-4960-bb5e-bbfffa0b609d,2016-02-09T11:30:57,10,,-1,,,201602060307,472,arifuttaran diff --git a/cadasta/organization/tests/files/test_wkt.csv b/cadasta/organization/tests/files/test_wkt.csv new file mode 100644 index 000000000..0c8988e02 --- /dev/null +++ b/cadasta/organization/tests/files/test_wkt.csv @@ -0,0 +1,11 @@ +name_mouza,j_l,tenure_type,name_of_HH,name_father_hus,present_add,village_name,Mobile_No,Occupation_HH,educational_qualification,amount_agriland,amount_othersland,class_HH,How_aquire_landw,How_aquire_landwh,How_aquire_landm,How_aquire_landd,How_aquire_landt,How_aquire_landp,Land_Calculation,deed_of_land,Khatain_of_land,Mutation_of_land,Dakhal_on_land,Everything,female_member,male_member,ownership_conflict,boundary_conflict,others_conflict,conflicts_resoulation,howconflict_resoulation,location_problems,tenure_name,tenure_notes,nid_number,geo_type,location_geometry,image_hh,audio_hh,start,end,today,deviceid,subscriberid,sim_serial,phonenumber,meta/instanceID,_id,_uuid,_submission_time,_index,_parent_table_name,_parent_index,_tags,_notes,_version,_duration,_submitted_by +chanderhowara,90,FH,সুরুজ্জামান,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৮০.০০ অারঙ্গহাটি ৩৬০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,yes,no,yes,no,4,5,yes,no,কিছু বেখলে অাছে জোর করে দখল করে ভোগ করে অন্য জমির মালক।,yes,local_justice,conflict risk_of_eviction,Freehold,some notes,3913647224045,,SRID=4326;POINT (30 10),,,2016-02-08T10:43:19.861+06,2016-02-09T09:03:56.526+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:c2b46f0e-dd3c-4c0b-858e-edd582047f6c,5349241,c2b46f0e-dd3c-4c0b-858e-edd582047f6c,2016-02-09T11:30:07,1,,-1,,,201602060307,80437,arifuttaran +chanderhowara,90,FH,অাব্দুল বারেক মন্ডল,মৃত বঙ্গু মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৯৮০৮১৯৯৪,farmer,Illiterate,৩০.০০ আরঙ্গহাটি ১২০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,no,yes,no,5,4,no,no,,,,,Leasehold,some notes on the tenure,3913647224033,,"SRID=4326;LINESTRING (30 10, 10 30, 40 40)",,,2016-02-08T11:13:52.453+06,2016-02-09T13:58:53.495+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,5349244,4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,2016-02-09T11:30:17,2,,-1,,,201602060307,96301,arifuttaran +chanderhowara,90,FH,হানিফ উদ্দিন,মৃত মুগল মন্ডল,অারঙ্গহাটি,পশ্চিম অারঙ্গহাটি,০১৭৯৮০৮১৯৯৪,farmer,litteracy,১৫.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,yes,yes,no,3,4,no,no,,,,,Customary,some more notes,3913647225965,,"SRID=4326;POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))",,,2016-02-08T11:21:20.859+06,2016-02-09T13:58:16.633+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:405a9d1c-3c54-42ca-929d-ab4f261ce59a,5349247,405a9d1c-3c54-42ca-929d-ab4f261ce59a,2016-02-09T11:30:28,3,,-1,,,201602060307,95816,arifuttaran +chanderhowara,90,FH,মো: অামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,service,educated,১৫.০০ অারঙ্গহাটি ৩০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,no,no,yes,no,2,1,no,no,,,,,,,3913647224032,,"SRID=4326;POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))",,,2016-02-08T11:27:32.805+06,2016-02-08T11:55:08.868+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:6925434e-37d3-4f09-b308-1e6e9ccf1d11,5349250,6925434e-37d3-4f09-b308-1e6e9ccf1d11,2016-02-09T11:30:38,4,,-1,,,201602060307,1656,arifuttaran +chanderhowara,90,FH,সোজা মন্ডল,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,৭০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,no,no,yes,no,0,1,no,no,,,,,,,3913647224043,,"SRID=4326;MULTIPOINT ((10 40), (40 30), (20 20), (30 10))",,,2016-02-08T11:32:28.205+06,2016-02-09T13:58:42.516+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:b2cdbeba-1ced-4740-9605-9430d1ed7ead,5349251,b2cdbeba-1ced-4740-9605-9430d1ed7ead,2016-02-09T11:30:40,5,,-1,,,201602060307,95174,arifuttaran +chanderhowara,90,FH,মিজানুর রহমান,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,15,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,3,2,no,no,,,,,,,3913647224044,,"SRID=4326;MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))",,,2016-02-08T11:37:42.708+06,2016-02-08T11:47:20.509+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:d16a03fa-5009-490e-bc4f-c3812e704b46,5349252,d16a03fa-5009-490e-bc4f-c3812e704b46,2016-02-09T11:30:42,6,,-1,,,201602060307,578,arifuttaran +chanderhowara,90,FH, জামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৫.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,2,2,no,no,,no,,,,,3913647224031,,"SRID=4326;MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))",,,2016-02-08T11:47:29.749+06,2016-02-08T11:51:46.250+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,5349254,73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,2016-02-09T11:30:50,7,,-1,,,201602060307,257,arifuttaran +chanderhowara,90,FH,মো: গোলজার হোসেন,মৃত মো: শাহাজান অালী,মেম্বার বাড়ি,চান্দের হাওড়া,০১৭৪৩০৪৮৪২৩,doctor,educated,0,১৫.০০,poor,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,4,3,no,no,,,,,,,3913647224185,,"SRID=4326;MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))",,,2016-02-08T12:14:23.738+06,2016-02-08T12:21:48.113+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:35bb0314-bdc4-4e1d-9994-66bd745d0c0b,5349255,35bb0314-bdc4-4e1d-9994-66bd745d0c0b,2016-02-09T11:30:52,8,,-1,,,201602060307,445,arifuttaran +chanderhowara,90,FH, সুমন টিকাদার,মৃত নওয়াব অালি টিকাদার,টিকাদার বাড়ি,চান্দের হাওড়া,০১৭৩৪২৫১৩৩৮,farmer,litteracy,১০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,1,4,no,no,,,,,,,3913647224283,,,,,2016-02-08T12:41:22.328+06,2016-02-08T12:45:05.345+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:2454181a-4d9a-4797-b908-0c1c82c6b92a,5349256,2454181a-4d9a-4797-b908-0c1c82c6b92a,2016-02-09T11:30:53,9,,-1,,,201602060307,223,arifuttaran +chanderhowara,90,FH,অাব্দুল জলিল মন্ডল ,মৃত কুব্বাত মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৭২৫৬০১৯১,farmer,Illiterate,২৭.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,4,8,no,no,,,,,Customary,a few notes,3913647224167,,,,,2016-02-08T12:45:10.187+06,2016-02-08T12:53:02.738+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:68e07841-0eb3-4960-bb5e-bbfffa0b609d,5349258,68e07841-0eb3-4960-bb5e-bbfffa0b609d,2016-02-09T11:30:57,10,,-1,,,201602060307,472,arifuttaran diff --git a/cadasta/organization/tests/test_importers.py b/cadasta/organization/tests/test_importers.py index 1d504929d..1ec346add 100644 --- a/cadasta/organization/tests/test_importers.py +++ b/cadasta/organization/tests/test_importers.py @@ -42,12 +42,11 @@ def setUp(self): self.valid_csv = '/organization/tests/files/test.csv' self.invalid_csv = '/organization/tests/files/test_invalid.csv' + self.invalid_col_csv = '/organization/tests/files/invalid_col.csv' self.geoshape_csv = '/organization/tests/files/test_geoshape.csv' self.geotrace_csv = '/organization/tests/files/test_geotrace.csv' - self.invalid_col_csv = '/organization/tests/files/invalid_col.csv' - self.invalid_geom_type = ( - '/organization/tests/files/invalid_geom_type.csv') self.no_tenure_type = '/organization/tests/files/no_tenure_type.csv' + self.test_wkt = '/organization/tests/files/test_wkt.csv' self.project = ProjectFactory.create(name='Test CSV Import') xlscontent = self.get_file( @@ -102,7 +101,6 @@ def test_import_data(self): 'party_name_field': 'name_of_hh', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geometry', 'attributes': self.attributes, 'project': self.project @@ -147,6 +145,29 @@ def test_import_data(self): assert len(tenure_relationships[0].attributes) == 2 assert tenure_relationships[0].attributes == tr_attrs + def test_import_with_invalid_column(self): + importer = csv.CSVImporter( + project=self.project, path=self.path + self.invalid_col_csv) + config_dict = { + 'file': self.path + self.invalid_col_csv, + 'party_name_field': 'name_of_hh', + 'party_type': 'IN', + 'location_type': 'PA', + 'geometry_field': 'location_geometry', + 'attributes': self.attributes, + 'project': self.project, + } + with pytest.raises(exceptions.DataImportError) as e: + importer.import_data(config_dict) + assert str(e.value) == ( + "Error importing file at line 2: " + "Number of headers and columns " + "do not match" + ) + assert Party.objects.all().count() == 0 + assert SpatialUnit.objects.all().count() == 0 + assert TenureRelationship.objects.all().count() == 0 + def test_import_with_geoshape(self): importer = csv.CSVImporter( project=self.project, path=self.path + self.geoshape_csv) @@ -155,7 +176,6 @@ def test_import_with_geoshape(self): 'party_name_field': 'name_of_hh', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geoshape', 'attributes': self.attributes, 'project': self.project @@ -176,7 +196,6 @@ def test_import_with_geotrace(self): 'party_name_field': 'name_of_hh', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geotrace', 'attributes': self.attributes, 'project': self.project @@ -197,7 +216,6 @@ def test_import_with_bad_defaults(self): 'party_name_field': 'bad_party_name_field', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geometry', 'attributes': self.attributes, 'project': self.project @@ -208,68 +226,60 @@ def test_import_with_bad_defaults(self): assert SpatialUnit.objects.all().count() == 0 assert TenureRelationship.objects.all().count() == 0 - def test_import_with_invalid_column(self): + def test_import_with_missing_tenure_type(self): importer = csv.CSVImporter( - project=self.project, path=self.path + self.invalid_col_csv) + project=self.project, path=self.path + self.no_tenure_type) config_dict = { - 'file': self.path + self.invalid_col_csv, + 'file': self.path + self.no_tenure_type, 'party_name_field': 'name_of_hh', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geometry', 'attributes': self.attributes, - 'project': self.project, - } - with pytest.raises(exceptions.DataImportError) as e: - importer.import_data(config_dict) - assert str(e.value) == ( - "Error importing file at line 2: " - "Number of headers and columns " - "do not match" - ) - assert Party.objects.all().count() == 0 - assert SpatialUnit.objects.all().count() == 0 - assert TenureRelationship.objects.all().count() == 0 - - def test_import_with_invalid_geom_type(self): - importer = csv.CSVImporter( - project=self.project, path=self.path + self.invalid_geom_type) - config_dict = { - 'file': self.path + self.invalid_geom_type, - 'party_name_field': 'name_of_hh', - 'party_type': 'IN', - 'location_type': 'PA', - 'geometry_type_field': 'geo_type', - 'geometry_field': 'location_geotrace', - 'attributes': self.attributes, 'project': self.project } with pytest.raises(exceptions.DataImportError) as e: importer.import_data(config_dict) - assert str(e.value) == ("Error importing file at line 5: " - "Invalid geometry type") + assert str(e.value) == ("Error importing file at line 2: " + "No 'tenure_type' column found") assert Party.objects.all().count() == 0 assert SpatialUnit.objects.all().count() == 0 assert TenureRelationship.objects.all().count() == 0 - def test_import_with_missing_tenure_type(self): + def test_import_with_wkt(self): importer = csv.CSVImporter( - project=self.project, path=self.path + self.no_tenure_type) + project=self.project, path=self.path + self.test_wkt) config_dict = { - 'file': self.path + self.no_tenure_type, + 'file': self.path + self.test_wkt, 'party_name_field': 'name_of_hh', 'party_type': 'IN', 'location_type': 'PA', - 'geometry_type_field': 'geo_type', 'geometry_field': 'location_geometry', 'attributes': self.attributes, 'project': self.project } - with pytest.raises(exceptions.DataImportError) as e: - importer.import_data(config_dict) - assert str(e.value) == ("Error importing file at line 2: " - "No 'tenure_type' column found") - assert Party.objects.all().count() == 0 - assert SpatialUnit.objects.all().count() == 0 - assert TenureRelationship.objects.all().count() == 0 + importer.import_data(config_dict) + assert Party.objects.all().count() == 10 + assert SpatialUnit.objects.all().count() == 10 + assert TenureRelationship.objects.all().count() == 10 + + # test wkt geom creation + su1 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647224045'}).first() + su2 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647224033'}).first() + su3 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647225965'}).first() + su4 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647224043'}).first() + su5 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647224044'}).first() + su6 = SpatialUnit.objects.filter( + attributes__contains={'nid_number': '3913647224185'}).first() + + assert su1.geometry.geom_type == 'Point' + assert su2.geometry.geom_type == 'LineString' + assert su3.geometry.geom_type == 'Polygon' + assert su4.geometry.geom_type == 'MultiPoint' + assert su5.geometry.geom_type == 'MultiLineString' + assert su6.geometry.geom_type == 'MultiPolygon' diff --git a/cadasta/organization/tests/test_views_default_projects.py b/cadasta/organization/tests/test_views_default_projects.py index e9e529c16..f10180002 100644 --- a/cadasta/organization/tests/test_views_default_projects.py +++ b/cadasta/organization/tests/test_views_default_projects.py @@ -1423,7 +1423,6 @@ def setUp(self): 'select_defaults-party_type': 'IN', 'select_defaults-location_type': 'PA', 'select_defaults-geometry_field': 'location_geometry', - 'select_defaults-geometry_type_field': 'geo_type', } def _get(self, status=None, check_content=False, login_redirect=False): diff --git a/cadasta/organization/views/default.py b/cadasta/organization/views/default.py index 6f120a599..c5fdbb680 100644 --- a/cadasta/organization/views/default.py +++ b/cadasta/organization/views/default.py @@ -830,7 +830,6 @@ def done(self, form_list, **kwargs): 'party_name_field': form_data[2]['party_name_field'], 'party_type': form_data[2]['party_type'], 'location_type': form_data[2]['location_type'], - 'geometry_type_field': form_data[2]['geometry_type_field'], 'geometry_field': form_data[2]['geometry_field'], 'attributes': map_attrs_data.getlist('attributes', None), } diff --git a/cadasta/templates/organization/project_defaults_import.html b/cadasta/templates/organization/project_defaults_import.html index 50add7f5c..1cf3cc8b3 100644 --- a/cadasta/templates/organization/project_defaults_import.html +++ b/cadasta/templates/organization/project_defaults_import.html @@ -1,9 +1,9 @@ -{% extends "organization/project_import_wrapper.html" %} +{% extends "organization/project_import_wrapper.html" %} {% load i18n %} {% load widget_tweaks %} -{% block extra_script %} {{ form.media }} {% endblock %} +{% block extra_script %} {{ form.media }} {% endblock %} {% block step_content %} @@ -20,7 +20,7 @@

{% trans "Configure default fields" %}

{% trans "Match the fields and select the default values below." %}

{% trans "Party" %}

-
+

{% trans "Location" %}

-
+
- {% render_field wizard.form.location_type class+="form-control" %} + {% render_field wizard.form.location_type class+="form-control" %}
-
- - -