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')
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')
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))
def get_delete_url(self, instance): return cruds_utils.crud_url(instance, cruds_utils.ACTION_DELETE)
def get_detail_url(self, instance): return cruds_utils.crud_url(instance, cruds_utils.ACTION_DETAIL)
def get_update_url(self, instance): return cruds_utils.crud_url(instance, cruds_utils.ACTION_UPDATE)
def get_create_url(self): return cruds_utils.crud_url(self.model, cruds_utils.ACTION_CREATE)
def get_list_url(self): return cruds_utils.crud_url(self.model, cruds_utils.ACTION_LIST)
def test_crud_url_for_model(self): self.assertEqual( utils.crud_url(Author, utils.ACTION_LIST), '/testapp/author/' )
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/' )
def get_absolute_url(self): return cruds_utils.crud_url(self, cruds_utils.ACTION_DETAIL)