Эх сурвалжийг харах

[beeswax] Do not use lazy string extraction in views

Romain Rigaux 13 жил өмнө
parent
commit
6bcf8bc75c

+ 5 - 0
apps/beeswax/src/beeswax/tests.py

@@ -778,6 +778,11 @@ for x in sys.stdin:
     Test installation of examples
     """
     assert_true(not beeswax.models.MetaInstall.get().installed_example)
+
+    # Check popup
+    resp = self.client.get('/beeswax/install_examples')
+    assert_true('Install sample tables' in resp.content)
+
     self.client.post('/beeswax/install_examples')
 
     # New tables exists

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

@@ -54,7 +54,7 @@ from jobsub.parameterization import find_variables, substitute_variables
 
 from filebrowser.views import location_to_url
 
-from django.utils.translation import ugettext_lazy as _t
+from django.utils.translation import ugettext as _
 
 LOG = logging.getLogger(__name__)
 
@@ -66,13 +66,13 @@ def authorized_get_design(request, design_id, owner_only=False, must_exist=False
     design = models.SavedQuery.objects.get(id=design_id)
   except models.SavedQuery.DoesNotExist:
     if must_exist:
-      raise PopupException(_t('Design %(id)s does not exist.') % {'id': design_id})
+      raise PopupException(_('Design %(id)s does not exist.') % {'id': design_id})
     else:
       return None
 
   if not conf.SHARE_SAVED_QUERIES.get() and (not request.user.is_superuser or owner_only) \
       and design.owner != request.user:
-    raise PopupException(_t('Cannot access design %(id)s') % {'id': design_id})
+    raise PopupException(_('Cannot access design %(id)s') % {'id': design_id})
   else:
     return design
 
@@ -83,13 +83,13 @@ def authorized_get_history(request, query_history_id, owner_only=False, must_exi
     query_history = models.QueryHistory.objects.get(id=query_history_id)
   except models.QueryHistory.DoesNotExist:
     if must_exist:
-      raise PopupException(_t('QueryHistory %(id)s does not exist.') % {'id': query_history_id})
+      raise PopupException(_('QueryHistory %(id)s does not exist.') % {'id': query_history_id})
     else:
       return None
 
   if not conf.SHARE_SAVED_QUERIES.get() and (not request.user.is_superuser or owner_only) \
       and query_history.owner != request.user:
-    raise PopupException(_t('Cannot access QueryHistory %(id)s') % {'id': query_history_id})
+    raise PopupException(_('Cannot access QueryHistory %(id)s') % {'id': query_history_id})
   else:
     return query_history
 
@@ -145,9 +145,9 @@ def drop_table(request, table):
     # but this was introduced in Hive 0.5, and therefore may not be available
     # with older metastores.
     if is_view:
-      title = _t("Do you really want to drop the view '%(table)s'?") % {'table': table}
+      title = _("Do you really want to drop the view '%(table)s'?") % {'table': table}
     else:
-      title = _t("This may delete the underlying data as well as the metadata.  Drop table '%(table)s'?") % {'table': table}
+      title = _("This may delete the underlying data as well as the metadata.  Drop table '%(table)s'?") % {'table': table}
     return render('confirm.html', request, dict(url=request.path, title=title))
   elif request.method == 'POST':
     if is_view:
@@ -162,8 +162,8 @@ def drop_table(request, table):
     except BeeswaxException, ex:
       # Note that this state is difficult to get to.
       error_message, log = expand_exception(ex)
-      error = _t("Failed to remove %(table)s.  Error: %(error)s") % {'table': table, 'error': error_message}
-      raise PopupException(error, title=_t("Beeswax Error"), detail=log)
+      error = _("Failed to remove %(table)s.  Error: %(error)s") % {'table': table, 'error': error_message}
+      raise PopupException(error, title=_("Beeswax Error"), detail=log)
 
 
 def read_table(request, table):
@@ -176,8 +176,8 @@ def read_table(request, table):
   except BeeswaxException, e:
     # Note that this state is difficult to get to.
     error_message, log = expand_exception(e)
-    error = _t("Failed to read table. Error: %(error)s") % {'error': error_message}
-    raise PopupException(error, title=_t("Beeswax Error"), detail=log)
+    error = _("Failed to read table. Error: %(error)s") % {'error': error_message}
+    raise PopupException(error, title=_("Beeswax Error"), detail=log)
 
 
 def confirm_query(request, query, on_success_url=None):
@@ -230,7 +230,7 @@ def safe_get_design(request, design_type, design_id=None):
     try:
       design = models.SavedQuery.get(design_id, request.user, design_type)
     except models.SavedQuery.DoesNotExist:
-      messages.error(request, _t('Design does not exist'))
+      messages.error(request, _('Design does not exist'))
   if design is None:
     design = models.SavedQuery(owner=request.user, type=design_type)
   return design
@@ -452,7 +452,7 @@ def _run_parameterized_query(request, design_id, explain):
   query_str = _strip_trailing_semicolon(query_form.query.cleaned_data["query"])
   parameterization_form_cls = make_parameterization_form(query_str)
   if not parameterization_form_cls:
-    raise PopupException(_t("Query is not parameterizable."))
+    raise PopupException(_("Query is not parameterizable."))
   parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")
   if parameterization_form.is_valid():
     real_query = substitute_variables(query_str, parameterization_form.cleaned_data)
@@ -480,9 +480,9 @@ def expand_exception(exc):
     log = db_utils.db_client().get_log(exc.log_context)
   except:
     # Always show something, even if server has died on the job.
-    log = _t("Could not retrieve log.")
+    log = _("Could not retrieve log.")
   if not exc.message:
-    error_message = _t("Unknown exception.")
+    error_message = _("Unknown exception.")
   else:
     error_message = force_unicode(exc.message, strings_only=True, errors='replace')
   return error_message, log
@@ -515,7 +515,7 @@ def save_design(request, form, type, design, explicit_save):
   elif type == models.SavedQuery.REPORT:
     design_cls = beeswax.report.ReportDesign
   else:
-    raise ValueError(_t('Invalid design type %(type)s') % {'type': type})
+    raise ValueError(_('Invalid design type %(type)s') % {'type': type})
 
   old_design = design
   design_obj = design_cls(form)
@@ -543,7 +543,7 @@ def save_design(request, form, type, design, explicit_save):
   LOG.info('Saved %sdesign "%s" (id %s) for %s' %
            (explicit_save and '' or 'auto ', design.name, design.id, design.owner))
   if explicit_save:
-    messages.error(request, _t('Saved design "%(name)s"') % {'name': design.name})
+    messages.error(request, _('Saved design "%(name)s"') % {'name': design.name})
   # Design may now have a new/different id
   return design
 
@@ -677,7 +677,7 @@ def clone_design(request, design_id):
   copy.name = design.name + ' (copy)'
   copy.owner = request.user
   copy.save()
-  messages.error(request, _t('Copied design: %(name)s') % {'name': design.name})
+  messages.error(request, _('Copied design: %(name)s') % {'name': design.name})
   return format_preserving_redirect(
       request, urlresolvers.reverse(execute_query, kwargs={'design_id': copy.id}))
 
@@ -729,14 +729,14 @@ def query_done_cb(request, server_id):
     return res
   design = history.design
   user = history.owner
-  subject = _t("Beeswax query completed")
+  subject = _("Beeswax query completed")
   if design:
     subject += ": %s" % (design.name,)
 
   link = "%s/#launch=Beeswax:%s" % \
             (get_desktop_uri_prefix(),
              urlresolvers.reverse(watch_query, kwargs={'id': history.id}))
-  body = _t("%(subject)s. You may see the results here: %(link)s\n\nQuery:\n%(query)s") % {'subject': subject, 'link': link, 'query': history.query}
+  body = _("%(subject)s. You may see the results here: %(link)s\n\nQuery:\n%(query)s") % {'subject': subject, 'link': link, 'query': history.query}
   try:
     user.email_user(subject, body)
   except Exception, ex:
@@ -782,7 +782,7 @@ def watch_query(request, id):
 
   # Query finished?
   if state == models.QueryHistory.STATE.expired:
-    raise PopupException(_t("The result of this query has expired."))
+    raise PopupException(_("The result of this query has expired."))
   elif state == models.QueryHistory.STATE.available:
     return format_preserving_redirect(request, on_success_url, request.GET)
   elif state == models.QueryHistory.STATE.failed:
@@ -828,12 +828,12 @@ def _get_server_id_and_state(query_history):
   ok, server_id = query_history.get_server_id()
   if not server_id:
     if ok:
-      raise PopupException(_t("Query is still being submitted to the Beeswax Server."))
-    raise PopupException(_t("Failed to retrieve query state from the Beeswax Server."))
+      raise PopupException(_("Query is still being submitted to the Beeswax Server."))
+    raise PopupException(_("Failed to retrieve query state from the Beeswax Server."))
 
   state = db_utils.get_query_state(query_history)
   if state is None:
-    raise PopupException(_t("Failed to contact Beeswax Server to check query status."))
+    raise PopupException(_("Failed to contact Beeswax Server to check query status."))
   return (server_id, state)
 
 
@@ -899,7 +899,7 @@ def view_results(request, id, first_row=0):
   # Retrieve query results
   try:
     results = db_utils.db_client().fetch(handle, start_over, -1)
-    assert results.ready, _t('Trying to display result that is not yet ready. Query id %(id)s') % {'id': id}
+    assert results.ready, _('Trying to display result that is not yet ready. Query id %(id)s') % {'id': id}
     # We display the "Download" button only when we know
     # that there are results:
     downloadable = (first_row > 0 or len(results.data) > 0)
@@ -956,8 +956,8 @@ def save_results(request, id):
   id = int(id)
   query_history = models.QueryHistory.objects.get(id=id)
   if query_history.owner != request.user:
-    raise PopupException(_t('This action is only available to the user who submitted the query.'))
-  _, state = _get_server_id_and_state(query_history)
+    raise PopupException(_('This action is only available to the user who submitted the query.'))
+  server_id, state = _get_server_id_and_state(query_history)
   query_history.save_state(state)
   error_msg, log = None, None
 
@@ -966,9 +966,9 @@ def save_results(request, id):
     # Note that we may still hit errors during the actual save
     if state != models.QueryHistory.STATE.available:
       if state in (models.QueryHistory.STATE.failed, models.QueryHistory.STATE.expired):
-        msg = _t('This query has %(state)s. Results unavailable.') % {'state': state}
+        msg = _('This query has %(state)s. Results unavailable.') % {'state': state}
       else:
-        msg = _t('The result of this query is not available yet.')
+        msg = _('The result of this query is not available yet.')
       raise PopupException(msg)
 
     form = beeswax.forms.SaveResultsForm(request.POST)
@@ -985,20 +985,20 @@ def save_results(request, id):
         result_meta = db_utils.db_client().get_results_metadata(handle)
       except QueryNotFoundException, ex:
         LOG.exception(ex)
-        raise PopupException(_t('Cannot find query.'))
+        raise PopupException(_('Cannot find query.'))
       if result_meta.table_dir:
         result_meta.table_dir = request.fs.urlsplit(result_meta.table_dir)[2]
 
       # 2. Check for partitioned tables
       if result_meta.table_dir is None:
-        raise PopupException(_t('Saving results from a partitioned table is not supported. You may copy from the HDFS location manually.'))
+        raise PopupException(_('Saving results from a partitioned table is not supported. You may copy from the HDFS location manually.'))
 
       # 3. Actual saving of results
       try:
         if form.cleaned_data['save_target'] == form.SAVE_TYPE_DIR:
           # To dir
           if result_meta.in_tablename:
-            raise PopupException(_t('Saving results from a table to a directory is not supported. You may copy from the HDFS location manually.'))
+            raise PopupException(_('Saving results from a table to a directory is not supported. You may copy from the HDFS location manually.'))
           target_dir = form.cleaned_data['target_dir']
           request.fs.rename_star(result_meta.table_dir, target_dir)
           LOG.debug("Moved results from %s to %s" % (result_meta.table_dir, target_dir))
@@ -1015,7 +1015,7 @@ def save_results(request, id):
             LOG.exception(bex)
             error_msg, log = expand_exception(bex)
       except WebHdfsException, ex:
-        raise PopupException(_t('The table could not be saved.'), detail=ex)
+        raise PopupException(_('The table could not be saved.'), detail=ex)
       except IOError, ex:
         LOG.exception(ex)
         error_msg = str(ex)
@@ -1023,7 +1023,7 @@ def save_results(request, id):
     form = beeswax.forms.SaveResultsForm()
 
   if error_msg:
-    error_msg = _t('Failed to save results from query: %(error)s') % {'error': error_msg}
+    error_msg = _('Failed to save results from query: %(error)s') % {'error': error_msg}
   return render('save_results.mako', request, dict(
     action=urlresolvers.reverse(save_results, kwargs={'id': str(id)}),
     form=form,
@@ -1080,7 +1080,7 @@ def _save_results_ctas(request, query_history, target_table, result_meta):
     table_loc = request.fs.urlsplit(table_obj.sd.location)[2]
     request.fs.rename_star(result_meta.table_dir, table_loc)
     LOG.debug("Moved results from %s to %s" % (result_meta.table_dir, table_loc))
-    messages.error(request, _t('Saved query results as new table %(table)s') % {'table': target_table})
+    messages.error(request, _('Saved query results as new table %(table)s') % {'table': target_table})
     query_history.save_state(models.QueryHistory.STATE.expired)
   except Exception, ex:
     LOG.error('Error moving data into storage of table %s. Will drop table.' % (target_table,))
@@ -1132,7 +1132,7 @@ def install_examples(request):
   """
   if request.method == 'GET':
     return render('confirm.html', request,
-                  dict(url=request.path, title=_t('Install sample tables and Beeswax examples?')))
+                  dict(url=request.path, title=_('Install sample tables and Beeswax examples?')))
   elif request.method == 'POST':
     result = {}
     result['creationSucceeded'] = False
@@ -1151,7 +1151,7 @@ def install_examples(request):
 def describe_partitions(request, table):
   table_obj = db_utils.meta_client().get_table("default", table)
   if len(table_obj.partitionKeys) == 0:
-    raise PopupException(_t("Table '%(table)s' is not partitioned.") % {'table': table})
+    raise PopupException(_("Table '%(table)s' is not partitioned.") % {'table': table})
   partitions = db_utils.meta_client().get_partitions("default", table, max_parts=-1)
   return render("describe_partitions.mako", request,
                 dict(table=table_obj, partitions=partitions, request=request))