2

I've a custom contentype. I need to override the base view of this objects only when is a anonymous user:

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()

I supposed to use the index_html of the super class, but I obtain an error:

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

Any suggestions? Vito

Vito
  • 1,201
  • 1
  • 10
  • 16

1 Answers1

2

If you want to use the method index_html() from the superclass, you should call it with

folder.ATFolder.index_html(self)

assuming folder.ATFolder is the name of the superclass.

Edit:

As @Mathias mentioned, you also could call it as:

super(Imagesblock, self).index_html()
Christian Tapia
  • 33,620
  • 7
  • 56
  • 73
  • 1
    I don't think so: http://stackoverflow.com/questions/576169/understanding-python-super-and-init-methods The problem is in the comment from @mathias: you must provide also "self" until you are on Python 3.0 – keul Jan 16 '14 at 15:26
  • And I don't really know why the downvotes? The way I mentioned doesn't work? It works for me. – Christian Tapia Jan 16 '14 at 15:39
  • The downvotes are because you said something which simply isn't true, which is that `super` calls the constructor. – Daniel Roseman Jan 16 '14 at 15:56
  • @DanielRoseman you are right, it was a confusion between languages, very early here. Edited. – Christian Tapia Jan 16 '14 at 15:58