def get_group(self, indexes=None):
     indexes = self._normalize_indexes(indexes, is_group=True)
     model_name = indexes.pop()
     expr_parts = []
     for parent_model, parent_item_index in indexes:
         expr_parts += ["/*[%s][count(preceding-sibling::*[%s]) = %d]" % (
             xpath_item(parent_model), xpath_item(), parent_item_index)]
     expr_parts += ["/*[@data-inline-model='%s' and %s]"
         % (model_name, xpath_cls('djn-group'))]
     expr = "/%s" % ("/".join(expr_parts))
     return self.selenium.find_element_by_xpath(expr)
Beispiel #2
0
 def get_group(self, indexes=None):
     indexes = self._normalize_indexes(indexes, is_group=True)
     model_name = indexes.pop()
     expr_parts = []
     for parent_model, parent_item_index in indexes:
         expr_parts += [
             "/*[%s][count(preceding-sibling::*[%s]) = %d]" %
             (xpath_item(parent_model), xpath_item(), parent_item_index)
         ]
     expr_parts += [
         "/*[@data-inline-model='%s' and %s]" %
         (model_name, xpath_cls('djn-group'))
     ]
     expr = "/%s" % ("/".join(expr_parts))
     return self.selenium.find_element_by_xpath(expr)
Beispiel #3
0
    def add_inline(self, indexes=None, model=None, **kwargs):
        model_name = "%s-%s" % (model._meta.app_label, model._meta.model_name)
        if issubclass(model, PolymorphicModel):
            base_model = get_base_polymorphic_model(model)
        else:
            base_model = model
        base_model_identifier = "%s-%s" % (base_model._meta.app_label,
                                           base_model._meta.model_name)

        if indexes:
            item = self.get_item(indexes)
            ctx_id = item.get_attribute("id")
            group_el = self.selenium.execute_script(
                'return $(arguments[0]).closest(".djn-group")[0]', item)
        else:
            group_el = self.get_group([base_model_identifier])
            ctx_id = group_el.get_attribute('id')

        error_desc = "%s in inline %s" % (model, indexes)

        add_selector = "#%s .djn-add-item a.djn-add-handler.djn-model-%s" % (
            ctx_id, base_model_identifier)
        add_els = self.selenium.find_elements_by_css_selector(add_selector)
        self.assertNotEqual(
            len(add_els), 0,
            "No inline add handlers found for %s" % (error_desc))
        self.click(add_els[0])

        add_link_selector = "return $('.polymorphic-type-menu:visible [data-type=\"%s\"]')[0]" % (
            model_name)
        poly_add_link = self.selenium.execute_script(add_link_selector)

        if poly_add_link:
            poly_add_link.click()

        indexes = self._normalize_indexes(indexes)

        group_el = self.selenium.execute_script(
            'return $(arguments[0]).closest(".djn-group")[0]', add_els[0])
        group_id = group_el.get_attribute('id')

        items_el = self.selenium.find_element_by_css_selector(
            '#%(id)s > .djn-fieldset > .djn-items, '
            "#%(id)s > .tabular.inline-related > .djn-fieldset > .djn-items, "
            '#%(id)s > .djn-items' % {'id': group_id})

        num_inlines = len(
            items_el.find_elements_by_xpath(
                './*[%s and not(%s)]' %
                (xpath_item(), xpath_cls('djn-empty-form'))))

        new_index = num_inlines - 1

        indexes.append([model_name, new_index])
        for field_name, val in six.iteritems(kwargs):
            self.set_field(field_name, val, indexes=indexes)
        return indexes
    def add_inline(self, indexes=None, model=None, **kwargs):
        model_name = "%s-%s" % (model._meta.app_label, model._meta.model_name)
        if issubclass(model, PolymorphicModel):
            base_model = get_base_polymorphic_model(model)
        else:
            base_model = model
        base_model_identifier = "%s-%s" % (
            base_model._meta.app_label, base_model._meta.model_name)

        if indexes:
            item = self.get_item(indexes)
            group_el = self.selenium.execute_script(
                'return $(arguments[0]).closest(".djn-group")[0]', item)
        else:
            group_el = self.get_group([base_model_identifier])

        group_id = group_el.get_attribute('id')

        error_desc = "%s in inline %s" % (model, indexes)

        add_selector = "#%s .djn-add-item a.djn-add-handler.djn-model-%s" % (
            group_id, base_model_identifier)
        add_els = self.selenium.find_elements_by_css_selector(add_selector)
        self.assertNotEqual(len(add_els), 0,
            "No inline add handlers found for %s" % (error_desc))
        self.click(add_els[0])

        add_link_selector = "return $('.polymorphic-type-menu:visible [data-type=\"%s\"]')[0]" % (
            model_name)
        poly_add_link = self.selenium.execute_script(add_link_selector)

        if poly_add_link:
            poly_add_link.click()

        indexes = self._normalize_indexes(indexes)

        group_el = self.selenium.execute_script(
            'return $(arguments[0]).closest(".djn-group")[0]', add_els[0])
        group_id = group_el.get_attribute('id')

        items_el = self.selenium.find_element_by_css_selector(
            '#%(id)s > .djn-fieldset > .djn-items, '
            "#%(id)s > .tabular.inline-related > .djn-fieldset > .djn-items, "
            '#%(id)s > .djn-items' % {'id': group_id})

        num_inlines = len(items_el.find_elements_by_xpath(
            './*[%s and not(%s)]' % (xpath_item(), xpath_cls('djn-empty-form'))))

        new_index = num_inlines - 1

        indexes.append([model_name, new_index])
        for field_name, val in six.iteritems(kwargs):
            self.set_field(field_name, val, indexes=indexes)
        return indexes
