[damned-lies] Add possibility to load sample data for a new DL instance



commit b90f43032f9069defb794c802a0e8d4aabd3e0f0
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Nov 8 12:23:02 2010 +0100

    Add possibility to load sample data for a new DL instance

 README                          |    3 +
 people/models.py                |   13 +
 stats/fixtures/sample_data.json |  687 +++++++++++++++++++++++++++++++++++++++
 stats/views.py                  |    5 +-
 teams/forms.py                  |    2 +-
 urls.py                         |    2 +-
 6 files changed, 708 insertions(+), 4 deletions(-)
---
diff --git a/README b/README
index f220bb1..8434c3c 100644
--- a/README
+++ b/README
@@ -56,6 +56,9 @@ Installation
 
     Note: The automatic migration fails on interdependencies.
 
+2b- If you want to populate the database with sample data, run:
+    ./manage.py loaddata sample_data
+
 3 - Configure Sites in admin interface to define the 'View on site'
     link.
 
diff --git a/people/models.py b/people/models.py
index 4f95660..10abc26 100644
--- a/people/models.py
+++ b/people/models.py
@@ -56,6 +56,19 @@ class Person(User):
             account.delete()
 
     @classmethod
+    def get_by_user(cls, user):
+        if user.is_anonymous():
+            return None
+        try:
+            return user.person
+        except Person.DoesNotExist:
+            _dict = user.__dict__.copy()
+            del _dict['_state']
+            user.person = Person(**_dict)
+            user.person.save()
+            return user.person
+
+    @classmethod
     def get_by_attr(cls, key, val):
         if not val:
             return None
