Add support for form media to DynamicFormMixin

Fix tag attach and remove action form media.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-06-09 02:30:13 -04:00
parent e5c92487de
commit 2ae2dfd687
5 changed files with 19 additions and 5 deletions

View File

@@ -288,6 +288,8 @@
* Disable hiding page navigation on idle.
* Display namespace in the transition trigger view.
* Sort events list in the transition trigger view.
* Add support for form media to DynamicFormMixin.
* Fix tag attach and remove action form media.
3.1.11 (2019-04-XX)
===================

View File

@@ -717,6 +717,8 @@ Other changes
- Disable hiding page navigation on idle.
- Display namespace in the transition trigger view.
- Sort events list in the transition trigger view.
- Add support for form media to DynamicFormMixin.
- Fix tag attach and remove action form media.
Removals

View File

@@ -173,6 +173,11 @@ class DynamicFormMixin(object):
self.fields[field_name] = field_class(**kwargs)
@property
def media(self):
return forms.Media(**self.schema.get('media', {}))
class DynamicForm(DynamicFormMixin, forms.Form):
pass

View File

@@ -78,7 +78,8 @@ class WorkflowAction(six.with_metaclass(WorkflowActionMetaclass, WorkflowActionB
def get_form_schema(self, request=None):
result = {
'fields': self.fields or (),
'widgets': getattr(self, 'widgets', {})
'media': getattr(self, 'media', {}),
'widgets': getattr(self, 'widgets', {}),
}
if hasattr(self, 'field_order'):

View File

@@ -24,6 +24,9 @@ class AttachTagAction(WorkflowAction):
},
}
label = _('Attach tag')
media = {
'js': ('tags/js/tags_form.js',)
}
widgets = {
'tags': {
'class': 'mayan.apps.tags.widgets.TagFormWidget', 'kwargs': {
@@ -33,6 +36,10 @@ class AttachTagAction(WorkflowAction):
}
permission = permission_tag_attach
def execute(self, context):
for tag in self.get_tags():
tag.attach_to(document=context['document'])
def get_form_schema(self, request):
user = request.user
logger.debug('user: %s', user)
@@ -46,16 +53,13 @@ class AttachTagAction(WorkflowAction):
return {
'fields': self.fields,
'media': self.media,
'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.get_tags():
tag.attach_to(document=context['document'])
class RemoveTagAction(AttachTagAction):
fields = {