Пример #1
0
    def _get_fields(self):
        if self._fields is None:
            self._fields = fields = {}
            model = self._model
            non_hiddable_fnames = self._non_hiddable_fnames
            fconfigs = FieldsConfig.LocalCache()
            is_field_hidden = fconfigs.get_4_model(model).is_field_hidden
            excluded = self.excluded_fields

            # TODO: use meta.ModelFieldEnumerator (need to be improved for grouped options)
            for field in model._meta.fields:
                if field.get_tag('viewable') and not is_date_field(field) \
                   and not isinstance(field, excluded):
                    if isinstance(field, ModelForeignKey):
                        self._build_related_fields(field, fields, fconfigs)
                    elif not is_field_hidden(
                            field) or field.name in non_hiddable_fnames:
                        fields[field.name] = [field]

            for field in model._meta.many_to_many:
                # if field.get_tag('viewable'):
                if field.get_tag(FieldTag.VIEWABLE):  # TODO: test not viewable
                    self._build_related_fields(field, fields, fconfigs)

        return self._fields
Пример #2
0
    def _build_related_fields(self, field, fields, fconfigs):
        fname = field.name
        related_model = field.remote_field.model
        field_hidden = fconfigs.get_4_model(field.model).is_field_hidden(field)
        excluded = self.excluded_fields
        non_hiddable_fnames = self._non_hiddable_fnames

        # if field.get_tag('enumerable') and (not field_hidden or fname in non_hiddable_fnames):
        if (field.get_tag(FieldTag.ENUMERABLE)
                and (not field_hidden or fname in non_hiddable_fnames)):
            fields[field.name] = [field]

        is_sfield_hidden = fconfigs.get_4_model(related_model).is_field_hidden

        for subfield in related_model._meta.fields:
            if (
                    # subfield.get_tag('viewable')
                    subfield.get_tag(FieldTag.VIEWABLE)
                    and not is_date_field(subfield)
                    and not isinstance(subfield, excluded)):
                full_name = f'{fname}__{subfield.name}'

                if (not (field_hidden or is_sfield_hidden(subfield))
                        or full_name in non_hiddable_fnames):
                    fields[full_name] = [field, subfield]
Пример #3
0
    def _get_editing(self):
        model_field = self.model_field
        template_name = None
        tpl_dict = {'field': self}

        if isinstance(model_field, models.TextField):
            template_name = 'crudity/infopath/create_template/frags/editing/text_field.xml'

        elif is_date_field(model_field):
            template_name = 'crudity/infopath/create_template/frags/editing/date_field.xml'

        elif isinstance(model_field, models.FileField):
            tpl_dict.update(
                {'allowed_file_types': settings.ALLOWED_EXTENSIONS})
            template_name = 'crudity/infopath/create_template/frags/editing/file_field.xml'

        elif isinstance(model_field, models.ImageField) or \
            (isinstance(model_field, models.ForeignKey) and issubclass(model_field.remote_field.model, Document)):
            tpl_dict.update(
                {'allowed_file_types': settings.ALLOWED_IMAGES_EXTENSIONS})
            template_name = 'crudity/infopath/create_template/frags/editing/file_field.xml'

        elif isinstance(model_field, models.ManyToManyField):
            template_name = 'crudity/infopath/create_template/frags/editing/m2m_field.xml'

        return render_to_string(
            template_name, tpl_dict,
            request=self.request) if template_name is not None else None
Пример #4
0
 def _date_field_choices(self, report):
     return [
         ('', pgettext_lazy('reports-date_filter', 'None')),
         *((field.name, field.verbose_name)
           for field in report.ct.model_class()._meta.fields
           if is_date_field(field)),
     ]
Пример #5
0
    def _build_related_fields(self, field, fields, fconfigs):
        fname = field.name
        related_model = field.remote_field.model
        field_hidden = fconfigs.get_4_model(field.model).is_field_hidden(field)
        is_sfield_hidden = fconfigs.get_4_model(related_model).is_field_hidden
        non_hiddable_fnames = self._non_hiddable_fnames

        for subfield in related_model._meta.fields:
            # if subfield.get_tag('viewable') and is_date_field(subfield):
            if subfield.get_tag(FieldTag.VIEWABLE) and is_date_field(subfield):
                full_name = f'{fname}__{subfield.name}'

                if (not (field_hidden or is_sfield_hidden(subfield))
                        or full_name in non_hiddable_fnames):
                    fields[full_name] = [field, subfield]
Пример #6
0
 def _accept_field(self, field, not_hiddable_cell_keys):
     return super()._accept_field(
         field, not_hiddable_cell_keys) and is_date_field(field)
Пример #7
0
 def test_is_date_field(self):
     entity = CremeEntity()
     get_field = entity._meta.get_field
     self.assertTrue(meta.is_date_field(get_field('created')))
     self.assertFalse(meta.is_date_field(get_field('user')))