diff --git a/stats/fixtures/sample_data.json b/stats/fixtures/sample_data.json
new file mode 100644
index 0000000..93cc2a5
--- /dev/null
+++ b/stats/fixtures/sample_data.json
@@ -0,0 +1,687 @@
+[
+ {
+  "pk": 1, 
+  "model": "sites.site", 
+  "fields": {
+   "domain": "localhost:8000", 
+   "name": "localhost:8000"
+  }
+ },
+ {
+  "pk": 1, 
+  "model": "languages.language", 
+  "fields": {
+   "locale": "en", 
+   "plurals": "nplurals=2; plural=(n != 1)", 
+   "name": "en", 
+   "team": null
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "languages.language", 
+  "fields": {
+   "locale": "fr", 
+   "plurals": "nplurals=2; plural=(n > 1)", 
+   "name": "French", 
+   "team": 1
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "languages.language", 
+  "fields": {
+   "locale": "it", 
+   "plurals": "nplurals=2; plural=(n != 1)", 
+   "name": "Italian", 
+   "team": 2
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.module", 
+  "fields": {
+   "comment": "", 
+   "vcs_web": "http://git.gnome.org/browse/gnome-hello/";, 
+   "name": "gnome-hello", 
+   "vcs_root": "git://git.gnome.org/gnome-hello", 
+   "bugs_product": "test", 
+   "maintainers": [], 
+   "bugs_component": "test", 
+   "bugs_base": "http://bugzilla.gnome.org";, 
+   "vcs_type": "git", 
+   "homepage": "", 
+   "description": ""
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.module", 
+  "fields": {
+   "comment": "This is not a GNOME-specific module. Please submit your translation through the <a href=\"http://www.transifex.net/projects/p/shared-mime-info/c/default/\";>Transifex platform</a>.", 
+   "vcs_web": "http://cgit.freedesktop.org/xdg/shared-mime-info/";, 
+   "name": "shared-mime-info", 
+   "vcs_root": "git://anongit.freedesktop.org/xdg/shared-mime-info", 
+   "bugs_product": "shared-mime-info", 
+   "maintainers": [], 
+   "bugs_component": "general", 
+   "bugs_base": "https://bugs.freedesktop.org/";, 
+   "vcs_type": "git", 
+   "homepage": "http://www.freedesktop.org/wiki/Software/shared-mime-info";, 
+   "description": "Shared MIME Info"
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "stats.module", 
+  "fields": {
+   "comment": null, 
+   "vcs_web": "http://git.gnome.org/browse/zenity/";, 
+   "name": "zenity", 
+   "vcs_root": "git://git.gnome.org/zenity", 
+   "bugs_product": "zenity", 
+   "maintainers": [], 
+   "bugs_component": "general", 
+   "bugs_base": "http://bugzilla.gnome.org/";, 
+   "vcs_type": "git", 
+   "homepage": "", 
+   "description": "Zenity"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.branch", 
+  "fields": {
+   "vcs_subpath": null, 
+   "file_hashes": "", 
+   "weight": 0, 
+   "name": "gnome-2-22", 
+   "module": 1
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.branch", 
+  "fields": {
+   "vcs_subpath": null, 
+   "file_hashes": "", 
+   "weight": 0, 
+   "name": "master", 
+   "module": 1
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "stats.branch", 
+  "fields": {
+   "vcs_subpath": null, 
+   "file_hashes": "", 
+   "weight": 0, 
+   "name": "master", 
+   "module": 2
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "stats.branch", 
+  "fields": {
+   "vcs_subpath": "", 
+   "file_hashes": "", 
+   "weight": 0, 
+   "name": "master", 
+   "module": 3
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "po", 
+   "dtype": "ui", 
+   "pot_method": null, 
+   "module": 3, 
+   "linguas_location": null, 
+   "directory": "po", 
+   "description": "UI translations"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "po", 
+   "dtype": "ui", 
+   "pot_method": null, 
+   "module": 1, 
+   "linguas_location": null, 
+   "directory": "po", 
+   "description": "UI Translations"
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "po", 
+   "dtype": "ui", 
+   "pot_method": null, 
+   "module": 2, 
+   "linguas_location": null, 
+   "directory": "po", 
+   "description": "UI translations"
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "help", 
+   "dtype": "doc", 
+   "pot_method": null, 
+   "module": 3, 
+   "linguas_location": null, 
+   "directory": "help", 
+   "description": "User Guide"
+  }
+ }, 
+ {
+  "pk": 5, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "help", 
+   "dtype": "doc", 
+   "pot_method": null, 
+   "module": 1, 
+   "linguas_location": null, 
+   "directory": "help", 
+   "description": "User Guide"
+  }
+ }, 
+ {
+  "pk": 6, 
+  "model": "stats.domain", 
+  "fields": {
+   "name": "help", 
+   "dtype": "doc", 
+   "pot_method": null, 
+   "module": 2, 
+   "linguas_location": null, 
+   "directory": "help", 
+   "description": "User Guide"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.release", 
+  "fields": {
+   "status": "official", 
+   "string_frozen": false, 
+   "name": "gnome-2-26", 
+   "weight": 0, 
+   "description": "GNOME 2.26 (Development)"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.release", 
+  "fields": {
+   "status": "xternal", 
+   "string_frozen": false, 
+   "name": "freedesktop-org", 
+   "weight": 0, 
+   "description": "freedesktop.org (non-GNOME)"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.category", 
+  "fields": {
+   "release": 2, 
+   "name": "default", 
+   "branch": 3
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.category", 
+  "fields": {
+   "release": 1, 
+   "name": "desktop", 
+   "branch": 2
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "stats.category", 
+  "fields": {
+   "release": 1, 
+   "name": "desktop", 
+   "branch": 4
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 3, 
+   "language": null, 
+   "num_figures": 0, 
+   "untranslated": 567, 
+   "translated": 0, 
+   "branch": 3, 
+   "date": "2008-11-08 19:14:23", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 3, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 4, 
+   "translated": 546, 
+   "branch": 3, 
+   "date": "2008-11-07 15:41:43", 
+   "fuzzy": 17
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 3, 
+   "language": 3, 
+   "num_figures": 0, 
+   "untranslated": 17, 
+   "translated": 541, 
+   "branch": 3, 
+   "date": "2008-11-07 15:41:44", 
+   "fuzzy": 9
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": null, 
+   "num_figures": 0, 
+   "untranslated": 135, 
+   "translated": 0, 
+   "branch": 2, 
+   "date": "2009-02-11 22:31:19", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 5, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 135, 
+   "branch": 2, 
+   "date": "2008-11-07 15:58:07", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 6, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": 3, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 135, 
+   "branch": 2, 
+   "date": "2008-11-07 15:58:13", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 7, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 4, 
+   "language": null, 
+   "num_figures": 11, 
+   "untranslated": 257, 
+   "translated": 0, 
+   "branch": 2, 
+   "date": "2009-02-11 22:31:20", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 8, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 4, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 257, 
+   "branch": 2, 
+   "date": "2009-02-11 22:21:30", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 9, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": null, 
+   "num_figures": 0, 
+   "untranslated": 130, 
+   "translated": 0, 
+   "branch": 1, 
+   "date": "2009-02-11 22:30:17", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 10, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 130, 
+   "branch": 1, 
+   "date": "2009-02-11 22:29:53", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 11, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 1, 
+   "language": 3, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 130, 
+   "branch": 1, 
+   "date": "2009-02-11 22:30:00", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 12, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 4, 
+   "language": null, 
+   "num_figures": 11, 
+   "untranslated": 253, 
+   "translated": 0, 
+   "branch": 1, 
+   "date": "2009-02-11 22:30:18", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 13, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 4, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 253, 
+   "branch": 1, 
+   "date": "2009-02-11 22:30:04", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 14, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 2, 
+   "language": null, 
+   "num_figures": 0, 
+   "untranslated": 47, 
+   "translated": 0, 
+   "branch": 4, 
+   "date": "2010-09-13 23:01:47", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 15, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 2, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 47, 
+   "branch": 4, 
+   "date": "2010-08-21 11:30:24", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 16, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 2, 
+   "language": 3, 
+   "num_figures": 0, 
+   "untranslated": 30, 
+   "translated": 9, 
+   "branch": 4, 
+   "date": "2010-08-21 11:30:25", 
+   "fuzzy": 8
+  }
+ }, 
+ {
+  "pk": 17, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 5, 
+   "language": null, 
+   "num_figures": 1, 
+   "untranslated": 22, 
+   "translated": 0, 
+   "branch": 4, 
+   "date": "2010-09-13 23:01:47", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 18, 
+  "model": "stats.statistics", 
+  "fields": {
+   "domain": 5, 
+   "language": 2, 
+   "num_figures": 0, 
+   "untranslated": 0, 
+   "translated": 22, 
+   "branch": 4, 
+   "date": "2010-08-21 11:30:31", 
+   "fuzzy": 0
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "teams.team", 
+  "fields": {
+   "mailing_list_subscribe": "http://www.traduc.org/mailman/listinfo/gnomefr";, 
+   "name": "fr", 
+   "webpage_url": "http://gnomefr.traduc.org/";, 
+   "use_workflow": true, 
+   "presentation": "Here can come any custom description for a team", 
+   "mailing_list": "gnomefr traduc org", 
+   "description": "French"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "teams.team", 
+  "fields": {
+   "mailing_list_subscribe": null, 
+   "name": "it", 
+   "webpage_url": "http://www.it.gnome.org/";, 
+   "use_workflow": true, 
+   "presentation": "", 
+   "mailing_list": null, 
+   "description": "Italian"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "teams.role", 
+  "fields": {
+   "person": 2, 
+   "role": "translator", 
+   "team": 1
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "teams.role", 
+  "fields": {
+   "person": 4, 
+   "role": "coordinator", 
+   "team": 2
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "teams.role", 
+  "fields": {
+   "person": 3, 
+   "role": "coordinator", 
+   "team": 1
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "vertimus.statedb", 
+  "fields": {
+   "domain": 5, 
+   "name": "None", 
+   "language": 2, 
+   "updated": "2009-05-29 23:20:51", 
+   "person": null, 
+   "branch": 4
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "vertimus.statedb", 
+  "fields": {
+   "domain": 4, 
+   "name": "None", 
+   "language": 2, 
+   "updated": "2009-06-16 19:53:36", 
+   "person": null, 
+   "branch": 2
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "auth.user", 
+  "fields": {
+   "username": "bob", 
+   "first_name": "Robert", 
+   "last_name": "Translator", 
+   "is_active": true, 
+   "is_superuser": false, 
+   "is_staff": false, 
+   "last_login": "2008-11-06 23:49:39", 
+   "groups": [], 
+   "user_permissions": [], 
+   "password": "sha1$4c846$3af94fa0135321db2ebc84866b323037028726ab", 
+   "email": "bob example org", 
+   "date_joined": "2008-11-06 23:49:39"
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "auth.user", 
+  "fields": {
+   "username": "coord_fr", 
+   "first_name": "French", 
+   "last_name": "Coordinator", 
+   "is_active": true, 
+   "is_superuser": false, 
+   "is_staff": false, 
+   "last_login": "2010-11-08 09:57:34", 
+   "groups": [], 
+   "user_permissions": [], 
+   "password": "sha1$0a578$c2f596f33f967c98bc5ed10ec48c490e3fe93199", 
+   "email": "coord_fr example org", 
+   "date_joined": "2008-11-06 23:49:39"
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "auth.user", 
+  "fields": {
+   "username": "coord_it", 
+   "first_name": "Alessio", 
+   "last_name": "Coordinator", 
+   "is_active": true, 
+   "is_superuser": false, 
+   "is_staff": false, 
+   "last_login": "2008-11-06 23:49:40", 
+   "groups": [], 
+   "user_permissions": [], 
+   "password": "sha1$52068$c609bd5b681c6818c91aeaa2a712043fa63b4306", 
+   "email": "alessio example org", 
+   "date_joined": "2008-11-06 23:49:40"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "people.person", 
+  "fields": {
+   "bugzilla_account": "", 
+   "groups": [], 
+   "image": "", 
+   "activation_key": "", 
+   "irc_nick": "bobby", 
+   "svn_account": "bob1", 
+   "webpage_url": "", 
+   "user_permissions": []
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "people.person", 
+  "fields": {
+   "bugzilla_account": "", 
+   "groups": [], 
+   "image": "", 
+   "activation_key": "", 
+   "irc_nick": "", 
+   "svn_account": "coord_fr", 
+   "webpage_url": "", 
+   "user_permissions": []
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "people.person", 
+  "fields": {
+   "bugzilla_account": "", 
+   "groups": [], 
+   "image": "", 
+   "activation_key": "", 
+   "irc_nick": "", 
+   "svn_account": "", 
+   "webpage_url": "", 
+   "user_permissions": []
+  }
+ }
+]
diff --git a/stats/views.py b/stats/views.py
index 08ecfe7..59506a9 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -33,6 +33,7 @@ from stats.models import Statistics, FakeStatistics, Module, Branch, Category, R
 from stats.forms import ModuleBranchForm
 from stats import utils
 from languages.models import Language
+from people.models import Person
 
 def modules(request, format='html'):
     all_modules = Module.objects.all()
@@ -50,7 +51,7 @@ def module(request, module_name):
     mod = get_object_or_404(Module, name=module_name)
     branches = mod.get_branches()
     if request.user.is_authenticated():
-        person = request.user.person
+        person = Person.get_by_user(request.user)
         langs = person.get_languages()
         for branch in branches:
             branch.get_ui_stats(mandatory_langs=langs)
@@ -187,7 +188,7 @@ def dynamic_po(request, filename):
         'year': date.today().year
     }
     if request.user.is_authenticated():
-        person = request.user.person
+        person = Person.get_by_user(request.user)
         dyn_content += u"# %(name)s <%(email)s>, %(year)s.\n#\n" % {
             'name' : person.name,
             'email': person.email,
diff --git a/teams/forms.py b/teams/forms.py
index 1441abc..8a0c343 100644
--- a/teams/forms.py
+++ b/teams/forms.py
@@ -17,7 +17,7 @@ class EditMemberRoleForm(forms.Form):
 
     def __init__(self, roles, *args, **kwargs):
         super(EditMemberRoleForm, self).__init__(*args, **kwargs)
-        choices = list(ROLE_CHOICES[:-1]) # exclude last element: coordinator
+        choices = list(filter(lambda x:x[0]!='coordinator', ROLE_CHOICES))
         choices.append(('remove', _("Remove From Team")))
         for role in roles:
             self.fields[str(role.pk)] = forms.ChoiceField(
diff --git a/urls.py b/urls.py
index a3f5d03..4ba7c06 100644
--- a/urls.py
+++ b/urls.py
@@ -47,7 +47,7 @@ urlpatterns = patterns('',
     url(r'^languages/', include('languages.urls')),
     url(r'^vertimus/', include('vertimus.urls')),
     url(r'^i18n/', include('django.conf.urls.i18n')),
-    url(r'^admin/(.*)', admin.site.root),
+    url(r'^admin/', include(admin.site.urls)),
     url(r'^rss/', include('feeds.urls')),
 )
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]