Skip to content

Commit

Permalink
abstract fix, convenience method for clearing joins. IQSS/dataverse#2937
Browse files Browse the repository at this point in the history
  • Loading branch information
raprasad committed Mar 11, 2016
1 parent d4a1c3b commit 293159f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 13 deletions.
15 changes: 15 additions & 0 deletions geoconnect/apps/gis_tabular/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ def get_worldmap_info(self):
return self.worldmapjoinlayerinfo_set.first()


def get_abstract_for_join(self):
"""
Populate the 'abstract' field when attempting to
create a WorldMap layer
This should be editable by the user
"""
abstract = ('{0}<p><b>File:</b> {1}</p>'
'<p><b>Source:</b> Dataverse repository</p>'
'').format(self.dataset_citation,\
self.datafile_label)
return abstract




class WorldMapTabularLayerInfo(TimeStampedModel):
"""
Expand Down
5 changes: 3 additions & 2 deletions geoconnect/apps/gis_tabular/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from apps.registered_dataverse.models import RegisteredDataverse

# Create a new TabularFileInfo object

name = 'Zip code test (happiness)'
dv_file_path = 'happiness.tab'
name = 'CBG Annual and Longitudinal Measures'
dv_file_path = 'CBG Annual and Longitudinal Measures.tab'

dv_meta = DataverseTestInfo.get_dataverse_test_info_dict(\
name,\
Expand All @@ -34,6 +34,7 @@ f.errors
tab_info = TabularFileInfo(**f.cleaned_data)
tab_info.save()

## stop....
import pandas as pd
df = pd.read_csv('CBG Annual and Longitudinal Measures.xlsx')
df = pd.read_excel('CBG Annual and Longitudinal Measures.xlsx')
Expand Down
8 changes: 4 additions & 4 deletions geoconnect/apps/worldmap_connect/jointarget_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ def get_available_layers_list_by_type(self, chosen_geocode_type=None):
if chosen_geocode_type == gtype_slug or\
chosen_geocode_type is None:

info_line = "{0} - {1}".format(info['year'], info['title'])
info_line = "{0} - {1}".format(info['year'], info['name'])

# If this is zero-padded, add that info
#zero_pad_note = self.get_zero_pad_note(info)
#if zero_pad_note:
# info_line = "{0} ({1})".format(info_line, zero_pad_note)

formatting_note = self.get_format_name(info)
if formatting_note:
info_line = "{0} - {1}".format(info_line, formatting_note)
#formatting_note = self.get_format_name(info)
#if formatting_note:
# info_line = "{0} - {1}".format(info_line, formatting_note)

join_targets.append((info['id'], info_line))

Expand Down
2 changes: 1 addition & 1 deletion geoconnect/apps/worldmap_connect/lat_lng_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_map_from_datatable_lat_lng(tabular_info, lat_col, lng_col):
# Prepare parameters
# --------------------------------
map_params = dict(title=tabular_info.name,
abstract="Abstract for ... {0}".format(tabular_info.name),
abstract=tabular_info.get_abstract_for_join(),
delimiter=tabular_info.delimiter,
lat_attribute=lat_col,
lng_attribute=lng_col)
Expand Down
11 changes: 7 additions & 4 deletions geoconnect/apps/worldmap_connect/table_join_map_maker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import json
import pprint
import logging
import requests
import sys

from django.conf import settings
#from django.core.files import File
Expand Down Expand Up @@ -327,7 +329,7 @@ def run_map_create(self):
# Prepare parameters
# --------------------------------
map_params = dict(title=self.datatable_obj.name,
abstract="Abstract for ... {0}".format(self.datatable_obj.name),
abstract=self.datatable_obj.get_abstract_for_join(),
delimiter=self.datatable_obj.delimiter,
table_attribute=self.table_attribute_for_join,
layer_name=target_layer_name,
Expand All @@ -338,7 +340,8 @@ def run_map_create(self):
#
map_params.update(self.dataverse_metadata_dict)

msg('map_params: %s' % map_params)
pp = pprint.PrettyPrinter(indent=4)
msg(pp.pprint(map_params))

# --------------------------------
# Prepare file
Expand Down Expand Up @@ -377,7 +380,7 @@ def run_map_create(self):
except:
self.add_error("Sorry! The mapping failed. (%s)" % r.text)
return False
msg('rjson: %s' % rjson)
msg('rjson: %s' % json.dumps(rjson, indent=4))

if rjson.get('success', False) is True:
self.rjson_output = rjson
Expand Down
1 change: 1 addition & 0 deletions geoconnect/apps/worldmap_connect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

url(r'^params-for-datavarse/(?P<import_success_id>\d{1,10})/$', 'show_import_success_params', name="show_import_success_params"),

url(r'^clear-jointarget-info/$', 'clear_jointarget_info', name="clear_jointarget_info"),
)
21 changes: 20 additions & 1 deletion geoconnect/apps/worldmap_connect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.contrib.auth.decorators import login_required


from apps.worldmap_connect.models import WorldMapLayerInfo
from apps.worldmap_connect.models import WorldMapLayerInfo, JoinTargetInformation
from apps.worldmap_connect.send_shapefile_service import SendShapefileService
from apps.dv_notify.metadata_updater import MetadataUpdater

Expand Down Expand Up @@ -74,3 +74,22 @@ def view_send_shapefile_to_worldmap(request, shp_md5):
print ('-' * 40)

return HttpResponseRedirect(reverse('view_shapefile_visualize_attempt', kwargs={'shp_md5': shp_md5 }))

@login_required
def clear_jointarget_info(request):
"""
For debugging, clear out any JoinTarget Information
saved from the WorldMap API
"""
if not request.user.is_superuser:
return HttpResponse('must be a superuser')

l = JoinTargetInformation.objects.all()

cnt = l.count()
if cnt == 0:
return HttpResponse('no JoinTargetInformation objects found')

l.delete()

return HttpResponse('%s JoinTargetInformation object(s) deleted' % cnt)
5 changes: 4 additions & 1 deletion geoconnect/templates/gis_tabular/test_file_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
{% endfor %}
<br />(<a href="{% url 'view_existing_map' %}">sample map</a>)
</div><!-- col -->
<div class="col-md-8"></div>
<div class="col-md-8 text-center">
<h5>debug</h5>
<a href="{% url 'clear_jointarget_info' %}" class="btn-success btn-sm" target="_blank">Clear JoinTarget info</a>
</div>
</div>

0 comments on commit 293159f

Please sign in to comment.