Repository: oppia/oppia

Issue:
Add paging to the list of commits in the exploration history tab
```
In as much detail as possible, please describe what you would like to see.

For explorations that have many versions, it would be nice to be able to page 
through them in order to see older versions -- currently, the history tab only 
shows the latest 30. We should generalize the existing paging infrastructure so 
that users can do this.

```

Original issue reported on code.google.com by `s...@seanlip.org` on 17 Aug 2014 at 7:54



Discussion:
/cc @wxyxinyu 

@kvharish, would you like to tackle this?

To reproduce: create an exploration and go to the history tab. You'll see that there are only 30 revisions shown at most, with no allowance for paging. The aim of this issue is to add support for paging.

Please let us know if you have any questions, and thanks!

Sure @seanlip I would like to give it a try and see how it goes. Thanks.

Hi @kvharish, how's this going? Just so you know, if you'd like to start with something easier, I'd also be happy to suggest an alternative project.

Thanks!


Resolving patch:
diff --git a/core/controllers/editor.py b/core/controllers/editor.py
--- a/core/controllers/editor.py
+++ b/core/controllers/editor.py
@@ -683,10 +683,12 @@ def get(self, exploration_id):
             raise self.PageNotFoundException
 
         # Patch `snapshots` to use the editor's display name.
-        for snapshot in snapshots:
-            if snapshot['committer_id'] != feconf.SYSTEM_COMMITTER_ID:
-                snapshot['committer_id'] = user_services.get_username(
-                    snapshot['committer_id'])
+        snapshots_committer_ids = [
+            snapshot['committer_id'] for snapshot in snapshots]
+        committer_usernames = user_services.get_usernames(
+            snapshots_committer_ids)
+        for index, snapshot in enumerate(snapshots):
+            snapshot['committer_id'] = committer_usernames[index]
 
         self.render_json({
             'snapshots': snapshots,
diff --git a/core/domain/user_services.py b/core/domain/user_services.py
--- a/core/domain/user_services.py
+++ b/core/domain/user_services.py
@@ -41,7 +41,10 @@
 # Generated using utils.convert_png_to_data_url
 DEFAULT_IDENTICON_DATA_URL = (
     'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEwAAABMCAYAAADHl1ErAAAAAXNSR0IArs4c6QAADhtJREFUeAHt%0AXHlwVdUZ/859jyxmIQESyCaglC0iAgkJIntrIpvKphSwY2ttxbFOp9R/cGGqdhykLaMVO2OtoyRS%0ACEKNEp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ayQWf/S8b7b%0AHobC3QWYrv3rZ%2BwuXuhIs88/Y4v8vfWz4BvrdoBpj4BBejWE2W4/yupTGMJ%2BD21O/emf3j1t2bTN%0ArYD8PgWkv7/FflvUwE8uFFelMAg2i8Uy05UTBlwCTAWtLUieJ8XA2MiQIxXX6xNYI%2B6XC3Wep%2Br5%0Axz/Jsszij1qDVREprp4s4DJgGmjaMQzcUA5bgaNkRTbH3GxSf5SEVMoxRBUMlrnHMIB//Arounxb%0AjgZZuWWtSzlokmyGkwWv4Bm8QwZ1GLpxZgUYcquHaRLgQ6A/SobJ4IiGpeyc7RE9ja55V/aKEOID%0A5s/3R8loQjkeVsTzwmmeF2oYuFlamT5xFeII/4qh3LMmgR/oWT4/rEgPhONxWEKifUJW4mWikfpy%0Avr5nBbNIkUQeD8BU7lm9fxyWHgDHA9fYQlzHg/0w/6qjuZzqdKwvb/J9PveiAl4Hz%2BE5q%2B8duKYX%0AHjHSjkf6sXkqWyEZK4QFLIQ51iihWrr2CJKCeE6fzm2pax8Grm8e6acHDffth0YSLdF9CCoZvFye%0A55okRU7gIetV1AkPuRJZSCfZUdefezJMYf3v0MhOwHVzLKlQxAWSRJlQlDr%2BzrPcUjjbGwbyBB2m%0ACKH62/K7KwywjWM8b5CQq%2BH9x%2B%2BCSVZiFKH8eI4ldQQOz4jJ/P/Bt86QcSFPPVqZA50Qu4NwFK7i%0A3tHK7HEEJ5reOFr5fwkK97jkk8ywAAAAAElFTkSuQmCC%0A') #pylint: disable=line-too-long
-
+SYSTEM_USERS = {
+    feconf.SYSTEM_COMMITTER_ID: feconf.SYSTEM_COMMITTER_ID,
+    feconf.MIGRATION_BOT_USER_ID: feconf.MIGRATION_BOT_USERNAME
+}
 
 class UserSettings(object):
     """Value object representing a user's settings.
@@ -696,10 +699,10 @@ def get_username(user_id):
     Returns:
         str. Username corresponding to the given user_id.
     """
-    if user_id == feconf.MIGRATION_BOT_USER_ID:
-        return feconf.MIGRATION_BOT_USERNAME
-    else:
-        return get_user_settings(user_id, strict=True).username
+    if user_id in SYSTEM_USERS:
+        return SYSTEM_USERS[user_id]
+
+    return get_user_settings(user_id, strict=True).username
 
 
 def get_usernames(user_ids):
@@ -713,8 +716,23 @@ def get_usernames(user_ids):
         If a user_id does not exist, the corresponding entry in the
         returned list is None.
     """
-    users_settings = get_users_settings(user_ids)
-    return [us.username if us else None for us in users_settings]
+    usernames = [None] * len(user_ids)
+    non_system_user_indices = []
+    non_system_user_ids = []
+    for index, user_id in enumerate(user_ids):
+        if user_id in SYSTEM_USERS:
+            usernames[index] = SYSTEM_USERS[user_id]
+        else:
+            non_system_user_indices.append(index)
+            non_system_user_ids.append(user_id)
+
+    non_system_users_settings = get_users_settings(non_system_user_ids)
+
+    for index, user_settings in enumerate(non_system_users_settings):
+        if user_settings:
+            usernames[non_system_user_indices[index]] = user_settings.username
+
+    return usernames
 
 
 # NB: If we ever allow usernames to change, update the


Test patch:
diff --git a/core/domain/user_services_test.py b/core/domain/user_services_test.py
--- a/core/domain/user_services_test.py
+++ b/core/domain/user_services_test.py
@@ -47,6 +47,35 @@ def test_set_and_get_username(self):
         user_services.set_username(user_id, username)
         self.assertEquals(username, user_services.get_username(user_id))
 
+    def test_get_username_for_system_user(self):
+        self.assertEqual(
+            feconf.SYSTEM_COMMITTER_ID,
+            user_services.get_username(feconf.SYSTEM_COMMITTER_ID))
+        self.assertEqual(
+            feconf.MIGRATION_BOT_USERNAME,
+            user_services.get_username(feconf.MIGRATION_BOT_USER_ID))
+
+    def test_get_usernames(self):
+        user_ids = ['test1', feconf.SYSTEM_COMMITTER_ID, 'test2']
+        usernames = ['name1', feconf.SYSTEM_COMMITTER_ID, 'name2']
+        user_emails = [
+            'test1@email.com', feconf.SYSTEM_EMAIL_ADDRESS, 'test2@email.com']
+
+        for uid, email, name in zip(user_ids, user_emails, usernames):
+            if uid != feconf.SYSTEM_COMMITTER_ID:
+                user_services.create_new_user(uid, email)
+                user_services.set_username(uid, name)
+        # Handle usernames that exists.
+        self.assertEqual(usernames, user_services.get_usernames(user_ids))
+
+        # Return empty list when no user id passed.
+        self.assertEqual([], user_services.get_usernames([]))
+
+        # Return None for usernames that don't exists.
+        self.assertEqual(
+            [None, 'name1'],
+            user_services.get_usernames(['fakeUser', 'test1']))
+
     def test_get_username_for_nonexistent_user(self):
         with self.assertRaisesRegexp(Exception, 'User not found.'):
             user_services.get_username('fakeUser')