Repository: learningequality/kolibri

Issue:
`kolibri manage provisiondevice` converts user-provided facility name to lower-case
### Observed behavior

In #7493, it was noted that `provisiondevice` converts facility names to lower-case, which might not be desirable.

This is probably because of this line in the code

https://github.com/learningequality/kolibri/blob/bf91a09cb7ea666f013f3488ea28d8391cefa1d1/kolibri/core/device/management/commands/provisiondevice.py#L78-L82

where `get_user_response` is the code that tries to normalize user input in the terminal (which includes converting to lower case).

### Expected behavior

When a user provides a facility name in the `provisiondevice` CLI tool, the eventual facility name matches the user's inputted facility name character-by-character. E.g. if I type "Jonathan's Facility", it doesn't convert it to "jonathan's facility"


### User-facing consequences

Facility name does not match what was provided in CLI, and admin will need to edit the name.

### Steps to reproduce


1. Use `kolibri manage provisiondevice`
1. At the new facility step, provide a name like "MY FACILITY"
1. When you actually view the Facility in Kolibri, it will have the name "my facility"


Discussion:

Resolving patch:
diff --git a/kolibri/core/device/management/commands/provisiondevice.py b/kolibri/core/device/management/commands/provisiondevice.py
--- a/kolibri/core/device/management/commands/provisiondevice.py
+++ b/kolibri/core/device/management/commands/provisiondevice.py
@@ -58,13 +58,16 @@ def check_device_setting(name):
     )
 
 
-def get_user_response(prompt, valid_answers=None):
+def get_user_response(prompt, valid_answers=None, to_lower_case=True):
     answer = None
     while not answer or (
         valid_answers is not None and answer.lower() not in valid_answers
     ):
         answer = six.moves.input(prompt)
-    return answer.lower()
+    if to_lower_case:
+        return answer.lower()
+    else:
+        return answer
 
 
 languages = dict(settings.LANGUAGES)
@@ -77,23 +80,27 @@ def create_facility(facility_name=None, preset=None, interactive=False):
         )
         if answer == "y":
             facility_name = get_user_response(
-                "What do you wish to name your facility? "
+                "What do you wish to name your facility? ", to_lower_case=False
             )
         else:
             sys.exit(1)
 
     if facility_name:
-        facility, created = Facility.objects.get_or_create(name=facility_name)
+        facility_query = Facility.objects.filter(name__iexact=facility_name)
 
-        if not created:
+        if facility_query.exists():
+            facility = facility_query.get()
             logger.warn(
-                "Facility with name {name} already exists, not modifying preset.".format(
-                    name=facility_name
+                "Facility with name '{name}' already exists, not modifying preset.".format(
+                    name=facility.name
                 )
             )
             return facility
-
-        logger.info("Facility with name {name} created.".format(name=facility_name))
+        else:
+            facility = Facility.objects.create(name=facility_name)
+            logger.info(
+                "Facility with name '{name}' created.".format(name=facility.name)
+            )
 
         if preset is None and interactive:
             preset = get_user_response(
@@ -125,7 +132,9 @@ def update_facility_settings(facility, new_settings):
         check_facility_setting(key)
         setattr(facility.dataset, key, value)
     facility.dataset.save()
-    logger.info("Facility settings updated with {}".format(new_settings))
+
+    if new_settings:
+        logger.info("Facility settings updated with {}".format(new_settings))
 
 
 def create_superuser(username=None, password=None, interactive=False, facility=None):
@@ -142,13 +151,13 @@ def create_superuser(username=None, password=None, interactive=False, facility=N
         try:
             FacilityUser.objects.create_superuser(username, password, facility=facility)
             logger.info(
-                "Superuser created with username {username} in facility {facility}.".format(
+                "Superuser created with username '{username}' in facility '{facility}'.".format(
                     username=username, facility=facility
                 )
             )
         except ValidationError:
             logger.warn(
-                "An account with username {username} already exists in facility {facility}, not creating user account.".format(
+                "An account with username '{username}' already exists in facility '{facility}', not creating user account.".format(
                     username=username, facility=facility
                 )
             )


Test patch: