Pārlūkot izejas kodu

HUE-1087 [beeswax] Pagination on /beeswax/list_designs page broken

Romain Rigaux 12 gadi atpakaļ
vecāks
revīzija
e67a1e06a5

+ 2 - 2
apps/beeswax/src/beeswax/templates/beeswax_components.mako

@@ -175,9 +175,9 @@ ${field.label_tag() | n}
 
 <%def name="pageref(num)">
   % if hasattr(filter_params, "urlencode"):
-    href="?page=${num}&${filter_params.urlencode()}"
+    href="?q-page=${num}&${filter_params.urlencode()}"
   % else:
-    href="?page=${num}&${filter_params}"
+    href="?q-page=${num}&${filter_params}"
   % endif
 </%def>
 <%def name="prevpage(page)">

+ 1 - 6
apps/beeswax/src/beeswax/templates/describe_table.mako

@@ -165,12 +165,7 @@ ${layout.menubar(section='tables')}
             <div class="control-group">
                 ${comps.bootstrapLabel(load_form["path"])}
                 <div class="controls">
-                    ${comps.field(load_form["path"],
-                                  placeholder="/user/user_name/data_dir/file",
-                                  klass="pathChooser input-xlarge",
-                                  file_chooser=True,
-                                  show_errors=False)
-                     }
+                    ${comps.field(load_form["path"], placeholder="/user/user_name/data_dir/file", klass="pathChooser input-xlarge", file_chooser=True, show_errors=False)}
                 </div>
             </div>
 

+ 27 - 6
apps/beeswax/src/beeswax/tests.py

@@ -50,6 +50,7 @@ from beeswax.test_base import make_query, wait_for_query_to_finish, verify_histo
   BEESWAXD_TEST_PORT
 from beeswax.design import hql_query, _strip_trailing_semicolon
 from beeswax.data_export import download
+from beeswax.models import SavedQuery, QueryHistory
 from beeswax.server import dbms
 from beeswax.server.beeswax_lib import BeeswaxDataTable
 from beeswax.test_base import BeeswaxSampleProvider
@@ -655,7 +656,6 @@ for x in sys.stdin:
     resp = cli.get('/beeswax/clone_design/%s' % (design.id,))
     resp = cli.get('/beeswax/clone_design/%s' % (design.id,))
     designs = beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')[:3]
-    print designs
 
     # Delete a design
     resp = cli.get('/beeswax/delete_designs')
@@ -781,13 +781,18 @@ for x in sys.stdin:
     about whether a table is partitioned.
     """
     # Check that view works
-    resp = self.client.get("/beeswax/table/default/test/load")
-    assert_true(resp.context["form"])
+    resp = self.client.get("/beeswax/table/default/test")
+    assert_true(resp.context["load_form"])
 
     # Try the submission
-    resp = self.client.post("/beeswax/table/default/test/load", dict(path="/tmp/foo", overwrite=True))
-    assert_equal_mod_whitespace("LOAD DATA INPATH '/tmp/foo' OVERWRITE INTO TABLE `default.test`",
-        resp.context["form"].query.initial["query"])
+    try:    
+      self.client.post("/beeswax/table/default/test/load", dict(path="/tmp/foo", overwrite=True))
+    except:
+      pass
+    query = QueryHistory.objects.latest('id')
+    
+    assert_equal_mod_whitespace("LOAD DATA INPATH '/tmp/foo' OVERWRITE INTO TABLE `default.test`", query.query, resp.context)
+
     resp = self.client.post("/beeswax/table/default/test/load", dict(path="/tmp/foo", overwrite=False))
     assert_equal_mod_whitespace("LOAD DATA INPATH '/tmp/foo' INTO TABLE `default.test`",
         resp.context["form"].query.initial["query"])
@@ -1218,6 +1223,22 @@ for x in sys.stdin:
     assert_false('"><script>alert(1);</script>' in resp.content, resp.content)
     assert_true('&quot;&gt;&lt;script&gt;alert(1);&lt;/script&gt;' in resp.content, resp.content)
 
+  def test_list_design_pagination(self):
+    client = make_logged_in_client()
+
+    _make_query(client, 'SELECT', name='my query history', submission_type='Save')
+    design = SavedQuery.objects.get(name='my query history')
+  
+    for i in range(25):
+      client.get('/beeswax/clone_design/%s' % (design.id,))
+  
+    resp = client.get('/beeswax/list_designs')
+    assert_true(len(resp.context['page'].object_list) >=20)
+    resp = client.get('/beeswax/list_designs?q-page=2')
+    assert_true(len(resp.context['page'].object_list) > 1)
+  
+    SavedQuery.objects.filter(name='my query history').delete()
+
 
 def test_import_gzip_reader():
   """Test the gzip reader in create table"""

+ 3 - 3
apps/beeswax/src/beeswax/views.py

@@ -181,7 +181,7 @@ def list_designs(request):
   only the personal queries of the user will be returned (even if another user is
   specified in ``filterargs``).
   """
-  DEFAULT_PAGE_SIZE = 10
+  DEFAULT_PAGE_SIZE = 20
   app_name= get_app_name(request)
 
   if conf.SHARE_SAVED_QUERIES.get() or request.user.is_superuser:
@@ -254,7 +254,7 @@ def list_query_history(request):
     page=<n>            - Controls pagination. Defaults to 1.
     user=<name>         - Show history items from a user. Default to current user only.
                           Also accepts ':all' to show all history items.
-    type=<type>         - <type> is "report|hql", for design type. Default to show all.
+    type=<type>         - <type> is "beeswax|impala", for design type. Default to show all.
     design_id=<id>      - Show history for this particular design id.
     sort=<key>          - Sort by the attribute <key>, which is one of:
                             "date", "state", "name" (design name), and "type" (design type)
@@ -402,7 +402,7 @@ def load_table(request, database, table):
       except Exception, e:
         raise PopupException(_("Can't load the data"), detail=e)
   else:
-    raise PopupException(_('Requires a POST'), detail=e)
+    raise PopupException(_('Requires a POST'))
 
 
 def describe_partitions(request, database, table):