[Tutor] loops

Norman Khine norman at khine.net
Wed Apr 29 09:05:22 CEST 2009


hello,
i have the following code:

if unique_id is not None:
    training = self.get_site_root()
    from training import Training
    # link back to news item
    root = context.root
    formats = ['itinerary', 'news']
    for document in formats:
        results = root.search(format=document, unique_id=unique_id)
        if results:
            result = results.get_documents()
            for item in result:
                print item.abspath
                item = self.get_handler(item.abspath)
                namespace['item_title'] = item.get_property('dc:title')
                if isinstance(training, Training):
                    namespace['item_url'] = item.abspath
                else:
                    # Need to strip the '/companies' from the path
                    #namespace['item_url'] = Path(item.abspath)[1:]
                    namespace['item_url'] = Path(item.abspath)
        else:
            namespace['item_title'] = None
            namespace['item_url'] = None

is there a way to optimise the loop for 'formats'

thanks


More information about the Tutor mailing list