Beispiel #5
0
 def get_item(self, indexes):
     indexes = self._normalize_indexes(indexes)
     group_indexes = indexes[:-1]
     model_id, item_index = indexes[-1]
     app_label, model_name = model_id.split('-')
     model_cls = apps.get_model(app_label, model_name)
     if issubclass(model_cls, PolymorphicModel):
         base_model_cls = get_base_polymorphic_model(model_cls)
     else:
         base_model_cls = model_cls
     base_model_id = "%s-%s" % (base_model_cls._meta.app_label,
                                base_model_cls._meta.model_name)
     try:
         group = self.get_group(indexes=group_indexes + [base_model_id])
     except TypeError:
         group = self.get_group(indexes=group_indexes + [model_id])
     group_id = group.get_attribute('id')
     djn_items = self.selenium.find_element_by_css_selector(
         "#%(id)s > .djn-fieldset > .djn-items, "
         "#%(id)s > .tabular.inline-related > .djn-fieldset > .djn-items, "
         "#%(id)s > .djn-items" % {'id': group_id})
     model_name, item_index = indexes[-1]
     return djn_items.find_element_by_xpath("./*[%s][%d]" %
                                            (xpath_item(), item_index + 1))
 def get_item(self, indexes):
     indexes = self._normalize_indexes(indexes)
     group_indexes = indexes[:-1]
     model_id, item_index = indexes[-1]
     app_label, model_name = model_id.split('-')
     model_cls = apps.get_model(app_label, model_name)
     if issubclass(model_cls, PolymorphicModel):
         base_model_cls = get_base_polymorphic_model(model_cls)
     else:
         base_model_cls = model_cls
     base_model_id = "%s-%s" % (
         base_model_cls._meta.app_label, base_model_cls._meta.model_name)
     try:
         group = self.get_group(indexes=group_indexes + [base_model_id])
     except TypeError:
         group = self.get_group(indexes=group_indexes + [model_id])
     group_id = group.get_attribute('id')
     djn_items = self.selenium.find_element_by_css_selector(
         "#%(id)s > .djn-fieldset > .djn-items, "
         "#%(id)s > .tabular.inline-related > .djn-fieldset > .djn-items, "
         "#%(id)s > .djn-items" % {'id': group_id})
     model_name, item_index = indexes[-1]
     return djn_items.find_element_by_xpath(
         "./*[%s][%d]" % (xpath_item(), item_index + 1))