2012-09-22 3 views
1

나는 아래 grok'ed plone.directives.form 코드가 :헤드 <style> 블록

는이 양식 결과
class EditForm(TreeFormMixin, form.SchemaForm): 
    """ 
    Edit form for our model. 

    We got one dummy button which allows us to manually inspect the data postback values. 
    """ 
    grok.context(ISiteRoot) 
    grok.name("dgftreeselect-test") 
    grok.require('zope2.View') 

    ignoreContext = True 
    schema = IFormSchema 

    label = u"Tree selection demo and manual testing" 

    @button.buttonAndHandler(u'Turbo boost') 
    def handleApply(self, action): 

     data, errors = self.extractData() 
     if errors: 
      self.status = self.formErrorsMessage 
      return 

     raise ActionExecutionError(Invalid(u"Please see that data stays intact over postback")) 

- 찾고 좋은되지 않습니다 :

DGFs in the action

데모 형식이므로 모든 관련 자료를 동일한 .py 파일에 보관하고 싶습니다. 그러나 양식이 못 생겨서 CSS 스타일의 가장 중요한 문제를 해결하기 위해 Python 소스 코드 문자열의 페이지에 <style> CSS 블록을 삽입하고 싶습니다.

plone.app.forms/BrowserViews가 <style> 블록을 <head> 또는 그 결과 HTML 페이지의 일부에 삽입하도록 제공하는 후크 유형은 무엇입니까? 이 작업을 위해 추가 파일 및 CSS 등록을 만들지 않는 것이 좋습니다.

전체 소스 :

https://github.com/miohtama/collective.z3cform.dgftreeselect/blob/master/src/collective/z3cform/dgftreeselect/testform.py

답변

2

plone.app.z3cform 및 조프 브라우저 뷰는 직접 머리로 지정 일을 주입하기 위해 어떤 후크를 제공하지 않습니다,하지만 당신은을 지정하여 사용자 정의 템플릿을 사용할 수 있습니다 양식 클래스의 템플릿 속성 :

template = grok.Template('path/to/template.pt') 

그런 다음 template.pt에 style_slot을 입력하여 스타일을 포함하십시오. 전체 템플릿은 다음과 같을 수 있습니다.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" 
     xmlns:tal="http://xml.zope.org/namespaces/tal" 
     xmlns:metal="http://xml.zope.org/namespaces/metal" 
     xmlns:i18n="http://xml.zope.org/namespaces/i18n" 
     lang="en" 
     metal:use-macro="context/main_template/macros/master" 
     i18n:domain="plone"> 
<body> 

<metal:block fill-slot="style_slot"> 
    <style type="text/css"> 
     /* insert styles here */ 
    </style> 
</metal:block> 

<metal:content-core fill-slot="main"> 
    <metal:content-core define-macro="content-core"> 
     <tal:button metal:use-macro="context/@@ploneform-macros/titlelessform" /> 
    </metal:content-core> 
</metal:content-core> 

</body> 
</html> 

위젯이 렌더링 될 때마다 스타일이 제공되어야하기 때문에 이는 권장되지 않습니다. 대신 일반적으로 portal_css 도구에서 CSS를 등록하는 것이 좋습니다.

+0

확인. 이것은 내가 생각하고 있던 것입니다. plone.app.z3cform에 후크를 추가하여 템플릿 + 채우기 대신 하나의 서브 뷰나 기능을 제공 할 수 있습니까? 예 : view.head? 뷰 전용 자바 스크립트 변수 삽입에도 유용합니다. plone.app.z3cform 패키지에서이 작업을 할 수 있습니다. –