Repository: translate/pootle

Issue:
Manage command to get a list of contributors
We need to be able to credit translators for version control commits.  For now we're not interested in more than knowing the information and leaving it to tools to use that information in commit messages.

The command should do the following:
1. Allow us to get a count `--count` so that we'd know if we can attribute this commit to one person or a group of people.
2. Specify a project and language - so that we can limit the information to one "domain" and commit
3. Give a range.  Which is likely either a time period of a revision count.  So `--from-revision` as we'll likely know what was the last revision we looked at before this commit.

Ideally data output is just text that we can use in our outside automation:

```
$ ./manage.py attribution --count --project=firefox --language=af
1
```

```
$ ./manage.py attribution --project=firefox --language=af
Dwayne Bailey <dwayne@translate.org.za>
```

Multiple contributors in a period would do the following

```
$ ./manage.py attribution --project=firefox --language=af
Dwayne Bailey <dwayne@translate.org.za>
A Nother <another@example.com>
```

We leave it to the outside scripts to use this information to make attribution,



Discussion:
I can take this one, please @dwaynebailey let me know

@codeadict Go ahead.


Resolving patch:
diff --git a/pootle/apps/pootle_app/management/commands/contributors.py b/pootle/apps/pootle_app/management/commands/contributors.py
new file mode 100644
--- /dev/null
+++ b/pootle/apps/pootle_app/management/commands/contributors.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) Pootle contributors.
+#
+# This file is a part of the Pootle project. It is distributed under the GPL3
+# or later license. See the LICENSE file for a copy of the license and the
+# AUTHORS file for copyright and authorship information.
+
+import os
+os.environ["DJANGO_SETTINGS_MODULE"] = "pootle.settings"
+
+from collections import Counter
+from optparse import make_option
+from django.contrib.auth import get_user_model
+from pootle_app.management.commands import PootleCommand
+from pootle_store.models import Unit
+
+
+User = get_user_model()
+
+
+class Command(PootleCommand):
+    option_list = PootleCommand.option_list + (
+        make_option("--from-revision", type=int, default=0, dest="revision",
+                    help="Only count contributions newer than this revision"),
+    )
+
+    help = "Print a list of contributors."
+
+    def handle_all(self, **options):
+        system_user = User.objects.get_system_user()
+        units = Unit.objects.exclude(submitted_by=system_user).exclude(submitted_by=None)
+
+        if options["revision"]:
+            units = units.filter(revision__gte=options["revision"])
+
+        if self.projects:
+            units = units.filter(store__translation_project__project__code__in=self.projects)
+
+        if self.languages:
+            units = units.filter(store__translation_project__language__code__in=self.languages)
+
+        contribs = Counter()
+        for v in units.values("submitted_by"):
+            contribs.update((v["submitted_by"], ))
+
+        self.list_contributions(contribs)
+
+    def list_contributions(self, contribs):
+        for id, count in contribs.items():
+            user = User.objects.get(id=id)
+            name = user.display_name
+            if user.email:
+                name += " <%s>" % (user.email)
+            self.stdout.write("%s (%i contributions)" % (name, count))


Test patch: