Pass the action dynamic form data to the class as a standard form_class
argument. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -68,6 +68,9 @@ class WorkflowAction(six.with_metaclass(WorkflowActionMetaclass, WorkflowActionB
|
||||
app.name, exception
|
||||
)
|
||||
|
||||
def __init__(self, form_data=None):
|
||||
self.form_data = form_data
|
||||
|
||||
def get_form_schema(self, request=None):
|
||||
return {
|
||||
'fields': self.fields or (),
|
||||
|
||||
@@ -253,7 +253,7 @@ class WorkflowStateAction(models.Model):
|
||||
return self.get_class().label
|
||||
|
||||
def get_class_instance(self):
|
||||
return self.get_class()(**self.loads())
|
||||
return self.get_class()(form_data=self.loads())
|
||||
|
||||
def loads(self):
|
||||
return json.loads(self.action_data)
|
||||
|
||||
@@ -54,17 +54,10 @@ class HTTPPostAction(WorkflowAction):
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, url=None, payload=None):
|
||||
self.url = url
|
||||
self.payload = payload
|
||||
|
||||
def get_form_schema(self, request):
|
||||
return {
|
||||
'fields': self.fields,
|
||||
'widgets': self.widgets
|
||||
}
|
||||
|
||||
def execute(self, context):
|
||||
self.url = self.form_data.get('url')
|
||||
self.payload = self.form_data.get('payload')
|
||||
|
||||
try:
|
||||
url = Template(self.url).render(
|
||||
context=Context(context)
|
||||
|
||||
@@ -33,12 +33,6 @@ class AttachTagAction(WorkflowAction):
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -55,14 +49,17 @@ class AttachTagAction(WorkflowAction):
|
||||
'widgets': self.widgets
|
||||
}
|
||||
|
||||
def get_tags(self):
|
||||
return Tag.objects.filter(pk__in=self.form_data.get('tags', ()))
|
||||
|
||||
def execute(self, context):
|
||||
for tag in self.tags:
|
||||
for tag in self.get_tags():
|
||||
tag.attach_to(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
|
||||
|
||||
class RemoveTagAction(WorkflowAction):
|
||||
class RemoveTagAction(AttachTagAction):
|
||||
fields = (
|
||||
{
|
||||
'name': 'tags', 'label': _('Tags'),
|
||||
@@ -73,39 +70,9 @@ class RemoveTagAction(WorkflowAction):
|
||||
},
|
||||
)
|
||||
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:
|
||||
for tag in self.get_tags():
|
||||
tag.remove_from(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user