Rename smart links title and dynamic_title fileds to label and dynamic_label.
This commit is contained in:
@@ -12,10 +12,10 @@ from .models import SmartLink, SmartLinkCondition
|
||||
class SmartLinkForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SmartLinkForm, self).__init__(*args, **kwargs)
|
||||
self.fields['dynamic_title'].help_text = ' '.join([unicode(self.fields['dynamic_title'].help_text), ModelAttribute.help_text_for(Document, type_names=['field', 'related', 'property'])])
|
||||
self.fields['dynamic_label'].help_text = ' '.join([unicode(self.fields['dynamic_label'].help_text), ModelAttribute.help_text_for(Document, type_names=['field', 'related', 'property'])])
|
||||
|
||||
class Meta:
|
||||
fields = ('title', 'dynamic_title', 'enabled')
|
||||
fields = ('label', 'dynamic_label', 'enabled')
|
||||
model = SmartLink
|
||||
|
||||
|
||||
|
||||
24
mayan/apps/linking/migrations/0003_auto_20150708_0318.py
Normal file
24
mayan/apps/linking/migrations/0003_auto_20150708_0318.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('linking', '0002_resolvedsmartlink'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='smartlink',
|
||||
old_name='dynamic_title',
|
||||
new_name='dynamic_label',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='smartlink',
|
||||
old_name='title',
|
||||
new_name='label',
|
||||
),
|
||||
]
|
||||
26
mayan/apps/linking/migrations/0004_auto_20150708_0320.py
Normal file
26
mayan/apps/linking/migrations/0004_auto_20150708_0320.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('linking', '0003_auto_20150708_0318'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='smartlink',
|
||||
name='dynamic_label',
|
||||
field=models.CharField(help_text='This expression will be evaluated against the current selected document.', max_length=96, verbose_name='Dynamic label', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='smartlink',
|
||||
name='label',
|
||||
field=models.CharField(max_length=96, verbose_name='Label'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
||||
@@ -14,22 +14,22 @@ from .literals import (
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class SmartLink(models.Model):
|
||||
title = models.CharField(max_length=96, verbose_name=_('Title'))
|
||||
dynamic_title = models.CharField(blank=True, max_length=96, verbose_name=_('Dynamic title'), help_text=_('This expression will be evaluated against the current selected document.'))
|
||||
label = models.CharField(max_length=96, verbose_name=_('Label'))
|
||||
dynamic_label = models.CharField(blank=True, max_length=96, verbose_name=_('Dynamic label'), help_text=_('This expression will be evaluated against the current selected document.'))
|
||||
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
||||
document_types = models.ManyToManyField(DocumentType, verbose_name=_('Document types'))
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
return self.label
|
||||
|
||||
def get_dynamic_title(self, document):
|
||||
if self.dynamic_title:
|
||||
def get_dynamic_label(self, document):
|
||||
if self.dynamic_label:
|
||||
try:
|
||||
return eval(self.dynamic_title, {'document': document})
|
||||
return eval(self.dynamic_label, {'document': document})
|
||||
except Exception as exception:
|
||||
return Exception(_('Error generating dynamic title; %s' % unicode(exception)))
|
||||
return Exception(_('Error generating dynamic label; %s' % unicode(exception)))
|
||||
else:
|
||||
return self.title
|
||||
return self.label
|
||||
|
||||
def resolve_for(self, document):
|
||||
return ResolvedSmartLink(smart_link=self, queryset=self.get_linked_document_for(document))
|
||||
|
||||
@@ -95,7 +95,7 @@ class ResolvedSmartLinkView(DocumentListView):
|
||||
'object': self.document,
|
||||
'title': _('Documents in smart link "%(smart_link)s" as relation to "%(document)s"') % {
|
||||
'document': self.document,
|
||||
'smart_link': self.smart_link.get_dynamic_title(self.document),
|
||||
'smart_link': self.smart_link.get_dynamic_label(self.document),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class SmartLinkListView(SingleObjectListView):
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'extra_columns': [
|
||||
{'name': _('Dynamic title'), 'attribute': 'dynamic_title'},
|
||||
{'name': _('Dynamic label'), 'attribute': 'dynamic_label'},
|
||||
{'name': _('Enabled'), 'attribute': encapsulate(lambda instance: two_state_template(instance.enabled))},
|
||||
],
|
||||
'hide_link': True,
|
||||
@@ -139,7 +139,7 @@ class DocumentSmartLinkListView(SmartLinkListView):
|
||||
return {
|
||||
'document': self.document,
|
||||
'extra_columns': (
|
||||
{'name': _('Title'), 'attribute': encapsulate(lambda smart_link: smart_link.get_dynamic_title(self.document))},
|
||||
{'name': _('Label'), 'attribute': encapsulate(lambda smart_link: smart_link.get_dynamic_label(self.document))},
|
||||
),
|
||||
'hide_object': True,
|
||||
'hide_link': True,
|
||||
|
||||
Reference in New Issue
Block a user