def search(self):

        response = self._response.copy()

        try:
            parent_url = urlparse(self.request.params['parent_url']).path
            if parent_url.startswith('/admin'):
                parent_url = parent_url.replace('/admin', '', 1)

            parent_url = parent_url.rsplit('.', 1)[0]
            info = MediaCollectionPageInfo.get_by_url(self.session, parent_url)
            items = []
            for item in info.node.children:
                dictified = item.dictify()
                dictified['file'] = {}
                if not item.file is None:
                    dictified['file'] = item.file.to_dict()
                dictified['translations'] = [t.dictify()
                                             for t in item.translations
                                             if t.lang == self.request.language]
                items.append(dictified)

        except KeyError as e:
            self.log.exception('Not URL param in the request.')
            self.session.rollback()
            self.request.response.status = 400
            response['msg'] = self.request.translate("Missing parameter: 'url'.")

        except NoResultFound as e:
            msg = "No MediaPageInfo found: %s" % parent_url
            self.log.exception(msg)
            self.session.rollback()
            self.request.response.status = 404
            response['msg'] = self.request.translate(msg)

        except Exception as e:
            self.log.exception('Unknown error.')
            self.session.rollback()
            self.request.response.status = 500
            response['msg'] = str(e)

        else:
            self.session.commit()
            response['success'] = True
            response['dataset'] = items
            response['dataset_length'] = len(response['dataset'])
            response['msg'] = self.request.translate("MediaItemPageInfo found.")

        finally:
            return response
    def _create(self, params):

            parent_url = urlparse(params['parent_url']).path
            if parent_url.startswith('/admin'):
                parent_url = parent_url.replace('/admin', '', 1)
            parent_url = parent_url.rsplit('.', 1)[0]

            node_info = MediaCollectionPageInfo.get_by_url(self.session,
                                                           parent_url)

            # Node attributes.
            enabled = params.get('enabled', 'on')
            enabled = True if enabled.lower() == 'on' else False
            hidden = params.get('hidden', 'off')
            hidden = True if hidden.lower() == 'on' else False
            max_weight = Node.get_max_weight(self.session, node_info.node)
            weight = params.get('weight', max_weight)
            #self.log.debug(max_weight)
            weight = int(weight) + 1
            # Page attributes.
            home = params.get('home', 'off')
            home = True if home.lower() == 'on' else False
            sitemap_priority = params.get('sitemap_priority')
            sitemap_priority = int(sitemap_priority) if sitemap_priority else 1
            # FIXME: add the right view needed by MediaItemPage rendering.
            view = View.get(self.session, 1)
            file_id = params.get('file', {}).get('id')

            node = MediaItemPage(enabled=enabled,
                                 hidden=hidden,
                                 parent=node_info.node,
                                 weight=weight,
                                 home=home,
                                 sitemap_priority=sitemap_priority,
                                 view=view,
                                 file_id=file_id)

            # NodeInfo attributes.
            translation = params.get('translations')[0]
            label = translation['label']
            language = self.request.language
            # CommonInfo attributes.
            title = translation.get('title', label)
            url_part = translation.get('url_part', title).strip()
            url_part = urlify(url_part)
            meta_description = translation.get('meta_description')
            head_content = translation.get('head_content')
            # Page attributes.
            content = translation.get('content', '')

            node_info = MediaItemPageInfo(label=label,
                                          node=node,
                                          lang=language,
                                          title=title,
                                          url_part=url_part,
                                          meta_description=meta_description,
                                          head_content=head_content,
                                          content=content)

            self.session.add(node)
            self.session.add(node_info)
            node_info.translate(enabled_only=True)

            return node