djangocms-cascade icon indicating copy to clipboard operation
djangocms-cascade copied to clipboard

optional render horizontal with EntangledModelFormMixin class

Open haricot opened this issue 5 years ago • 6 comments

In this image "Adapt Picture Zoom" is inline. ( save in List) I want to display forms EntangledModelFormMixinclass in inlines. (save in FiedJson)

what would be the best approach?

Capture d’écran du 2019-11-08 12-48-30

haricot avatar Nov 08 '19 12:11 haricot

by modifying admin/change_form.html and adding css logic on widgets this might be feasible, perhaps. Actually, it is not possible to put custom css classes and access formset on forms, only on widgets. The ideal will be responsive, inline if logic media-query. For now, we could add a color border to the form to delimit some of the FormMixins.

haricot avatar Nov 08 '19 13:11 haricot

Yes, this was one of the drawbacks I encountered, after I introduced django-entangled to Cascade. First I didn't find any quick solution for it, later I got used to it, and since the popping up plugin editors remain quite slim, it can even be considered as an advantage that a user only has to scroll vertically, but not horizontally. What do you think?

jrief avatar Nov 08 '19 16:11 jrief

There is a quick fix with the fieldset attribute. Its format simply allows it, parentheses take care of everything. And a little css to tweak for help if we need.

1 none) vertical 2 none) horizontal 3 none) mixed

    fieldsets = (
            (None, {
               'classes': ('custom_help',),
                'fields': (
                    ('some_fields'),('some_fields1'),  ('some_fields2')
                ),  
            }),
           (None, {
               'classes': ('custom_help'),
                'fields': (
                   ('some_fields3','some_fields4', 'some_fields5'), 
                ),    
            }),
            (None, {
               'classes': ('custom_help',),
                'fields': (
                    ('some_fields6',('some_fields7')),  ('some_fields8')
                ),
                
            }),
        )

haricot avatar Nov 10 '19 17:11 haricot

With from django.contrib.admin.options import flatten_fieldsets, there might be logic if in Meta there are an attribute entangled_fieldset is present:

class MixedHorizantalVerticalFormMixin(EntangledModelFormMixin):

    class Meta
        entangled_fieldset=( None, { "fields" : (('some_fields1',
             'some_fields2','some_fields3'),  'some_fields6', 'some_fields5')})

        #Otpional default: 'glossary'
        entangled_glossary_key='glossary' 
...
from django.contrib.admin.options import flatten_fieldsets 
...

class EntangledFormMetaclass(ModelFormMetaclass):
 
    def __new__(cls, class_name, bases, attrs, ):
          ...    
              entangled_fields=flatten_fieldsets((entangled_fieldset,))
              # ['some_fields1', 'some_fields2','some_fields3',  'some_fields6', 'some_fields5']
          ...

haricot avatar Nov 11 '19 11:11 haricot

Or rather, make entangled_fields accept the tuple format: I'm thinking of pulling a pull-request for django-entangled in this way.

 class Meta: 
       entangled_fields = {'glossary':  (('some_field1', ''some_field2', 'some_field3',) 'some_field4', ''some_field5')}

haricot avatar Nov 11 '19 16:11 haricot

OK, now I see what you mean. So basically you want django-entangled to behave similar to django.contrib.admin using fieldsets.

Yes, this would be a useful feature. The pull request then should go against django-entangled.

BTW: tuples. For readability, use them rarely. I only use them, if I want to signalize that the interacting API really expects that exact number of elements, rather than a variable list of elements. This for instance would be the tuples inside a list of choices.

jrief avatar Nov 12 '19 22:11 jrief