Add slugs to indexes to be able to reference them from the mirroring app.

This commit is contained in:
Roberto Rosario
2015-07-28 21:54:40 -04:00
parent 6039ea86ec
commit e4fa3c4960
5 changed files with 72 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('document_indexing', '0004_auto_20150708_0113'),
]
operations = [
migrations.AddField(
model_name='index',
name='slug',
field=models.SlugField(null=True, max_length=128, blank=True, help_text='This values will be used by other apps to reference this index.', unique=True, verbose_name='Slug'),
preserve_default=True,
),
]

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.template.defaultfilters import slugify
def assign_slugs(apps, schema_editor):
Index = apps.get_model('document_indexing', 'Index')
for index in Index.objects.all():
index.slug = slugify(index.label)
index.save()
class Migration(migrations.Migration):
dependencies = [
('document_indexing', '0005_index_slug'),
]
operations = [
migrations.RunPython(assign_slugs),
]

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('document_indexing', '0006_auto_20150729_0144'),
]
operations = [
migrations.AlterField(
model_name='index',
name='slug',
field=models.SlugField(default='', max_length=128, help_text='This values will be used by other apps to reference this index.', unique=True, verbose_name='Slug'),
preserve_default=False,
),
]

View File

@@ -18,6 +18,11 @@ class Index(models.Model):
label = models.CharField(
max_length=128, unique=True, verbose_name=_('Label')
)
slug = models.SlugField(
help_text=_(
'This values will be used by other apps to reference this index.'
), max_length=128, unique=True, verbose_name=_('Slug')
)
enabled = models.BooleanField(
default=True,
help_text=_(

View File

@@ -37,7 +37,7 @@ from .widgets import index_instance_item_link, get_breadcrumbs, node_level
# Setup views
class SetupIndexCreateView(SingleObjectCreateView):
extra_context = {'title': _('Create index')}
fields = ('label', 'enabled')
fields = ('label', 'slug', 'enabled')
model = Index
post_action_redirect = reverse_lazy('indexing:index_setup_list')
view_permission = permission_document_indexing_create
@@ -53,13 +53,14 @@ class SetupIndexListView(SingleObjectListView):
'hide_object': True,
'extra_columns': [
{'name': _('Label'), 'attribute': 'label'},
{'name': _('Slug'), 'attribute': 'slug'},
{'name': _('Enabled'), 'attribute': encapsulate(lambda x: two_state_template(x.enabled))},
]
}
class SetupIndexEditView(SingleObjectEditView):
fields = ('label', 'enabled')
fields = ('label', 'slug', 'enabled')
model = Index
post_action_redirect = reverse_lazy('indexing:index_setup_list')
view_permission = permission_document_indexing_edit