changeset 115:a1e344b3c064

Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
author avarma@sm-labs01.mozilla.org
date Fri, 28 Mar 2008 19:03:13 -0700
parents 95ed7c25c065
children ae03ae3d91e9
files PersonasBackend/personas/urls.py import_japanese_personas.py
diffstat 2 files changed, 84 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/PersonasBackend/personas/urls.py	Fri Mar 28 18:37:59 2008 -0700
+++ b/PersonasBackend/personas/urls.py	Fri Mar 28 19:03:13 2008 -0700
@@ -10,7 +10,7 @@
      name='personas-all-json'),
 
     # Dynamic wrappers for views
-    url(r'^legacy/(?P<name>[_a-z]+)$',
+    url(r'^legacy/(?P<name>.+)$',
         'PersonasBackend.personas.views.legacy_cbeard_persona',
         name='legacy-cbeard-persona'),
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/import_japanese_personas.py	Fri Mar 28 19:03:13 2008 -0700
@@ -0,0 +1,83 @@
+# Imports the personas from personas_all.dat and
+# personas_categories.dat (the contents of which are contained in this
+# file as constants) into the database.
+
+import os
+
+os.environ["DJANGO_SETTINGS_MODULE"] = "PersonasBackend.settings"
+
+from django.utils import simplejson
+from PersonasBackend.personas import models
+
+def makeCategory( name ):
+    return models.Category( name = name )
+
+def makePersona( name, category, text_color, json_id ):
+    url = "http://personas-view/legacy-cbeard-persona?name=%s" % json_id
+    return models.Persona(
+        name = name,
+        category = category,
+        text_color = text_color,
+        description = "&nbsp;",
+        url = url,
+        status = "published"
+        )
+
+personas_categories_dat = """
+{ "categories": [
+        {"label": "Japan Rock Festival 2007", "id" : "personas-mozilla24-menu", "type" : "list", "parent" : "personas-category-menu"}
+  ]
+}
+"""
+
+personas_all_dat = """
+{ "personas": [
+    {"label": "101A", "id" : "101a", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "AJI", "id" : "aji", "menu" : "personas-mozilla24-menu", "dark" : "false" },
+       {"label": "TAIZO JINNOUCHI", "id" : "jinnouchi", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "KOKUSYOKU SUMIRE", "id" : "kokushoku", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "marron", "id" : "marron", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "MARS EURYTHMICS", "id" : "mars", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "MIDORI", "id" : "midori", "menu" : "personas-mozilla24-menu", "dark" : "false" },
+       {"label": "O-NO KIYOFUMI", "id" : "ohno", "menu" : "personas-mozilla24-menu", "dark" : "false" },
+       {"label": "Qomolangma Tomato", "id" : "qomo", "menu" : "personas-mozilla24-menu", "dark" : "false" },
+       {"label": "Shonen Knife", "id" : "shonen", "menu" : "personas-mozilla24-menu", "dark" : "false" },
+       {"label": "SLUGGER", "id" : "slugger", "menu" : "personas-mozilla24-menu", "dark" : "true" },
+       {"label": "TsuShiMaMiRe", "id" : "tsushimamire", "menu" : "personas-mozilla24-menu", "dark" : "false" }
+  ]
+}
+
+"""
+
+if __name__ == "__main__":
+    personas = simplejson.loads( personas_all_dat )
+    personas = personas["personas"]
+
+    categories = simplejson.loads( personas_categories_dat )
+    categories = categories["categories"]
+
+    json_cats = {}
+
+    for category in categories:
+        if category["parent"] == "personas-category-menu":
+            cat = makeCategory(
+                name = category["label"],
+                )
+            print "Saving category %s" % cat.name
+            cat.save()
+            json_cats[category["id"]] = cat
+
+    for persona in personas:
+        menu = persona["menu"].split( "," )[0]
+        if persona.get( "dark", "false" ) == "true":
+            text_color = "#FFFFFF"
+        else:
+            text_color = "#000000"
+        persona = makePersona(
+            name = persona["label"],
+            category = json_cats[menu],
+            text_color = text_color,
+            json_id = persona["id"],
+            )
+        print "Saving persona %s" % persona.name
+        persona.save()