Commits

Diego Búrigo Zacarão committed 3e78b45

Made component option should_calculate work properly

- Now if a component has should_calculate=False the stats
calculation for it will be skipped.
- Old stats are still displayed in the user interface for
earlier checkouts

  • Participants
  • Parent commits fdf4054

Comments (0)

Files changed (5)

File transifex/projects/management/commands/txstatsrefresh.py

 from exceptions import Exception
 import logging
 import os
-import traceback
 from optparse import make_option, OptionParser
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.management.base import (LabelCommand, CommandError)
         """Override default method to make it work without arguments."""
         _continue = options.get('continue')
         skip = options.get('skip')
-        verbose = options.get('verbose')
         if _continue and not os.access(os.path.dirname(__file__), os.W_OK):
             raise CommandError("Insufficient rights to resume file.")
             
                         print("Failed refreshing %s." % comp)
                         pass
                     else:
-                        if verbose:
-                            print traceback.format_exc()
                         raise CommandError("Error refreshing stats for %s. "
                             "Use --skip to ignore broken ones)." % comp)
                 if _continue and not errors.has_key(comp):
             raise CommandError("No component with full name '%s'." % comp_name)
         if verbose:
             print '- %s' % (comp.full_name)
-        comp.prepare()
-        # Calculate statistics
-        try:
-            comp.trans.set_stats()
-        except:
-            if verbose:
-                print traceback.format_exc()
-            raise CommandError("Error in setting stats for %s." % comp.full_name)
-            sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
-            sys.exit(1)
+        
+        if comp.should_calculate:
+            comp.prepare()
+            # Calculate statistics
+            try:
+                comp.trans.set_stats()
+            except:
+                raise CommandError("Error in setting stats for %s." % comp.full_name)
+                sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
+                sys.exit(1)
+        else:
+            print "Component '%s' has should_calculate=False." % comp_name

File transifex/projects/views.py

     component = get_object_or_404(Component, slug=component_slug,
                                   project__slug=project_slug)
     logger.debug("Requested stats calc for component %s" % component.full_name)
-    # Checkout
-    component.prepare()
-    # Calculate statistics
-    try:
-        component.trans.set_stats()
-    except FileFilterError:
-        logger.debug("File filter does not allow POTFILES.in file name"
-                     " for %s component" % component.full_name)
+    if component.should_calculate:
+        # Checkout
+        component.prepare()
+        # Calculate statistics
+        try:
+            component.trans.set_stats()
+        except FileFilterError:
+            logger.debug("File filter does not allow POTFILES.in file name"
+                        " for %s component" % component.full_name)
+            request.user.message_set.create(message = _(
+                "The file filter of this intltool POT-based component does not "
+                " seem to allow the POTFILES.in file. Please fix it."))
+
+        except PotDirError:
+            logger.debug("There is no 'pot' directory in the set of files. %s does "
+                        "not seem to be a Publian like project."
+                        % component.full_name)
+            request.user.message_set.create(message = _("There is no 'pot' "
+                "directory named in the set of files of this Publian like "
+                "component. Maybe its file filter is not allowing access to it."))
+
+    else:
+        logger.debug("Component %s has should_calculate=False" % component)
         request.user.message_set.create(message = _(
-            "The file filter of this intltool POT-based component does not "
-            " seem to allow the POTFILES.in file. Please fix it."))
-
-    except PotDirError:
-        logger.debug("There is no 'pot' directory in the set of files. %s does "
-                     "not seem to be a Publian like project."
-                     % component.full_name)
-        request.user.message_set.create(message = _("There is no 'pot' "
-            "directory named in the set of files of this Publian like "
-            "component. Maybe its file filter is not allowing access to it."))
+            "This component is set up for do not calculate statistics."))
 
     return HttpResponseRedirect(reverse('projects.views.component_detail', 
                                 args=(project_slug, component_slug,)))

File transifex/templates/projects/component_detail.html

 {% include "translations/stats_table_filter_box.html" %}
 
 {% with component.trans.get_stats as stats %} 
-{% comp_stats_table stats component.should_calculate %}
+{% comp_stats_table stats %}
 
 {% if component.allows_submission %}
  {% get_permission "project_perm.submit_file" for request.user and component.project as "can_submit_file" %}

File transifex/translations/templates/comp_stats_table.html

         </td>
         {% with 140 as barwidth %}
         <td class="stats" style="width: {{ barwidth|add:"2" }}px;">
-          {% if calculated %}
           <div class="stats_string_comp" title="{% trans "Trans:" %}{{stat.trans}} {% trans "Fuzzy:" %}{{stat.fuzzy}} {% trans "Untrans:" %}{{stat.untrans}}" >{{stat.trans_perc}}% <span class='trans_detail'>({{stat.trans}}/{{stat.fuzzy}}/{{stat.untrans}})<span></div> 
           {% stats_bar_full stat barwidth %}
-          {% else %}
-          <div class="compact">{% trans "(not calculated)" %}</div>
-          {% endif %}
         </td>
         {% endwith %}
         <td class="left actions">

File transifex/translations/templatetags/statistics.py

 ## Template tags
 
 @register.inclusion_tag('comp_stats_table.html', takes_context=True)
-def comp_stats_table(context, stats, calculated=True):
+def comp_stats_table(context, stats):
     """
     Create a HTML table to presents the statistics of all 
     languages for a component.
     """
     context['stats'] = key_sort(stats, 'sort_id', '-trans_perc')
-    context['calculated'] = calculated
     return context
 
 @register.inclusion_tag("project_stats_table.html")