[damned-lies] Add domain.layout field
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Add domain.layout field
- Date: Mon, 20 Aug 2018 20:37:58 +0000 (UTC)
commit 3fd3c7fe6658cd980e5e694fcb9034847c2fb723
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Aug 20 20:51:10 2018 +0200
Add domain.layout field
This should progressively replace domain.directory.
stats/admin.py | 8 ++++----
stats/fixtures/sample_data.json | 5 +++++
stats/migrations/0013_domain_layout.py | 17 +++++++++++++++++
stats/migrations/0014_migrate_dir_to_layout.py | 21 +++++++++++++++++++++
stats/models.py | 4 ++++
5 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/stats/admin.py b/stats/admin.py
index 78226cf2..9165a2f3 100644
--- a/stats/admin.py
+++ b/stats/admin.py
@@ -44,7 +44,7 @@ class DomainInline(admin.StackedInline):
form = DomainForm
fieldsets = (
(None, {
- 'fields': (('name', 'description', 'dtype', 'directory'),)
+ 'fields': (('name', 'description', 'dtype', 'directory', 'layout'),)
}),
('Advanced', {
'fields': (('pot_method', 'pot_params'),
@@ -62,7 +62,7 @@ class DomainInline(admin.StackedInline):
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'description':
kwargs['widget'] = forms.Textarea(attrs={'rows':'1', 'cols':'20'})
- elif db_field.name in ('name', 'directory'):
+ elif db_field.name in ('name', 'directory', 'layout'):
kwargs['widget'] = forms.TextInput(attrs={'size':'20'})
elif db_field.name in ('red_filter', 'extra_its_dirs'):
kwargs['widget'] = forms.Textarea(attrs={'rows':'1', 'cols':'40'})
@@ -123,9 +123,9 @@ class BranchAdmin(admin.ModelAdmin):
class DomainAdmin(admin.ModelAdmin):
form = DomainForm
- list_display = ('__str__', 'directory', 'pot_method')
+ list_display = ('__str__', 'directory', 'layout', 'pot_method')
list_filter = ('dtype', 'pot_method')
- search_fields = ('name', 'module__name','directory', 'pot_method')
+ search_fields = ('name', 'module__name','directory', 'layout', 'pot_method')
class CategoryInline(admin.TabularInline):
model = Category
diff --git a/stats/fixtures/sample_data.json b/stats/fixtures/sample_data.json
index d658dbb6..4fac5660 100644
--- a/stats/fixtures/sample_data.json
+++ b/stats/fixtures/sample_data.json
@@ -319,6 +319,7 @@
"red_filter": "",
"branch_to": null,
"directory": "help",
+ "layout": "help/{lang}/{lang}.po",
"description": "User Guide"
},
"model": "stats.domain",
@@ -335,6 +336,7 @@
"red_filter": "",
"branch_to": null,
"directory": "po",
+ "layout": "po/{lang}.po",
"description": "UI Translations"
},
"model": "stats.domain",
@@ -351,6 +353,7 @@
"red_filter": "",
"branch_to": null,
"directory": "help",
+ "layout": "help/{lang}/{lang}.po",
"description": "User Guide"
},
"model": "stats.domain",
@@ -367,6 +370,7 @@
"red_filter": "",
"branch_to": null,
"directory": "po",
+ "layout": "po/{lang}.po",
"description": "UI Translations"
},
"model": "stats.domain",
@@ -383,6 +387,7 @@
"red_filter": "",
"branch_to": null,
"directory": "help",
+ "layout": "help/{lang}/{lang}.po",
"description": "User Guide"
},
"model": "stats.domain",
diff --git a/stats/migrations/0013_domain_layout.py b/stats/migrations/0013_domain_layout.py
new file mode 100644
index 00000000..46701f6f
--- /dev/null
+++ b/stats/migrations/0013_domain_layout.py
@@ -0,0 +1,17 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('stats', '0012_remove_domain_pot_method_old'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='domain',
+ name='layout',
+ field=models.CharField(default='', help_text="UI standard is 'po/{lang}.po', doc standard is
'po/{lang}/{lang}.po'", max_length=50),
+ preserve_default=False,
+ ),
+ ]
diff --git a/stats/migrations/0014_migrate_dir_to_layout.py b/stats/migrations/0014_migrate_dir_to_layout.py
new file mode 100644
index 00000000..002c8645
--- /dev/null
+++ b/stats/migrations/0014_migrate_dir_to_layout.py
@@ -0,0 +1,21 @@
+from django.db import migrations
+
+
+def migrate_layout(apps, schema_editor):
+ Domain = apps.get_model("stats", "Domain")
+ for dom in Domain.objects.all():
+ # This rule is valid for 95% of cases. The rest will need manual tweak.
+ if dom.dtype == 'ui':
+ dom.layout = '%s/{lang}.po' % dom.directory
+ elif dom.dtype == 'doc':
+ dom.layout = '%s/{lang}/{lang}.po' % dom.directory
+ dom.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('stats', '0013_domain_layout'),
+ ]
+
+ operations = [migrations.RunPython(migrate_layout, migrations.RunPython.noop)]
diff --git a/stats/models.py b/stats/models.py
index 0135c642..10f97814 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -733,6 +733,10 @@ class Domain(models.Model):
description = models.TextField(blank=True)
dtype = models.CharField(max_length=5, choices=DOMAIN_TYPE_CHOICES, default='ui')
directory = models.CharField(max_length=50)
+ layout = models.CharField(
+ max_length=50,
+ help_text="UI standard is 'po/{lang}.po', doc standard is 'po/{lang}/{lang}.po'"
+ )
pot_method = models.CharField(max_length=20, choices=POT_METHOD_CHOICES, default='auto')
pot_params = models.CharField(
max_length=100, blank=True, help_text="Only for shell or URL methods"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]