Repository: learningequality/kolibri

Issue:
Topic thumbnails missing
### Observed behavior

Topic thumbnails do not get properly imported in v0.7.1:
http://35.229.41.226/learn/#/topics/f9d3e0e46ea25789bbed672ff6a399ed

simpler case
http://35.229.41.226/learn/#/topics/c401c87e3cf652128fd3efaa5b3774f2



…

### Expected behavior

Thumnail for each folder to appear as in this v0.5.0 instance
http://35.196.171.6/learn/#/f9d3e0e46ea25789bbed672ff6a399ed/topics

simpler case
http://35.196.171.6/learn/#/c401c87e3cf652128fd3efaa5b3774f2/topics


### User-facing consequences

Content looks less appealing to learners.
Content on demo server looks less impressive.



### Errors and logs

Nothing in teresting in logs except an urelated WARNING about le_utils None language lookup

```
WARNING  Did not find language code None in our le_utils.constants!
WARNING:kolibri.content.api:Did not find language code None in our le_utils.constants!
INFO     Downloading data for channel id f9d3e0e46ea25789bbed672ff6a399ed
INFO:kolibri.content.management.commands.importchannel:Downloading data for channel id f9d3e0e46ea25789bbed672ff6a399ed
100%|##########| 7271424/7271424 [00:00<00:00, 17697490.24it/s]INFO     Importing ContentTag data
INFO:kolibri.content.utils.channel_import:Importing ContentTag data
INFO     Importing ContentNode_has_prerequisite data
INFO:kolibri.content.utils.channel_import:Importing ContentNode_has_prerequisite data
INFO     Importing ContentNode_related data
INFO:kolibri.content.utils.channel_import:Importing ContentNode_related data
INFO     Importing ContentNode_tags data
INFO:kolibri.content.utils.channel_import:Importing ContentNode_tags data
INFO     Importing ContentNode data
INFO:kolibri.content.utils.channel_import:Importing ContentNode data
INFO     Importing Language data
INFO:kolibri.content.utils.channel_import:Importing Language data
INFO     Importing File data
INFO:kolibri.content.utils.channel_import:Importing File data
INFO     Importing LocalFile data
INFO:kolibri.content.utils.channel_import:Importing LocalFile data
INFO     Importing AssessmentMetaData data
INFO:kolibri.content.utils.channel_import:Importing AssessmentMetaData data
INFO     Importing ChannelMetadata data
INFO:kolibri.content.utils.channel_import:Importing ChannelMetadata data
INFO     Setting availability of File objects based on LocalFile availability
INFO:kolibri.content.utils.annotation:Setting availability of File objects based on LocalFile availability
INFO     Setting availability of non-topic ContentNode objects based on File availability
INFO:kolibri.content.utils.annotation:Setting availability of non-topic ContentNode objects based on File availability
INFO     Setting availability of ContentNode objects with children for 3 levels
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for 3 levels
INFO     Setting availability of ContentNode objects with children for level 3
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 3
INFO     Setting availability of ContentNode objects with children for level 2
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 2
INFO     Setting availability of ContentNode objects with children for level 1
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 1

INFO     Setting availability of 5754 LocalFile objects based on passed in checksums
INFO:kolibri.content.utils.annotation:Setting availability of 5754 LocalFile objects based on passed in checksums
INFO     Setting availability of File objects based on LocalFile availability
INFO:kolibri.content.utils.annotation:Setting availability of File objects based on LocalFile availability
INFO     Setting availability of non-topic ContentNode objects based on File availability
INFO:kolibri.content.utils.annotation:Setting availability of non-topic ContentNode objects based on File availability
INFO     Setting availability of ContentNode objects with children for 3 levels
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for 3 levels
INFO     Setting availability of ContentNode objects with children for level 3
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 3
INFO     Setting availability of ContentNode objects with children for level 2
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 2
INFO     Setting availability of ContentNode objects with children for level 1
INFO:kolibri.content.utils.annotation:Setting availability of ContentNode objects with children for level 1
```


### Steps to reproduce

Import channel `c401c87e3cf652128fd3efaa5b3774f2` 
Observe the folder "Content Nodes" doesn't have a thumbnail.




### Context

Originally we thought it was a problem with the chef, but after re-publishing and re-importing it seems to be a Kolibri import thing.


The sqlite DB has topic thumbnails in it:
```sqlite> select * from content_file limit 10;
a5194bdf9ddd48c9b05477940861cf71|935609414c16c15f9d2ce995084e0ca2|png|1|380738|topic_thumbnail|1|1|1|529175b4246e525e8d709c66e5c4982c|
f2fdde8b060847daa9b5980505a97681|ee2d23fc70af86341739fd8bf4a0294c|png|1|434990|topic_thumbnail|1|1|1|cfd954f6d8885f1ba1ece9ccd59b5ef8|
9bf11a1983364889a3914e75b4a717a3|21d00e515ff907c1a85b1d65bae98728|png|1|424734|topic_thumbnail|1|1|1|2e8f136249475d12876dc87c94dcdcb4|
```

Studio has them:
http://studio.learningequality.org/content/storage/9/3/935609414c16c15f9d2ce995084e0ca2.png
but the same storage path on kolibridemo is a 404:
http://kolibridemo.learningequality.org/content/storage/9/3/935609414c16c15f9d2ce995084e0ca2.png





Discussion:
The issue is here: https://github.com/learningequality/kolibri/blob/develop/kolibri/content/utils/import_export_content.py#L27

We are filtering downloads by leaf nodes for some reason - so topic images are not getting captured!

Resolving patch:
diff --git a/kolibri/content/utils/import_export_content.py b/kolibri/content/utils/import_export_content.py
--- a/kolibri/content/utils/import_export_content.py
+++ b/kolibri/content/utils/import_export_content.py
@@ -6,12 +6,12 @@ def get_files_to_transfer(channel_id, node_ids, exclude_node_ids, available):
     files_to_transfer = LocalFile.objects.filter(files__contentnode__channel_id=channel_id, available=available)
 
     if node_ids:
-        leaf_node_ids = _get_leaf_node_ids(node_ids)
-        files_to_transfer = files_to_transfer.filter(files__contentnode__in=leaf_node_ids)
+        node_ids = _get_node_ids(node_ids)
+        files_to_transfer = files_to_transfer.filter(files__contentnode__in=node_ids)
 
     if exclude_node_ids:
-        exclude_leaf_node_ids = _get_leaf_node_ids(exclude_node_ids)
-        files_to_transfer = files_to_transfer.exclude(files__contentnode__in=exclude_leaf_node_ids)
+        exclude_node_ids = _get_node_ids(exclude_node_ids)
+        files_to_transfer = files_to_transfer.exclude(files__contentnode__in=exclude_node_ids)
 
     # Make sure the files are unique, to avoid duplicating downloads
     files_to_transfer = files_to_transfer.distinct()
@@ -21,10 +21,9 @@ def get_files_to_transfer(channel_id, node_ids, exclude_node_ids, available):
     return files_to_transfer, total_bytes_to_transfer
 
 
-def _get_leaf_node_ids(node_ids):
+def _get_node_ids(node_ids):
 
     return ContentNode.objects \
         .filter(pk__in=node_ids) \
         .get_descendants(include_self=True) \
-        .filter(children__isnull=True) \
         .values_list('id', flat=True)


Test patch: