Add slugs to indexes to be able to reference them from the mirroring app.
This commit is contained in:
20
mayan/apps/document_indexing/migrations/0005_index_slug.py
Normal file
20
mayan/apps/document_indexing/migrations/0005_index_slug.py
Normal 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,
|
||||
),
|
||||
]
|
||||
@@ -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),
|
||||
]
|
||||
@@ -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,
|
||||
),
|
||||
]
|
||||
@@ -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=_(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user