More document grouping rename updates
This commit is contained in:
@@ -105,17 +105,17 @@ class SmartLinkImageWidget(forms.widgets.Widget):
|
|||||||
|
|
||||||
class SmartLinkInstanceForm(forms.Form):
|
class SmartLinkInstanceForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
groups = kwargs.pop('groups', None)
|
smart_link_instances = kwargs.pop('smart_link_instances', None)
|
||||||
links = kwargs.pop('links', None)
|
links = kwargs.pop('links', None)
|
||||||
current_document = kwargs.pop('current_document', None)
|
current_document = kwargs.pop('current_document', None)
|
||||||
super(SmartLinkInstanceForm, self).__init__(*args, **kwargs)
|
super(SmartLinkInstanceForm, self).__init__(*args, **kwargs)
|
||||||
for group, data in groups.items():
|
for smart_link_instance, data in smart_link_instances.items():
|
||||||
self.fields['preview-%s' % group] = forms.CharField(
|
self.fields['preview-%s' % smart_link_instance] = forms.CharField(
|
||||||
widget=SmartLinkImageWidget(),
|
widget=SmartLinkImageWidget(),
|
||||||
label=u'%s (%d)' % (unicode(data['title']), len(data['documents'])),
|
label=u'%s (%d)' % (unicode(data['title']), len(data['documents'])),
|
||||||
required=False,
|
required=False,
|
||||||
initial={
|
initial={
|
||||||
'group': group,
|
'group': smart_link_instance,
|
||||||
'group_data': data['documents'],
|
'group_data': data['documents'],
|
||||||
'current_document': current_document,
|
'current_document': current_document,
|
||||||
'links': links
|
'links': links
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from documents.models import Document
|
|||||||
from grouping.literals import INCLUSION_AND, INCLUSION_OR
|
from grouping.literals import INCLUSION_AND, INCLUSION_OR
|
||||||
|
|
||||||
|
|
||||||
class DocumentGroupManager(models.Manager):
|
class SmartLinkManager(models.Manager):
|
||||||
def get_groups_for(self, document, group_obj=None):
|
def get_groups_for(self, document, group_obj=None):
|
||||||
errors = []
|
errors = []
|
||||||
document_groups = {}
|
document_groups = {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from grouping.managers import DocumentGroupManager
|
from grouping.managers import SmartLinkManager
|
||||||
from grouping.literals import OPERATOR_CHOICES, INCLUSION_AND, \
|
from grouping.literals import OPERATOR_CHOICES, INCLUSION_AND, \
|
||||||
INCLUSION_CHOICES
|
INCLUSION_CHOICES
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ class DocumentGroup(models.Model):
|
|||||||
dynamic_title = models.CharField(blank=True, max_length=96, verbose_name=_(u'dynamic title'), help_text=_(u'This expression will be evaluated against the current selected document. The document metadata is available as variables `metadata` and document properties under the variable `document`.'))
|
dynamic_title = models.CharField(blank=True, max_length=96, verbose_name=_(u'dynamic title'), help_text=_(u'This expression will be evaluated against the current selected document. The document metadata is available as variables `metadata` and document properties under the variable `document`.'))
|
||||||
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'))
|
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'))
|
||||||
|
|
||||||
objects = DocumentGroupManager()
|
objects = SmartLinkManager()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def smart_link_instances_for_document(request, document_id):
|
|||||||
|
|
||||||
subtemplates_list = []
|
subtemplates_list = []
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
smart_links, errors = DocumentGroup.objects.get_groups_for(document)
|
smart_link_instances, errors = DocumentGroup.objects.get_groups_for(document)
|
||||||
if (request.user.is_staff or request.user.is_superuser) and errors:
|
if (request.user.is_staff or request.user.is_superuser) and errors:
|
||||||
for error in errors:
|
for error in errors:
|
||||||
messages.warning(request, _(u'Smart link query error: %s' % error))
|
messages.warning(request, _(u'Smart link query error: %s' % error))
|
||||||
@@ -67,15 +67,15 @@ def smart_link_instances_for_document(request, document_id):
|
|||||||
if not SHOW_EMPTY_GROUPS:
|
if not SHOW_EMPTY_GROUPS:
|
||||||
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
||||||
#dictionary
|
#dictionary
|
||||||
document_groups = dict([(group, data) for group, data in document_groups.items() if data['documents']])
|
smart_link_instances = dict([(group, data) for group, data in smart_link_instances.items() if data['documents']])
|
||||||
|
|
||||||
if smart_links:
|
if smart_link_instances:
|
||||||
subtemplates_list = [{
|
subtemplates_list = [{
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
'context': {
|
'context': {
|
||||||
'title': _(u'smart links (%s)') % len(smart_links.keys()),
|
'title': _(u'smart links (%s)') % len(smart_link_instances.keys()),
|
||||||
'form': SmartLinkInstanceForm(
|
'form': SmartLinkInstanceForm(
|
||||||
groups=smart_links, current_document=document,
|
smart_link_instances=smart_link_instances, current_document=document,
|
||||||
links=[smart_link_instance_view_link]
|
links=[smart_link_instance_view_link]
|
||||||
),
|
),
|
||||||
'form_action': reverse('smart_link_action'),
|
'form_action': reverse('smart_link_action'),
|
||||||
|
|||||||
Reference in New Issue
Block a user