Add the tag remove workflow state action.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -7,9 +7,9 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from acls.models import AccessControlList
|
||||
from document_states.classes import WorkflowAction
|
||||
from tags.models import Tag
|
||||
from tags.permissions import permission_tag_view
|
||||
from tags.permissions import permission_tag_attach, permission_tag_remove
|
||||
|
||||
__all__ = ('AttachTagAction',)
|
||||
__all__ = ('AttachTagAction', 'RemoveTagAction')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class AttachTagAction(WorkflowAction):
|
||||
logger.debug('user: %s', user)
|
||||
|
||||
queryset = AccessControlList.objects.filter_by_access(
|
||||
permission_tag_view, user, queryset=Tag.objects.all()
|
||||
permission_tag_attach, user, queryset=Tag.objects.all()
|
||||
)
|
||||
|
||||
self.fields[0]['kwargs']['queryset'] = queryset
|
||||
@@ -60,3 +60,52 @@ class AttachTagAction(WorkflowAction):
|
||||
tag.attach_to(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
|
||||
|
||||
class RemoveTagAction(WorkflowAction):
|
||||
fields = (
|
||||
{
|
||||
'name': 'tags', 'label': _('Tags'),
|
||||
'class': 'django.forms.ModelMultipleChoiceField', 'kwargs': {
|
||||
'help_text': _('Tags to remove from the document'),
|
||||
'queryset': Tag.objects.none(), 'required': False
|
||||
}
|
||||
},
|
||||
)
|
||||
label = _('Remove tag')
|
||||
widgets = {
|
||||
'tags': {
|
||||
'class': 'tags.widgets.TagFormWidget', 'kwargs': {
|
||||
'attrs': {'class': 'select2-tags'},
|
||||
'queryset': Tag.objects.none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, tags=None):
|
||||
if tags:
|
||||
self.tags = Tag.objects.filter(pk__in=tags)
|
||||
else:
|
||||
self.tags = Tag.objects.none()
|
||||
|
||||
def get_form_schema(self, request):
|
||||
user = request.user
|
||||
logger.debug('user: %s', user)
|
||||
|
||||
queryset = AccessControlList.objects.filter_by_access(
|
||||
permission_tag_remove, user, queryset=Tag.objects.all()
|
||||
)
|
||||
|
||||
self.fields[0]['kwargs']['queryset'] = queryset
|
||||
self.widgets['tags']['kwargs']['queryset'] = queryset
|
||||
|
||||
return {
|
||||
'fields': self.fields,
|
||||
'widgets': self.widgets
|
||||
}
|
||||
|
||||
def execute(self, context):
|
||||
for tag in self.tags:
|
||||
tag.remove_from(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user