Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bug 797783] Add Locale model.

Includes migration to create and populate table.
  • Loading branch information...
commit 0e922b00896ed9f0abb625ed1fb8ee549724567d 1 parent 175e473
@rlr rlr authored
View
22 apps/wiki/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
-from wiki.models import Document, ImportantDate
+from wiki.models import Document, ImportantDate, Locale
class DocumentAdmin(admin.ModelAdmin):
@@ -75,3 +75,23 @@ class ImportantDateAdmin(admin.ModelAdmin):
admin.site.register(ImportantDate, ImportantDateAdmin)
+
+
+class LocaleAdmin(admin.ModelAdmin):
+ list_display = ('locale',)
+ list_display_links = ('locale',)
+ raw_id_fields = ('leaders', 'reviewers', 'editors')
+ readonly_fields = ('locale',)
+ search_fields = ('locale',)
+
+ # Disable adding and deleting new locales from the admin.
+ # Use migrations instead.
+
+ def has_add_permission(self, request):
+ return False
+
+ def has_delete_permission(self, request, *args, **kwargs):
+ return False
+
+
+admin.site.register(Locale, LocaleAdmin)
View
14 apps/wiki/models.py
@@ -892,6 +892,20 @@ class ImportantDate(ModelBase):
date = models.DateField(db_index=True)
+class Locale(ModelBase):
+ """A locale supported in the KB."""
+ locale = models.CharField(max_length=7, db_index=True)
+ leaders = models.ManyToManyField(
+ User, blank=True, related_name='locales_leader')
+ reviewers = models.ManyToManyField(
+ User, blank=True, related_name='locales_reviewer')
+ editors = models.ManyToManyField(
+ User, blank=True, related_name='locales_editor')
+
+ class Meta:
+ ordering = ['locale']
+
+
def _doc_components_from_url(url, required_locale=None, check_host=True):
"""Return (locale, path, slug) if URL is a Document, False otherwise.
View
9 docs/localization.rst
@@ -342,12 +342,17 @@ should delete these, never commit them::
Adding a New Locale
-------------------
-Adding a new locale is even easier than updating the templates. Say you wanted
-to add ``fa-IR``::
+Say you wanted to add ``fa-IR``::
$ mkdir -p locale/fa-IR/LC_MESSAGES
$ python manage.py merge
+Then add 'fa-IR' to SUMO_LANGUAGES in settings.py.
+
+And finally, add a migration with::
+
+ INSERT INTO `wiki_locale` (`locale`) VALUES ('fa-IR');
+
Done!
View
118 migrations/178-add-locales-model-and-migration.sql
@@ -0,0 +1,118 @@
+CREATE TABLE `wiki_locale_leaders` (
+ `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
+ `locale_id` integer NOT NULL,
+ `user_id` integer NOT NULL,
+ UNIQUE (`locale_id`, `user_id`)
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
+ALTER TABLE `wiki_locale_leaders` ADD CONSTRAINT `user_id_refs_id_e961639` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
+
+CREATE TABLE `wiki_locale_reviewers` (
+ `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
+ `locale_id` integer NOT NULL,
+ `user_id` integer NOT NULL,
+ UNIQUE (`locale_id`, `user_id`)
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
+ALTER TABLE `wiki_locale_reviewers` ADD CONSTRAINT `user_id_refs_id_590fc64b` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
+
+CREATE TABLE `wiki_locale_editors` (
+ `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
+ `locale_id` integer NOT NULL,
+ `user_id` integer NOT NULL,
+ UNIQUE (`locale_id`, `user_id`)
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
+ALTER TABLE `wiki_locale_editors` ADD CONSTRAINT `user_id_refs_id_5b30f591` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
+
+CREATE TABLE `wiki_locale` (
+ `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
+ `locale` varchar(7) NOT NULL
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
+ALTER TABLE `wiki_locale_leaders` ADD CONSTRAINT `locale_id_refs_id_e2c5fe94` FOREIGN KEY (`locale_id`) REFERENCES `wiki_locale` (`id`);
+ALTER TABLE `wiki_locale_reviewers` ADD CONSTRAINT `locale_id_refs_id_1f5e3d0` FOREIGN KEY (`locale_id`) REFERENCES `wiki_locale` (`id`);
+ALTER TABLE `wiki_locale_editors` ADD CONSTRAINT `locale_id_refs_id_c998d4c4` FOREIGN KEY (`locale_id`) REFERENCES `wiki_locale` (`id`);
+CREATE INDEX `wiki_locale_928541cb` ON `wiki_locale` (`locale`);
+
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ach');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ak');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ar');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('as');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ast');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('be');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('bg');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('bn-BD');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('bn-IN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('bs');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ca');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('cs');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('da');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('de');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('el');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('en-US');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('eo');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('es');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('et');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('eu');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('fa');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ff');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('fi');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('fr');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('fur');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('fy-NL');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ga-IE');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('gd');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('gl');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('gu-IN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('he');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('hi-IN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('hr');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('hu');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('hy-AM');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('id');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ilo');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('is');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('it');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ja');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('kk');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('km');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('kn');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ko');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('lg');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('lt');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('mai');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('mk');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ml');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('mn');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('mr');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ms');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('my');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('nb-NO');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ne-NP');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('nl');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('no');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('nso');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('pa-IN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('pl');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('pt-BR');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('pt-PT');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('rm');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ro');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ru');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('rw');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('si');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sk');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sl');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('son');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sq');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sr-CYRL');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sr-LATN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('sv');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ta-LK');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('ta');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('te');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('th');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('tr');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('uk');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('vi');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('zh-CN');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('zh-TW');
+INSERT INTO `wiki_locale` (`locale`) VALUES ('zu');
+
Please sign in to comment.
Something went wrong with that request. Please try again.