Enable smart links from the documents types side
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -200,6 +200,8 @@
|
||||
* Fix smart link ACL support.
|
||||
* Update JavaScript downloader to work with Python 3.
|
||||
* Improve speed of the NPM package hash verification.
|
||||
* Add view to enable smart links for documents types
|
||||
from the document type side.
|
||||
|
||||
3.1.11 (2019-04-XX)
|
||||
===================
|
||||
|
||||
@@ -232,6 +232,8 @@ Other changes
|
||||
* Fix smart link ACL support.
|
||||
* Update JavaScript downloader to work with Python 3.
|
||||
* Improve speed of the NPM package hash verification.
|
||||
* Add view to enable smart links for documents types
|
||||
from the document type side.
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
@@ -19,12 +19,13 @@ from mayan.apps.navigation.classes import SourceColumn
|
||||
|
||||
from .events import event_smart_link_created, event_smart_link_edited
|
||||
from .links import (
|
||||
link_smart_link_create, link_smart_link_condition_create,
|
||||
link_smart_link_condition_delete, link_smart_link_condition_edit,
|
||||
link_smart_link_condition_list, link_smart_link_delete,
|
||||
link_smart_link_document_types, link_smart_link_edit,
|
||||
link_smart_link_instance_view, link_smart_link_instances_for_document,
|
||||
link_smart_link_list, link_smart_link_setup
|
||||
link_document_type_smart_links, link_smart_link_create,
|
||||
link_smart_link_condition_create, link_smart_link_condition_delete,
|
||||
link_smart_link_condition_edit, link_smart_link_condition_list,
|
||||
link_smart_link_delete, link_smart_link_document_types,
|
||||
link_smart_link_edit, link_smart_link_instance_view,
|
||||
link_smart_link_instances_for_document, link_smart_link_list,
|
||||
link_smart_link_setup
|
||||
)
|
||||
from .permissions import (
|
||||
permission_smart_link_delete, permission_smart_link_edit,
|
||||
@@ -47,6 +48,9 @@ class LinkingApp(MayanAppConfig):
|
||||
Document = apps.get_model(
|
||||
app_label='documents', model_name='Document'
|
||||
)
|
||||
DocumentType = apps.get_model(
|
||||
app_label='documents', model_name='DocumentType'
|
||||
)
|
||||
|
||||
ResolvedSmartLink = self.get_model(model_name='ResolvedSmartLink')
|
||||
SmartLink = self.get_model(model_name='SmartLink')
|
||||
@@ -106,6 +110,9 @@ class LinkingApp(MayanAppConfig):
|
||||
link_smart_link_condition_list,
|
||||
), sources=(SmartLink,)
|
||||
)
|
||||
menu_list_facet.bind_links(
|
||||
links=(link_document_type_smart_links,), sources=(DocumentType,)
|
||||
)
|
||||
menu_object.bind_links(
|
||||
links=(
|
||||
link_smart_link_condition_edit,
|
||||
|
||||
@@ -3,6 +3,10 @@ from __future__ import absolute_import, unicode_literals
|
||||
from mayan.apps.appearance.classes import Icon
|
||||
from mayan.apps.documents.icons import icon_document_type
|
||||
|
||||
icon_smart_link = Icon(driver_name='fontawesome', symbol='link')
|
||||
|
||||
icon_document_type_smart_links = icon_smart_link
|
||||
|
||||
icon_smart_link_condition = Icon(driver_name='fontawesome', symbol='code')
|
||||
icon_smart_link_condition_create = Icon(
|
||||
driver_name='fontawesome-dual', primary_symbol='code',
|
||||
@@ -25,5 +29,5 @@ icon_smart_link_edit = Icon(driver_name='fontawesome', symbol='pencil-alt')
|
||||
icon_smart_link_instances_for_document = Icon(
|
||||
driver_name='fontawesome', symbol='link'
|
||||
)
|
||||
icon_smart_link_setup = Icon(driver_name='fontawesome', symbol='link')
|
||||
icon_smart_link_list = Icon(driver_name='fontawesome', symbol='link')
|
||||
icon_smart_link_setup = icon_smart_link
|
||||
icon_smart_link_list = icon_smart_link
|
||||
|
||||
@@ -2,18 +2,24 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.documents.permissions import permission_document_view
|
||||
from mayan.apps.documents.permissions import (
|
||||
permission_document_type_edit, permission_document_view
|
||||
)
|
||||
from mayan.apps.navigation.classes import Link
|
||||
|
||||
#from .icons import (
|
||||
# icon_smart_link_condition_create, icon_smart_link_create,
|
||||
# icon_smart_link_instances_for_document, icon_smart_link_setup
|
||||
#)
|
||||
|
||||
from .permissions import (
|
||||
permission_smart_link_create, permission_smart_link_delete,
|
||||
permission_smart_link_edit, permission_smart_link_view
|
||||
)
|
||||
|
||||
|
||||
link_document_type_smart_links = Link(
|
||||
args='resolved_object.pk',
|
||||
icon_class_path='mayan.apps.linking.icons.icon_document_type_smart_links',
|
||||
permissions=(permission_document_type_edit,), text=_('Smart links'),
|
||||
view='linking:document_type_smart_links',
|
||||
)
|
||||
link_smart_link_condition_create = Link(
|
||||
args='object.pk',
|
||||
icon_class_path='mayan.apps.linking.icons.icon_smart_link_condition_create',
|
||||
|
||||
@@ -36,7 +36,8 @@ class SmartLink(models.Model):
|
||||
)
|
||||
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
||||
document_types = models.ManyToManyField(
|
||||
to=DocumentType, verbose_name=_('Document types')
|
||||
related_name='smart_links', to=DocumentType,
|
||||
verbose_name=_('Document types')
|
||||
)
|
||||
|
||||
objects = SmartLinkManager()
|
||||
@@ -212,4 +213,3 @@ class SmartLinkCondition(models.Model):
|
||||
)
|
||||
|
||||
get_full_label.short_description = _('Full label')
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@ from .api_views import (
|
||||
APISmartLinkConditionListView, APISmartLinkConditionView
|
||||
)
|
||||
from .views import (
|
||||
DocumentSmartLinkListView, ResolvedSmartLinkView,
|
||||
SetupSmartLinkDocumentTypesView, SmartLinkConditionListView,
|
||||
SmartLinkConditionCreateView, SmartLinkConditionEditView,
|
||||
SmartLinkConditionDeleteView, SmartLinkCreateView, SmartLinkDeleteView,
|
||||
SmartLinkEditView, SmartLinkListView
|
||||
DocumentSmartLinkListView, DocumentTypeSmartLinksView,
|
||||
ResolvedSmartLinkView, SetupSmartLinkDocumentTypesView,
|
||||
SmartLinkConditionListView, SmartLinkConditionCreateView,
|
||||
SmartLinkConditionEditView, SmartLinkConditionDeleteView,
|
||||
SmartLinkCreateView, SmartLinkDeleteView, SmartLinkEditView,
|
||||
SmartLinkListView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@@ -25,7 +26,11 @@ urlpatterns = [
|
||||
regex=r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$',
|
||||
view=ResolvedSmartLinkView.as_view(), name='smart_link_instance_view'
|
||||
),
|
||||
|
||||
url(
|
||||
regex=r'^document_types/(?P<pk>\d+)/smart_links/$',
|
||||
view=DocumentTypeSmartLinksView.as_view(),
|
||||
name='document_type_smart_links'
|
||||
),
|
||||
url(
|
||||
regex=r'^setup/list/$', view=SmartLinkListView.as_view(),
|
||||
name='smart_link_list'
|
||||
|
||||
@@ -14,12 +14,14 @@ from mayan.apps.common.generics import (
|
||||
AddRemoveView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||
SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from mayan.apps.documents.events import event_document_type_edited
|
||||
from mayan.apps.documents.models import Document, DocumentType
|
||||
from mayan.apps.documents.permissions import (
|
||||
permission_document_type_edit, permission_document_view
|
||||
)
|
||||
from mayan.apps.documents.views import DocumentListView
|
||||
|
||||
from .events import event_smart_link_edited
|
||||
from .forms import SmartLinkConditionForm, SmartLinkForm
|
||||
from .icons import icon_smart_link_setup, icon_smart_link_condition
|
||||
from .links import link_smart_link_create, link_smart_link_condition_create
|
||||
@@ -32,6 +34,50 @@ from .permissions import (
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DocumentTypeSmartLinksView(AddRemoveView):
|
||||
main_object_method_add = 'smart_link_add'
|
||||
main_object_method_remove = 'smart_link_remove'
|
||||
main_object_permission = permission_document_type_edit
|
||||
main_object_model = DocumentType
|
||||
main_object_pk_url_kwarg = 'pk'
|
||||
secondary_object_model = SmartLink
|
||||
secondary_object_permission = permission_smart_link_edit
|
||||
list_available_title = _('Available smart links')
|
||||
list_added_title = _('Smart links enabled')
|
||||
related_field = 'smart_links'
|
||||
|
||||
def action_add(self, queryset, _user):
|
||||
event_document_type_edited.commit(
|
||||
actor=_user, target=self.main_object
|
||||
)
|
||||
for obj in queryset:
|
||||
self.main_object.smart_links.add(obj)
|
||||
event_smart_link_edited.commit(
|
||||
actor=_user, action_object=self.main_object, target=obj
|
||||
)
|
||||
|
||||
def action_remove(self, queryset, _user):
|
||||
event_document_type_edited.commit(
|
||||
actor=_user, target=self.main_object
|
||||
)
|
||||
for obj in queryset:
|
||||
self.main_object.smart_links.remove(obj)
|
||||
event_smart_link_edited.commit(
|
||||
actor=_user, action_object=self.main_object, target=obj
|
||||
)
|
||||
|
||||
def get_actions_extra_kwargs(self):
|
||||
return {'_user': self.request.user}
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'object': self.main_object,
|
||||
'title': _(
|
||||
'Smart links to enable for document type: %s'
|
||||
) % self.main_object,
|
||||
}
|
||||
|
||||
|
||||
class ResolvedSmartLinkView(DocumentListView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.document = get_object_or_404(
|
||||
|
||||
Reference in New Issue
Block a user