Skip to content

Commit

Permalink
Fix: #832 Add suport for XLSX imports (#898)
Browse files Browse the repository at this point in the history
* Add XLSX imports
* Add import of Locations or Parties separately
* Add selection of location_type field in import
* Add selection of party_type field in import
* Add suport for 1-M relations in import
  • Loading branch information
bjohare authored and oliverroick committed Dec 2, 2016
1 parent fdf4a84 commit be55f0e
Show file tree
Hide file tree
Showing 30 changed files with 1,681 additions and 612 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
}
}


5 changes: 5 additions & 0 deletions cadasta/config/settings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,8 @@
FILE_UPLOAD_HANDLERS = [
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]

IMPORTERS = {
'csv': 'organization.importers.csv.CSVImporter',
'xls': 'organization.importers.xls.XLSImporter'
}
13 changes: 13 additions & 0 deletions cadasta/core/static/css/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 51 additions & 28 deletions cadasta/core/static/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ label {

a {
color: $link-color;
&:hover,
&:hover,
&:focus {
color: $brand-darkblue;
outline: none;
Expand Down Expand Up @@ -209,7 +209,7 @@ header {
text-align: center;
padding-top: 24px;
@include button-variant($gray-lighter, transparent, $btn-blue-bg);
&:hover,
&:hover,
&:focus {
@include button-variant(#fff, darken($btn-blue-bg, 5%), $btn-blue-bg);
transition: all 0.3s ease 0s;
Expand Down Expand Up @@ -281,7 +281,7 @@ header {
#dashboard .header,
#project-single .header,
#project-wizard .header,
#organization-single .header {
#organization-single .header {
position: fixed;
}

Expand Down Expand Up @@ -400,9 +400,9 @@ header {
.page-header { // navy band on index pages
background: $brand-darkblue;
background-color: $brand-primary;
background: -moz-linear-gradient(top, $brand-darkblue 0%, $brand-primary 70%);
background: -webkit-linear-gradient(top, $brand-darkblue 0%,$brand-primary 70%);
background: linear-gradient(to bottom, $brand-darkblue 0%,$brand-primary 70%);
background: -moz-linear-gradient(top, $brand-darkblue 0%, $brand-primary 70%);
background: -webkit-linear-gradient(top, $brand-darkblue 0%,$brand-primary 70%);
background: linear-gradient(to bottom, $brand-darkblue 0%,$brand-primary 70%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$brand-darkblue', endColorstr='$brand-primary',GradientType=0 );
margin: 0;
padding-top: 48px;
Expand Down Expand Up @@ -467,14 +467,19 @@ header {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

&:hover{
overflow: visible;
white-space: normal;
}
}
}
}

/* =Page header single project or organizations
-------------------------------------------------------------- */

#project-single .page-header,
#project-single .page-header,
#organization-single .page-header { // navy band on pages for single project or organization
background: $brand-darkblue;
height: 110px;
Expand Down Expand Up @@ -525,16 +530,16 @@ header {
}
}

#organization-single .page-header {
padding-top: 35px; // offset to match project
#organization-single .page-header {
padding-top: 35px; // offset to match project
.top-btn {
margin-top: 1px;
}
}

@media (max-width: $screen-sm-max) {
#project-single .page-header,
#organization-single .page-header {
#project-single .page-header,
#organization-single .page-header {
overflow: visible;
padding-top: 8px;
padding-bottom: 0;
Expand All @@ -551,14 +556,14 @@ header {
margin-left: 14px;
}
}
#project-single .page-header .page-title,
#project-single .page-header .page-title,
#organization-single .page-header .page-title {
padding-bottom: 0;
}
}

@media (max-width: $screen-xs-max) {
#project-single .page-header,
#project-single .page-header,
#organization-single .page-header {
.more-menu {
width: 24px;
Expand Down Expand Up @@ -665,7 +670,7 @@ main.container-fluid {
-------------------------------------------------------------- */

#project-single #page-content main,
#organization-single #page-content main {
#organization-single #page-content main {
position: relative;
left: 0;
margin-left: 0;
Expand All @@ -685,7 +690,8 @@ main.container-fluid {
#project-single #page-content main,
#organization-single #page-content main,
#project-single #page-content main.show-sidebar,
#organization-single #page-content main.show-sidebar {
#organization-single #page-content main.show-sidebar,
#organization-single #page-content main {
margin-left: 0;
background: #fff;
}
Expand Down Expand Up @@ -775,7 +781,7 @@ main.container-fluid {
margin: 10px auto 20px;
float: none;
text-align: center;
img {
img {
width: 90%;
max-width: 200px;
}
Expand Down Expand Up @@ -834,7 +840,7 @@ main.container-fluid {
}
}
}
.row-height .detail { // columns fixed to match heights like org overview
.row-height .detail { // columns fixed to match heights like org overview
padding-top: 0;
}
.detail-edit { // edit on right
Expand All @@ -843,7 +849,7 @@ main.container-fluid {
background: transparent;
}
}
.panel { // content box in main panel
.panel { // content box in main panel
border: 1px solid $table-border-color;
clear: both;
.panel-heading {
Expand Down Expand Up @@ -877,7 +883,7 @@ main.container-fluid {
}
}
}
.member-panel { // member edit page
.member-panel { // member edit page
border: 0;
-webkit-box-shadow: none !important;
box-shadow: none !important;
Expand Down Expand Up @@ -961,7 +967,24 @@ textarea.form-control {
font-size: 16px;
font-weight: 600;
}
small {
small {
margin-top: 6px;
font-weight: 300;
display: block;
}
}
}

.spacing-md {
margin-top: 15px;
li {
margin-left: 15px;
margin-bottom: 15px;
label {
font-size: 16px;
font-weight: 600;
}
small {
margin-top: 6px;
font-weight: 300;
display: block;
Expand All @@ -982,7 +1005,7 @@ textarea.form-control {

.dataTables_wrapper {
clear: both;
.table-search { // search
.table-search { // search
label {
float: left;
text-align: left;
Expand Down Expand Up @@ -1017,7 +1040,7 @@ textarea.form-control {
.table-pagination { // pagination
float: right;
display: inline-block;
.pagination > li > a,
.pagination > li > a,
.pagination > li > span {
color: $gray-dark;
}
Expand Down Expand Up @@ -1060,7 +1083,7 @@ textarea.form-control {
}

@media (max-width: 400px) {
#project-single .dataTables_wrapper .col-sm-6,
#project-single .dataTables_wrapper .col-sm-6,
#organization-single .dataTables_wrapper .col-sm-6 {
width: 100% !important; // fix for col-xs-6
float: left !important;
Expand Down Expand Up @@ -1285,7 +1308,7 @@ img.org-logo, img#org-logo {
}
}

div.add-btn-btm { // add party link at bottom of table
div.add-btn-btm { // add party link at bottom of table
padding: 10px 24px;
text-align: left;
border-bottom: 3px solid $table-border-color;
Expand All @@ -1311,7 +1334,7 @@ div.add-btn-btm { // add party link at bottom of table
.top-btn .btn {
min-width: 80px;
}
#project-single .page-header,
#project-single .page-header,
#organization-single .page-header {
.top-btn {
padding: 4px 14px 0;
Expand Down Expand Up @@ -1392,8 +1415,8 @@ div.add-btn-btm { // add party link at bottom of table
display: inline-block;
margin-left: 6px;
margin-right: 6px;
font-size: 11px;
font-weight: 500;
font-size: 11px;
font-weight: 500;
vertical-align: middle;
}

Expand All @@ -1415,7 +1438,7 @@ h1 .label {
@media (max-width: $screen-xs-max) {
h1 .label {
font-size: 12px;
}
}
}

/* =Modals
Expand Down
4 changes: 0 additions & 4 deletions cadasta/core/static/js/import.js

This file was deleted.

20 changes: 15 additions & 5 deletions cadasta/organization/download/xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,38 @@ def write_items(self, worksheet, queryset, content_type, model_attrs):
worksheet.append(values)

def write_locations(self):
worksheet = self.workbook.create_sheet(title='locations')
locations = self.project.spatial_units.all()
if locations.count() == 0:
return
worksheet = self.workbook.create_sheet(title='locations')

content_type = ContentType.objects.get(app_label='spatial',
model='spatialunit')
self.write_items(worksheet, locations, content_type,
['id', 'geometry.ewkt'])
['id', 'geometry.ewkt', 'type'])

def write_parties(self):
worksheet = self.workbook.create_sheet(title='parties')
parties = self.project.parties.all()
if parties.count() == 0:
return
worksheet = self.workbook.create_sheet(title='parties')

content_type = ContentType.objects.get(app_label='party',
model='party')
self.write_items(worksheet, parties, content_type,
['id', 'name', 'type'])

def write_relationships(self):
worksheet = self.workbook.create_sheet(title='relationships')
relationships = self.project.tenure_relationships.all()
if relationships.count() == 0:
return
worksheet = self.workbook.create_sheet(title='relationships')

content_type = ContentType.objects.get(app_label='party',
model='tenurerelationship')
self.write_items(worksheet, relationships, content_type,
['party_id', 'spatial_unit_id', 'tenure_type.label'])
['party_id', 'spatial_unit_id', 'tenure_type.id',
'tenure_type.label'])

def make_download(self, f_name):
path = os.path.join(settings.MEDIA_ROOT, 'temp/{}.xlsx'.format(f_name))
Expand Down
Loading

0 comments on commit be55f0e

Please sign in to comment.