def test_filters(self):
     self.author = test_helper.create_author(name='BarFoo')
     url = cruds_utils.crud_url(Author, cruds_utils.ACTION_LIST)
     response = self.app.get(url)
     form = response.forms[0]
     form['name'] = 'foo'
     response = form.submit()
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'BarFoo')
Ejemplo n.º 2
0
 def render(self, value, record, bound_column):
     if self.action:
         url = crud_url(record, self.action)
     else:
         url = record.get_absolute_url()
     attrs = AttributeDict((("href", url),))
     return format_html(
         "<a {attrs}>{text}</a>",
         attrs=attrs.as_html(),
         text=self.action_name,
     )
    def test_bulk_actions(self):
        self.author = test_helper.create_author()
        url = cruds_utils.crud_url(Author, cruds_utils.ACTION_LIST)
        response = self.app.get(url)

        form = response.forms[1]
        form['select_all'] = True
        response = form.submit(name='action', value='bulk_activate')
        self.assertEqual(response.status_code, 302)

        response = response.follow()
        self.assertContains(response, 'Bulk activate successful')
    def test_bulk_actions_with_intermediate_view(self):
        self.author = test_helper.create_author()
        url = cruds_utils.crud_url(Author, cruds_utils.ACTION_LIST)
        response = self.app.get(url)

        form = response.forms[1]
        form['select_all'] = True
        response = form.submit(name='action',
                               value='bulk_activate_with_confirmation')
        self.assertEqual(response.status_code, 200)

        form = response.form
        response = form.submit(name='submit')

        response = response.follow()
        self.assertContains(response, 'activated')
    def test_default(self):
        url = cruds_utils.crud_url(Author, cruds_utils.ACTION_LIST)
        response = self.app.get(url)
        self.assertEqual(response.status_code, 200)

        create_label = create_model_title(Author)
        self.assertContains(response, create_label)

        response = response.click(create_label)
        form = response.form
        self.assertIn('name', form.fields)
        self.assertIn('birthday', form.fields)
        form['name'] = 'foo bar'
        form['birthday'] = '2001-01-01'
        response = form.submit()

        self.assertEqual(response.status_code, 302)
        response = response.follow()

        self.assertContains(response, 'foo bar')

        edit_label = _('edit')
        self.assertContains(response, edit_label)
        response = response.click(edit_label)

        form = response.form
        self.assertIn('name', form.fields)
        self.assertIn('birthday', form.fields)
        form['name'] = 'BarFoo'
        response = form.submit()
        self.assertEqual(response.status_code, 302)
        response = response.follow()
        self.assertContains(response, 'BarFoo')

        edit_label = _('edit')
        self.assertContains(response, edit_label)
        response = response.click(edit_label)
        delete_label = _('delete')
        self.assertContains(response, delete_label)
        response = response.click(delete_label)
        form = response.form
        response = form.submit()
        response = response.follow()
        self.assertContains(response, _('Record has been deleted.'))
        self.assertNotContains(response, 'BarFoo')
Ejemplo n.º 6
0
 def bulk_activate(self, request, action_name, selection, select_all,
                   queryset):
     queryset.update(active=True)
     return self.add_message_and_redirect(
         'Bulk activate successful',
         cruds_utils.crud_url(Author, cruds_utils.ACTION_LIST))
Ejemplo n.º 7
0
 def get_delete_url(self, instance):
     return cruds_utils.crud_url(instance, cruds_utils.ACTION_DELETE)
Ejemplo n.º 8
0
 def get_detail_url(self, instance):
     return cruds_utils.crud_url(instance, cruds_utils.ACTION_DETAIL)
Ejemplo n.º 9
0
 def get_update_url(self, instance):
     return cruds_utils.crud_url(instance, cruds_utils.ACTION_UPDATE)
Ejemplo n.º 10
0
 def get_create_url(self):
     return cruds_utils.crud_url(self.model, cruds_utils.ACTION_CREATE)
Ejemplo n.º 11
0
 def get_list_url(self):
     return cruds_utils.crud_url(self.model, cruds_utils.ACTION_LIST)
Ejemplo n.º 12
0
 def test_crud_url_for_model(self):
     self.assertEqual(
         utils.crud_url(Author, utils.ACTION_LIST),
         '/testapp/author/'
     )
Ejemplo n.º 13
0
 def test_crud_url_for_instance(self):
     instance = Author.objects.create(name='foo')
     self.assertEqual(
         utils.crud_url(instance, utils.ACTION_DETAIL),
         '/testapp/author/1/'
     )
Ejemplo n.º 14
0
 def get_absolute_url(self):
     return cruds_utils.crud_url(self, cruds_utils.ACTION_DETAIL)