Skip to content

Commit

Permalink
Initial integration of ISA archive and metadata file imports
Browse files Browse the repository at this point in the history
  • Loading branch information
hackdna committed Jun 24, 2015
1 parent 677b422 commit a6fa7c8
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 256 deletions.
9 changes: 4 additions & 5 deletions refinery/data_set_manager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from data_set_manager.views import (
ImportISATabView, ProcessISATabView, ProcessMetadataTableView,
CheckDataFilesView, FileUploadView, ChunkedFileUploadView,
DataSetImportView, ImportISATabView, ProcessISATabView,
ProcessMetadataTableView, CheckDataFilesView, ChunkedFileUploadView,
ChunkedFileUploadCompleteView
)

Expand All @@ -26,8 +26,9 @@

url(r'^nodes/(?P<study_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(?P<assay_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(?P<type>[\w ]+)/annotate$', "node_annotate", name="data_set_manager_update_annotated_nodes" ),

url(r'^import/$', DataSetImportView.as_view(), name='import_data_set'),
url(r'^import/isa-tab/$', csrf_exempt(ImportISATabView.as_view()),
name='import_isa_tab'),
name='import_isa_tab'), # csrf_exempt required for POST requests from external sites
url(r'^import/isa-tab-form/$', login_required(ProcessISATabView.as_view()),
name='process_isa_tab'),
url(r'^contents/(?P<study_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(?P<assay_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', "contents", name="data_set_manager_contents" ),
Expand All @@ -36,8 +37,6 @@
name='process_metadata_table'),
url(r'^import/check_files/$', CheckDataFilesView.as_view(),
name='check_files'),
url(r'^import/file-upload-form/$', login_required(FileUploadView.as_view()),
name='upload_files'),
url(r'^import/chunked-upload/$',
login_required(ChunkedFileUploadView.as_view()),
name='api_chunked_upload'),
Expand Down
106 changes: 53 additions & 53 deletions refinery/data_set_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,54 +99,18 @@ def search_typeahead(request):
mimetype='application/json')


# ===============================================================================
# ISA-Tab import
#===============================================================================
class ImportISATabView(View):
'''Capture ISA archive URL from POST requests submitted from external sites
'''

def post(self, request, *args, **kwargs):
try:
isa_tab_url = request.POST['isa_tab_url']
except KeyError:
logger.error("ISA archive URL was not provided")
return HttpResponseBadRequest("Please provide an ISA archive URL")
else:
# set cookie and redirect to process_isa_tab view
response = HttpResponseRedirect(reverse('process_isa_tab'))
response.set_cookie('isa_tab_url', isa_tab_url)
return response


class ImportISATabFileForm(forms.Form):
'''ISA-Tab file upload form
# Data set import

'''
isa_tab_file = forms.FileField(label='ISA-Tab file', required=False)
isa_tab_url = forms.URLField(label='ISA-Tab URL', required=False,
widget=forms.TextInput(attrs={'size': '37'}))
class DataSetImportView(View):
"""Main view for data set importing
def clean(self):
cleaned_data = super(ImportISATabFileForm, self).clean()
f = cleaned_data.get("isa_tab_file")
url = cleaned_data.get("isa_tab_url")
# either a file or a URL must be provided
if f or url:
return cleaned_data
else:
raise forms.ValidationError("Please provide either a file or a URL")


class ProcessISATabView(View):
'''Process ISA-Tab archive
'''
template_name = 'data_set_manager/isa-tab-import.html'
"""
template_name = "data_set_manager/import.html"
success_view_name = 'data_set'
isa_tab_cookie_name = 'isa_tab_url'

# def get(self, request, *args, **kwargs):
# return render(request, self.template_name)
# a workaround for automatic ISA archive import after logging in
def get(self, request, *args, **kwargs):
try:
Expand Down Expand Up @@ -200,6 +164,52 @@ def get(self, request, *args, **kwargs):
response.delete_cookie(self.isa_tab_cookie_name)
return response


class ImportISATabView(View):
'''Capture ISA archive URL from POST requests submitted from external sites
'''

def post(self, request, *args, **kwargs):
try:
isa_tab_url = request.POST['isa_tab_url']
except KeyError:
logger.error("ISA archive URL was not provided")
return HttpResponseBadRequest("Please provide an ISA archive URL")
else:
# set cookie and redirect to process_isa_tab view
response = HttpResponseRedirect(reverse('process_isa_tab'))
response.set_cookie('isa_tab_url', isa_tab_url)
return response


class ImportISATabFileForm(forms.Form):
'''ISA-Tab file upload form
'''
isa_tab_file = forms.FileField(label='ISA-Tab file', required=False)
isa_tab_url = forms.URLField(label='ISA-Tab URL', required=False,
widget=forms.TextInput(attrs={'size': '37'}))

def clean(self):
cleaned_data = super(ImportISATabFileForm, self).clean()
f = cleaned_data.get("isa_tab_file")
url = cleaned_data.get("isa_tab_url")
# either a file or a URL must be provided
if f or url:
return cleaned_data
else:
raise forms.ValidationError("Please provide either a file or a URL")


class ProcessISATabView(View):
'''Process ISA-Tab archive
'''
template_name = 'data_set_manager/isa-tab-import.html'
success_view_name = 'data_set'
isa_tab_cookie_name = 'isa_tab_url'

def post(self, request, *args, **kwargs):
form = ImportISATabFileForm(request.POST, request.FILES)
if form.is_valid():
Expand Down Expand Up @@ -352,16 +362,6 @@ def post(self, request, *args, **kwargs):
content_type="application/json")


class FileUploadView(TemplateView):
"""Data file upload form view
"""
template_name = 'data_set_manager/import.html'

def get(self, request, *args, **kwargs):
return render(request, self.template_name)


class ChunkedFileUploadView(ChunkedUploadView):

model = ChunkedUpload
Expand Down
2 changes: 1 addition & 1 deletion refinery/templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h3><i class="icon-file m-r-1-4"></i>Data Sets</h3>
{% if user.is_authenticated and not REFINERY_REPOSITORY_MODE %}
<span class="refinery-header-right">
<h4>
<a href={% url "process_isa_tab" %} class="no-underline-hover">
<a href={% url "import_data_set" %} class="no-underline-hover">
<i class="icon-plus-sign"></i>
</a>
</h4>
Expand Down
182 changes: 0 additions & 182 deletions refinery/templates/data_set_manager/file-import.html

This file was deleted.

0 comments on commit a6fa7c8

Please sign in to comment.