Repository: translate/pootle

Issue:
Document the dump management command
`dump` looks like it could be useful for development.  But I'm not 100% sure what data I'm looking at when I execute it.  @ta2-1 I suspect this one might be yours.  Let me know how it works and I'll happily document it.  Or the other option is to remove it.



Discussion:

Resolving patch:
diff --git a/pootle/apps/pootle_app/management/commands/dump.py b/pootle/apps/pootle_app/management/commands/dump.py
--- a/pootle/apps/pootle_app/management/commands/dump.py
+++ b/pootle/apps/pootle_app/management/commands/dump.py
@@ -18,7 +18,8 @@
 
 from optparse import make_option
 
-from pootle.core.utils.json import jsonify
+from django.core.management.base import CommandError
+
 from pootle_app.management.commands import PootleCommand
 from pootle_app.models import Directory
 from pootle_project.models import Project
@@ -56,10 +57,15 @@ def handle_all(self, **options):
             stats = options.get('stats', False)
             data = options.get('data', False)
             stop_level = int(options.get('stop_level', -1))
+
             if stats:
                 self.dump_stats(stop_level=stop_level)
+                return
             if data:
                 self.dump_all(stop_level=stop_level)
+                return
+
+            raise CommandError("Set --data or --stats option.")
         else:
             super(Command, self).handle_all(**options)
 
@@ -70,25 +76,19 @@ def handle_translation_project(self, tp, **options):
         if stats:
             res = {}
             self._dump_stats(tp.directory, res, stop_level=stop_level)
+            return
 
-            stats_dump = jsonify(res)
-            self.stdout.write(stats_dump)
         if data:
             self._dump_item(tp.directory, 0, stop_level=stop_level)
+            return
+
+        raise CommandError("Set --data or --stats option.")
 
     def dump_stats(self, stop_level):
         res = {}
         for prj in Project.objects.all():
             self._dump_stats(prj, res, stop_level=stop_level)
 
-        for key, item in res.items():
-            out = u"%s  %s,%s,%s,%s,%s,%s,%s,%s" % \
-                  (key, item['total'], item['translated'], item['fuzzy'],
-                   item['suggestions'], item['critical'], item['is_dirty'],
-                   item['lastaction']['id'], item['lastupdated']['id'])
-
-            self.stdout.write(out)
-
     def _dump_stats(self, item, res, stop_level):
         key = item.get_cachekey()
         item.initialize_children()
@@ -102,6 +102,24 @@ def _dump_stats(self, item, res, stop_level):
 
         res[key] = (item.get_stats(include_children=False))
 
+        if res[key]['lastaction']:
+            last_action_id = res[key]['lastaction']['id']
+        else:
+            last_action_id = None
+
+        if res[key]['lastupdated']:
+            last_updated_id = res[key]['lastupdated']['id']
+        else:
+            last_updated_id = None
+
+        out = u"%s  %s,%s,%s,%s,%s,%s,%s,%s" % \
+              (key, res[key]['total'], res[key]['translated'],
+               res[key]['fuzzy'], res[key]['suggestions'],
+               res[key]['critical'], res[key]['is_dirty'],
+               last_action_id, last_updated_id)
+
+        self.stdout.write(out)
+
     def dump_all(self, stop_level):
         root = Directory.objects.root
         self._dump_item(root, 0, stop_level=stop_level)


Test patch: