Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Multifile upload support #20

Merged
27 commits merged into from
Sep 26, 2016
Merged

Multifile upload support #20

27 commits merged into from
Sep 26, 2016

Conversation

sarasafavi
Copy link

Reference @bitner's original PR at GeoNode#39

Adds "multifile" support to the upload process: now, multiple files can be selected after clicking "choose file(s)" on the "Add data" page. This allows upload of multiple layers at once, as well as uploading of unzipped shapefiles. A single upload can include any number of files in any mix of (supported) formats.

I've also removed the outdated list of "Valid file types" from the "Add data" page's template (ref: #19). This is equivalent to Exchange's current default importer (that is, no explicit list of supported file types is shown to the user at this point in the upload process), which seems acceptable at this point in development.

@sarasafavi sarasafavi changed the title Multiform Multifile upload support Sep 22, 2016
@ghost
Copy link

ghost commented Sep 23, 2016

This is exciting but I'm too tired to review it tonight, tomorrow we'll dig in more and exercise it


if self.json:
return self.render_to_json_response({'state': upload.state, 'id': upload.id})
return self.render_to_json_response({'state': upload.state, 'id': upload.id, 'count': UploadFile.objects.filter(upload=upload.id).count()})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely my ignorance, but I want to understand why 'count' is being added to this response. If it is not being specifically needed by any frontends, I'd rather not include it because making it public API means we can't really remove it, and I'm nervous about what happens if the table is large (table scan hanging the view?)

return sizeof_fmt(self.size)

def file_url(self):
"""
Exposes the file url.
"""
return self.uploadfile_set.first().file.url
return '' # self.uploadfile_set.first().file.url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used? I'd personally rather remove the method and in that way cleanly break existing API than start returning something which may cause silent or confusing failures.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this may be used in osgeo_importer/static/osgeo_importer/partials/upload.html around line 108. Can we check whether this breaks the Download link in the UI? If so, maybe we need to just delete it, or is there some other way we should support it (e.g. multiple download links)?

@@ -48,9 +48,6 @@ <h2 class="page-title">{% trans "Add data" %}</h2>
<i class="fa fa-warning"> {{ error|escape }}</i>
{% endfor %}
</div>
<div class="col-md-6" style="padding-top: 5px; padding-left: 2px;">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not need for this information? We could generate it using values defined in python if we wanted.

Copy link
Author

@sarasafavi sarasafavi Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment about this in the PR description -- essentially 1) removing it puts us in the same state as current (non-osgeo) importer, so it's not truly a UX regression; 2) yep we should be generating it dynamically based on values defined elsewhere to avoid stale markup (ref: #19)

see below comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard my previous comment; forgot https://github.com/sarasafavi/django-osgeo-importer/blob/749c9561168df36cc2ca363bd26911b920909c4d/osgeo_importer_prj/settings.py#L83 was in here now, so I'll update shortly with a fix incorporating that settings var

Copy link
Author

@sarasafavi sarasafavi Sep 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harts-boundless this is resolved at 39522d2 but I don't know how to kill this comment thread because new-GitHub is silly... so, FYI

@ghost
Copy link

ghost commented Sep 23, 2016

My feedback on this is pretty trivial, I think it looks good.

I think we should improve test coverage beyond this, but I don't think that should be a barrier to merge

@sarasafavi sarasafavi force-pushed the multiform branch 2 times, most recently from 69b78f5 to ac5fe5f Compare September 23, 2016 21:40
Sasha Hart and others added 8 commits September 25, 2016 19:04
variable name: b -> bundle
and other variable names:
uploadid -> upload_id, uploadobj -> upload_obj, cnt -> count
uf -> uploadfile

make import_layer explicitly take pk kwarg:
since this method is only using kwargs to get pk, we might as well extract pk
early and default it to None instead of using kwargs.get.
I actually would prefer pk to be a required arg and to dispense with **kwargs,
so we have a real signature that can check us when we make mistakes; but that
will have to depend on an analysis of where these methods are used

pass request as Bundle arg instead of setting attr after
This can help a little to make uploads more distinguishable when they don't
have different names.
also permit null file_size for UploadedData.
Sometimes an upload doesn't have a size (maybe it didn't finish uploading).
In that case, it is not really sensible to say it is 0 bytes.
It has no size.

def test_single_too_long(self):
max_length = models.UploadedData._meta.get_field('name').max_length
too_long = "ObviouslyWayWayWayWayWayWayWayWayWayWayWayWayWayWayTooLong"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

<div class="layer-upload-name"> {{layer.name}}
<div class="layer-upload-name">
<span>{{layer.name || layer.file_name}}</span>
<span ng-show="layer.name && layer.name != layer.file_name"><br>(in {{layer.file_name}})</span>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is a nice touch

Since some of the multifile and geopackage changes, it is no longer obvious
what should be the name of an upload. If it just contains one file, we can do
as before, but otherwise things can become more difficult.

The heuristics for this are a little complex, so they've been split off into
their own method and tests created just for this method.
Sasha Hart and others added 9 commits September 26, 2016 15:31
No longer possible just to assume that there is one upload file type and it is
the same file type as a layer, so we need to detect the actual file type, store
it in the database and present it to users.

- add to api
- add to UploadLayer as property
- add to UploadFile as field
- add the migration to make the column
- set it from the form processing
to api, UploadLayer, set in form processing, migration to add column.

layer.name keeps filename info that is used to import, so we can't stuff actual
layer names (e.g. from inside gpkg) there without breaking import. If we change
both, any existing databases will be storing a different kind of information in
that field, which may be confusing. We can deprecate layer.name if we need to.
Whether extensions are explicitly specified in settings, or else just
the default list of extensions is used, we should consider
importers.VALID_EXTENSIONS as canon and use that in user-facing templates
@sarasafavi
Copy link
Author

An edge-case bug has been logged at #24, but I don't see this as a blocker to getting this merged in; #24 can (and should) be worked in a separate PR

@sarasafavi
Copy link
Author

@harts-boundless reviewed your latest, looks good! I'm fine with merging if you are.

@ghost
Copy link

ghost commented Sep 26, 2016

This runs fine for me manually and all tests are passing.
Your recent additions look clean too. I'm gonna merge it.

@ghost ghost merged commit b46f4c3 into planetfederal:master Sep 26, 2016
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant