2014-01-16 48 views
2

我有一個自定義的內容類型。我需要的是一個匿名用戶時,覆蓋基本鑑於此對象只:覆蓋自定義內容類型的方法index_html

class Imagesblock(folder.ATFolder): 
....... 
def index_html(self): 
    """ use the parent view """ 

    portal_state = getMultiAdapter((self, self.REQUEST), name="plone_portal_state") 
    if portal_state.anonymous()==True: 
     response = self.REQUEST.response 
     url = self.aq_parent.absolute_url() 
     return response.redirect(url, status=303) 
    else: 
     return super(Imagesblock).index_html() 

我應該使用超類的index_html,但我得到了一個錯誤:

AttributeError: 'super' object has no attribute 'index_html'

任何建議? 維託

+1

超(Imagesblock,'self').index_html()? – Mathias

回答

2

如果你想從超使用的方法index_html(),你應該

folder.ATFolder.index_html(self) 

假設folder.ATFolder是超類的名字來稱呼它。

編輯:

正如@Mathias提到的,你也可以叫它爲:

super(Imagesblock, self).index_html() 
+1

我不這麼認爲:http://stackoverflow.com/questions/576169/understanding-python-super-and-init-methods 問題出自@mathias的評論:你必須提供「自我」直到你使用Python 3.0 –

+0

我不知道爲什麼downvotes?我提到的方式不起作用?這個對我有用。 – Christian

+0

它在你編輯它之後工作:) –