a
    DgN	                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ dd	lmZ dd
lmZ dddZe jdd Zdd ZdS )    N)ImproperlyConfigured)ManyToOneRel)fields_for_model)formfield_for_dbfield)PanelPlaceholder   )Panel)
FieldPanel)
ObjectListc           	   	   C   s   t | dr| jS g }g }|r&|| t| |td}| D ]@\}}z|j }W n tyh   t	}Y n0 ||}|
| q<|S )Npanels)excludeZformfield_callback)hasattrr   extendr   r   itemsZwidgetZ	get_panelAttributeErrorr	   append)	modelr   r   Z_excludefields
field_namefieldZpanel_classpanel r   _/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/panels/model_utils.py*extract_panel_definitions_from_model_class   s"    


r   c                 C   s,   t | dr| j}nt| }t|}|| S )zL
    Get the panel to use in the Wagtail admin when editing this model.
    edit_handler)r   r   r   r
   Zbind_to_model)r   r   r   r   r   r   get_edit_handler)   s
    
r   c                 C   s   g }|D ]}t |tr"|| qt |trD|  }r|| qt |tr| j|}t |trddl	m
} ||| q|t| qtd|t|f q|S )z
    Given a list which may be a mixture of Panel instances and strings (representing field/relation names),
    expand it into a flat list of Panel instances
    r   )InlinePanelz>Invalid panel definition %r - expected Panel or string, got %r)
isinstancer   r   r   Z	constructstrZ_meta	get_fieldr   Zinline_panelr   r	   r   type)r   r   resultr   Z
real_panelr   r   r   r   r   expand_panel_list8   s&    




r"   )N)	functoolsZdjango.core.exceptionsr   Z'django.db.models.fields.reverse_relatedr   Zdjango.forms.modelsr   Zwagtail.admin.forms.modelsr   Zwagtail.modelsr   baser   Zfield_panelr	   groupr
   r   cacher   r"   r   r   r   r   <module>   s   

