Repository: learningequality/kolibri

Issue:
Unselecting topic or resource sets size to import to 0
### Observed behavior
Tested the `0.13.0b2` release on Windows 7. Importing full channels works OK, but as soon as one subtopic or resource checkbox is unchecked, the total size of the content selected drops to zero ~(number is still apparently accurate)~, the number is inaccurate (104+55+14=173, not 219), and the subsequent import fails immediately, labeled as `Finished`.

![2019-11-26_10-54-17](https://user-images.githubusercontent.com/1457929/69619908-af19b080-103c-11ea-9284-e2c5f319bace.png)


### Expected behavior
Size of the granular import correctly recalculated, and successful import.

### User-facing consequences
Impossibility to deselect and import just the selected content. 

### Errors and logs
Nothing observable in the logs.

### Steps to reproduce

* select all
* then, unselect a topic

### Context

 * Kolibri version: 0.13.0b2 release
 * Operating system: Windows 7
 * Browser: Firefox & Chrome




Discussion:
@rtibbles The CalculateImportExportSizeView does seem to have some inaccuracies in calculating sizes when the 'excluded' array is non empty. Here's an example similar to Radina's:

http://localhost:8000/en/device/#/content/channels/a9b25ac9814742c883ce1b0579448337?node_id=89a3c0a53c874eb48d0191f4cb910b0d

(Also note that # resources is 5 on bottom, when sum of two topics should be 2, only 1 resource per topic)

![Screen Shot 2019-11-26 at 12 43 54 PM](https://user-images.githubusercontent.com/10248067/69671207-69fc7b00-104a-11ea-87bd-1e0a3762d598.png)

```
Request:
channel_id: "a9b25ac9814742c883ce1b0579448337"
exclude_node_ids: ["147e935ea467406dbb248ebf2b8cbbf7"] <- one subtopic of '...b0d'
node_ids: ["89a3c0a53c874eb48d0191f4cb910b0d"] <- the whole topic 

Response: 
{"resource_count":5,"file_size":0} <- 0 bytes
```
Also noticing that if I try to `print` `nodes_for_transfer` with `exclude_node_ids` non-empty, I get a 'IndexError: list index out of range' error, (The array prints fine if you don't exclude anything).

(e.g. add a print statement around here)

https://github.com/learningequality/kolibri/blob/56d6988b467b213dda0fb56a61d3d3df21a85569/kolibri/plugins/device/api.py#L128-L137

Resolving patch:
diff --git a/kolibri/core/content/utils/import_export_content.py b/kolibri/core/content/utils/import_export_content.py
--- a/kolibri/core/content/utils/import_export_content.py
+++ b/kolibri/core/content/utils/import_export_content.py
@@ -57,8 +57,8 @@ def get_nodes_to_transfer(
             pk__in=exclude_node_ids
         ).get_descendants(include_self=True)
 
-        nodes_to_include = nodes_to_include.order_by().difference(
-            nodes_to_exclude.order_by()
+        nodes_to_include = nodes_to_include.order_by().exclude(
+            pk__in=nodes_to_exclude.values("pk")
         )
 
     # By default don't filter node ids by their underlying file importability


Test patch:
diff --git a/kolibri/plugins/device/test/test_api.py b/kolibri/plugins/device/test/test_api.py
--- a/kolibri/plugins/device/test/test_api.py
+++ b/kolibri/plugins/device/test/test_api.py
@@ -299,7 +299,7 @@ def test_include_exclude_nodes_studio(self):
             },
             format="json",
         )
-        self.assertEqual(response.data["resource_count"], 3)
+        self.assertEqual(response.data["resource_count"], 0)
         self.assertEqual(response.data["file_size"], 0)
 
     def test_all_nodes_present_export(self):