Convert the two_state_widget to a class and update it to use the new icon class.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-08-04 16:56:03 -04:00
parent 7a4202b459
commit 4f028b1f54
12 changed files with 89 additions and 52 deletions

View File

@@ -16,6 +16,9 @@ icon_current_user_locale_profile_edit = Icon(
driver_name='fontawesome', symbol='globe'
)
icon_documentation = Icon(driver_name='fontawesome', symbol='book')
icon_fail = Icon(
driver_name='fontawesome', symbol='times'
)
icon_forum = Icon(
driver_name='fontawesome', symbol='life-ring'
)
@@ -31,6 +34,9 @@ icon_menu_user = Icon(
icon_object_error_list_with_icon = Icon(
driver_name='fontawesome', symbol='lock'
)
icon_ok = Icon(
driver_name='fontawesome', symbol='check'
)
icon_packages_licenses = Icon(
driver_name='fontawesome', symbol='certificate'
)
@@ -43,3 +49,4 @@ icon_support = Icon(
icon_tools = Icon(
driver_name='fontawesome', symbol='wrench'
)

View File

@@ -5,6 +5,8 @@ from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from icons import icon_fail as default_icon_fail, icon_ok as default_icon_ok
class DisableableSelectWidget(forms.SelectMultiple):
allow_multiple_selected = True
@@ -76,8 +78,22 @@ class TextAreaDiv(forms.widgets.Widget):
super(TextAreaDiv, self).__init__(default_attrs)
def two_state_template(state, ok_icon='fa fa-check', fail_icon='fa fa-times'):
if state:
return mark_safe('<i class="text-success {}"></i>'.format(ok_icon))
class TwoStateWidget(object):
def __init__(self, state, icon_ok=None, icon_fail=None):
self.state = state
self.icon_ok = icon_ok or default_icon_ok
self.icon_fail = icon_fail or default_icon_fail
def render(self):
if self.state:
return mark_safe(
'<div class="text-success">{}</div>'.format(
self.icon_ok.render()
)
)
else:
return mark_safe('<i class="text-danger {}"></i>'.format(fail_icon))
return mark_safe(
'<div class="text-danger">{}</div>'.format(
self.icon_fail.render()
)
)

View File

@@ -14,7 +14,7 @@ from common import (
MayanAppConfig, menu_facet, menu_main, menu_object, menu_secondary,
menu_setup, menu_tools
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from documents.signals import post_document_created, post_initial_document_type
from mayan.celery import app
from navigation import SourceColumn
@@ -80,7 +80,9 @@ class DocumentIndexingApp(MayanAppConfig):
SourceColumn(source=Index, label=_('Slug'), attribute='slug')
SourceColumn(
source=Index, label=_('Enabled'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
SourceColumn(
@@ -108,13 +110,15 @@ class DocumentIndexingApp(MayanAppConfig):
)
SourceColumn(
source=IndexTemplateNode, label=_('Enabled'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
SourceColumn(
source=IndexTemplateNode, label=_('Has document links?'),
func=lambda context: two_state_template(
context['object'].link_documents
)
func=lambda context: TwoStateWidget(
state=context['object'].link_documents
).render()
)
SourceColumn(

View File

@@ -15,7 +15,7 @@ from common import (
from common.classes import ModelAttribute
from common.links import link_object_error_list
from common.permissions_runtime import permission_error_log_view
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from mayan.celery import app
from navigation import SourceColumn
@@ -198,7 +198,9 @@ class DocumentStatesApp(MayanAppConfig):
SourceColumn(
source=WorkflowState, label=_('Is initial state?'),
func=lambda context: two_state_template(context['object'].initial)
func=lambda context: TwoStateWidget(
state=context['object'].initial
).render()
)
SourceColumn(
source=WorkflowState, label=_('Completion'), attribute='completion'
@@ -209,7 +211,9 @@ class DocumentStatesApp(MayanAppConfig):
)
SourceColumn(
source=WorkflowStateAction, label=_('Enabled?'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
SourceColumn(
source=WorkflowStateAction, label=_('When?'),

View File

@@ -17,7 +17,7 @@ from common import (
from common.classes import ModelAttribute
from common.dashboards import dashboard_main
from common.signals import post_initial_setup
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from converter.links import link_transformation_list
from converter.permissions import (
permission_transformation_create,
@@ -251,7 +251,9 @@ class DocumentsApp(MayanAppConfig):
SourceColumn(
source=DocumentTypeFilename, label=_('Enabled'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
# DeletedDocument

View File

@@ -8,7 +8,7 @@ from common import (
MayanAppConfig, menu_main, menu_object, menu_secondary, menu_tools,
menu_user
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from navigation import SourceColumn
from .links import (
@@ -75,9 +75,9 @@ class EventsApp(MayanAppConfig):
)
SourceColumn(
source=Notification, label=_('Seen'),
func=lambda context: two_state_template(
func=lambda context: TwoStateWidget(
state=context['object'].read
)
).render()
)
menu_main.bind_links(

View File

@@ -10,7 +10,7 @@ from common import (
MayanAppConfig, menu_facet, menu_object, menu_secondary, menu_setup,
menu_sidebar
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from navigation import SourceColumn
from .links import (
@@ -65,12 +65,16 @@ class LinkingApp(MayanAppConfig):
)
SourceColumn(
source=SmartLink, label=_('Enabled'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
SourceColumn(
source=SmartLinkCondition, label=_('Enabled'),
func=lambda context: two_state_template(context['object'].enabled)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
menu_facet.bind_links(

View File

@@ -12,7 +12,7 @@ from common import (
MayanAppConfig, menu_object, menu_multi_item, menu_secondary, menu_setup,
menu_tools
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from mayan.celery import app
from navigation import SourceColumn
@@ -60,15 +60,15 @@ class MailerApp(MayanAppConfig):
)
SourceColumn(
source=UserMailer, label=_('Default?'),
func=lambda context: two_state_template(
context['object'].default
)
func=lambda context: TwoStateWidget(
state=context['object'].default
).render()
)
SourceColumn(
source=UserMailer, label=_('Enabled?'),
func=lambda context: two_state_template(
context['object'].enabled
)
func=lambda context: TwoStateWidget(
state=context['object'].enabled
).render()
)
SourceColumn(
source=UserMailer, label=_('Label'), attribute='backend_label'

View File

@@ -14,7 +14,7 @@ from common import (
menu_setup, menu_sidebar
)
from common.classes import ModelAttribute
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from documents.search import document_page_search, document_search
from documents.signals import post_document_type_change
from mayan.celery import app
@@ -135,9 +135,9 @@ class MetadataApp(MayanAppConfig):
)
SourceColumn(
source=DocumentMetadata, label=_('Required'),
func=lambda context: two_state_template(
context['object'].is_required
)
func=lambda context: TwoStateWidget(
state=context['object'].is_required
).render()
)
app.conf.CELERY_QUEUES.append(

View File

@@ -18,7 +18,7 @@ from common.views import (
ConfirmView, MultiFormView, SingleObjectCreateView,
SingleObjectDeleteView, SingleObjectEditView, SingleObjectListView
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from documents.models import DocumentType, Document
from documents.permissions import (
permission_document_create, permission_document_new_version
@@ -574,7 +574,7 @@ class SetupSourceListView(SingleObjectListView):
{
'name': _('Enabled'),
'attribute': encapsulate(
lambda entry: two_state_template(entry.enabled)
lambda entry: TwoStateWidget(state=entry.enabled).render()
)
},
),

View File

@@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _
from common import (
MayanAppConfig, menu_object, menu_secondary, menu_tools
)
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from navigation import SourceColumn
from .classes import CeleryQueue, Task
@@ -34,15 +34,15 @@ class TaskManagerApp(MayanAppConfig):
)
SourceColumn(
source=CeleryQueue, label=_('Default queue?'),
func=lambda context: two_state_template(
context['object'].is_default_queue
)
func=lambda context: TwoStateWidget(
state=context['object'].is_default_queue
).render()
)
SourceColumn(
source=CeleryQueue, label=_('Is transient?'),
func=lambda context: two_state_template(
context['object'].is_transient
)
func=lambda context: TwoStateWidget(
state=context['object'].is_transient
).render()
)
SourceColumn(
source=Task, label=_('Type'), attribute='task_type'
@@ -56,9 +56,9 @@ class TaskManagerApp(MayanAppConfig):
)
SourceColumn(
source=Task, label=_('Acknowledged'),
func=lambda context: two_state_template(
context['object'].kwargs['acknowledged']
)
func=lambda context: TwoStateWidget(
state=context['object'].kwargs['acknowledged']
).render()
)
SourceColumn(
source=Task, label=_('Arguments'),

View File

@@ -9,7 +9,7 @@ from acls.links import link_acl_list
from acls.permissions import permission_acl_edit, permission_acl_view
from common import menu_multi_item, menu_object, menu_secondary, menu_setup
from common.apps import MayanAppConfig
from common.widgets import two_state_template
from common.widgets import TwoStateWidget
from metadata import MetadataLookup
from navigation import SourceColumn
from rest_api.fields import DynamicSerializerField
@@ -96,15 +96,15 @@ class UserManagementApp(MayanAppConfig):
)
SourceColumn(
source=User, label=_('Active'),
func=lambda context: two_state_template(
context['object'].is_active
)
func=lambda context: TwoStateWidget(
state=context['object'].is_active
).render()
)
SourceColumn(
source=User, label=_('Has usable password?'),
func=lambda context: two_state_template(
context['object'].has_usable_password()
)
func=lambda context: TwoStateWidget(
state=context['object'].has_usable_password()
).render()
)
menu_multi_item.bind_links(