Ejemplo n.º 1
0
    def js_args(self, block):
        classname = [
            "field",
            camelcase_to_underscore(block.field.__class__.__name__),
            "widget-" + camelcase_to_underscore(block.field.widget.__class__.__name__),
            "fieldname-" + block.name,
        ]

        form_classname = getattr(block.meta, "form_classname", "")
        if form_classname:
            classname.append(form_classname)

        # Provided for backwards compatibility. Replaced with 'form_classname'
        legacy_classname = getattr(block.meta, "classname", "")
        if legacy_classname:
            classname.append(legacy_classname)

        meta = {
            "label": block.label,
            "required": block.required,
            "icon": block.meta.icon,
            "classname": " ".join(classname),
            "showAddCommentButton": getattr(
                block.field.widget, "show_add_comment_button", True
            ),
            "strings": {"ADD_COMMENT": _("Add Comment")},
        }
        if block.field.help_text:
            meta["helpText"] = block.field.help_text

        return [
            block.name,
            block.field.widget,
            meta,
        ]
Ejemplo n.º 2
0
    def js_args(self, block):
        classname = [
            'field',
            camelcase_to_underscore(block.field.__class__.__name__),
            'widget-' +
            camelcase_to_underscore(block.field.widget.__class__.__name__),
            'fieldname-' + block.name,
        ]

        form_classname = getattr(block.meta, 'form_classname', '')
        if form_classname:
            classname.append(form_classname)

        # Provided for backwards compatibility. Replaced with 'form_classname'
        legacy_classname = getattr(block.meta, 'classname', '')
        if legacy_classname:
            classname.append(legacy_classname)

        meta = {
            'label': block.label,
            'required': block.required,
            'icon': block.meta.icon,
            'classname': ' '.join(classname),
        }
        if block.field.help_text:
            meta['helpText'] = block.field.help_text

        return [
            block.name,
            block.field.widget,
            meta,
        ]
Ejemplo n.º 3
0
def fieldtype(bound_field):
    try:
        return camelcase_to_underscore(bound_field.field.__class__.__name__)
    except AttributeError:
        try:
            return camelcase_to_underscore(bound_field.__class__.__name__)
        except AttributeError:
            return ""
Ejemplo n.º 4
0
def fieldtype(bound_field):
    try:
        return camelcase_to_underscore(bound_field.field.__class__.__name__)
    except AttributeError:
        try:
            return camelcase_to_underscore(bound_field.__class__.__name__)
        except AttributeError:
            return ""
Ejemplo n.º 5
0
        def resolve_pages(self,
                          info: ResolveInfo,
                          parent: int = None,
                          **_kwargs):
            # session authentication
            #if info.context.user.is_anonymous:
            #    raise GraphQLError('You must be logged')

            query = wagtailPage.objects

            # prefetch specific type pages
            selections = set(
                camelcase_to_underscore(f.name.value)
                for f in info.field_asts[0].selection_set.selections
                if not isinstance(f, InlineFragment))
            for pf in registry.page_prefetch_fields.intersection(selections):
                query = query.select_related(pf)

            if parent is not None:
                parent_page = wagtailPage.objects.filter(id=parent).first()
                if parent_page is None:
                    raise ValueError(f'Page id={parent} not found.')
                query = query.child_of(parent_page)

            return with_page_permissions(
                info.context, query.specific()).live().order_by('path').all()
Ejemplo n.º 6
0
    def test_camelcase_to_underscore(self):
        test_cases = [('HelloWorld', 'hello_world'),
                      ('longValueWithVarious subStrings',
                       'long_value_with_various sub_strings')]

        for (original, expected_result) in test_cases:
            self.assertEqual(camelcase_to_underscore(original),
                             expected_result)
Ejemplo n.º 7
0
 def field_type(self):
     return camelcase_to_underscore(self.bound_field.field.__class__.__name__)
Ejemplo n.º 8
0
def fieldtype(bound_field):
    return camelcase_to_underscore(bound_field.field.__class__.__name__)
Ejemplo n.º 9
0
def widgettype(bound_field):
    return camelcase_to_underscore(bound_field.field.widget.__class__.__name__)
Ejemplo n.º 10
0
 def field_type(self):
     return camelcase_to_underscore(self.bound_field.field.__class__.__name__)
Ejemplo n.º 11
0
 def get_template(self, request):
     return "mail/%s.html" % (camelcase_to_underscore(self.__class__.__name__))
Ejemplo n.º 12
0
 def get_template_base_prefix(self, instance, **kwargs):
     return camelcase_to_underscore(type(instance).__name__) + '_'