예제 #1
0
class ViewBuilderTestCase(TestCase):
    def setUp(self):
        self.builder = ViewBuilder('tests', 'testmodel', TestModelCrud)

    def test_get_model_class(self):
        model_class = self.builder.get_model_class
        self.assertEqual(model_class.__name__, "TestModel")

    def test_list_view(self):
        list_view = self.builder.generate_list_view()
        self.assertEqual(list_view.__name__, "TestmodelListView")
        self.assertEqual(list_view.table_pagination,
                         {'per_page': self.builder.tables2_pagination})

    def test_create_view(self):
        create_view = self.builder.generate_create_view()
        self.assertEqual(create_view.__name__, 'TestmodelCreateView')

    def test_detail_view(self):
        detail_view = self.builder.generate_detail_view()
        self.assertEqual(detail_view.__name__, 'TestmodelDetailView')

    def test_update_view(self):
        update_view = self.builder.generate_update_view()
        self.assertEqual(update_view.__name__, 'TestmodelUpdateView')

    def test_table_pagination(self):
        tables2_pagination = self.builder.tables2_pagination
        self.assertEqual(tables2_pagination, 20)

        # test the default pagination
        self.builder.tables2_pagination = None
        list_view = self.builder.generate_list_view()
        self.assertEqual(list_view.table_pagination, {'per_page': 10})

    def test_tables2_fields(self):
        tables2_fields = self.builder.tables2_fields
        self.assertEqual(tables2_fields, ('name', 'email'))

    def test_custom_list_view_permission(self):
        # test custom permission
        self.builder.permissions = dict(list='mycustom_list_perm')
        self.assertEqual(self.builder.view_permission('list'),
                         'mycustom_list_perm')

    def test_default_list_view_permission(self):
        # test auto generated (default) permission
        self.assertEqual(self.builder.view_permission('list'),
                         'tests.testmodel_list')

    def test_check_crud_views(self):
        self.builder.generate_crud()
        generated_views = [
            view_type for view_type in self.builder.classes.keys()
        ]
        expected_views = [
            'TestmodelCreateView', 'TestmodelListView', 'TestmodelDetailView',
            'TestmodelUpdateView', 'TestmodelDeleteView'
        ]
        self.assertEqual(sorted(generated_views), sorted(expected_views))
예제 #2
0
class UrlBuilder(BaseBuilder):
    def __init__(self, *args, **kwargs):
        super(UrlBuilder, self).__init__(*args, **kwargs)
        self.viewbuilder = ViewBuilder(*args, **kwargs)
        self.urls = self.generate_urls()

    def generate_urls(self):
        urls = []

        pluralized = text.plural(self.model)

        list_view = self.viewbuilder.generate_list_view()
        update_view = self.viewbuilder.generate_update_view()
        detail_view = self.viewbuilder.generate_detail_view()
        create_view = self.viewbuilder.generate_create_view()
        delete_view = self.viewbuilder.generate_delete_view()

        entries = [
            (r'^{}/{}/$', list_view.as_view(), '{}-{}-list'),
            (r'^{}/{}/(?P<pk>\d+)/$', detail_view.as_view(), '{}-{}-detail'),
            (r'^{}/{}/create/$', create_view.as_view(), '{}-{}-create'),
            (r'^{}/{}/(?P<pk>\d+)/update/$',
                update_view.as_view(),
                '{}-{}-update'),
            (r'^{}/{}/(?P<pk>\d+)/delete/$',
                delete_view.as_view(),
                '{}-{}-delete'),
        ]

        for entry in entries:
            address = entry[0].format(self.app, pluralized)
            url_name = entry[2].format(self.app, self.model)

            urls.append(
                url(address, entry[1], name=url_name),
            )
        return urls
class ViewBuilderTestCase(TestCase):
	def setUp(self):
		self.builder = ViewBuilder('tests', 'testmodel')

	def test_get_model_class(self):
		model_class = self.builder.get_model_class
		self.assertEqual(model_class.__name__, "TestModel")

	def test_list_view(self):
		list_view = self.builder.generate_list_view()
		self.assertEqual(list_view.__name__, "TestmodelListView")
		self.assertEqual(list_view.table_pagination, self.builder.tables2_pagination)

	def test_create_view(self):
		create_view = self.builder.generate_create_view()
		self.assertEqual(create_view.__name__, 'TestmodelCreateView')

	def test_detail_view(self):
		detail_view = self.builder.generate_detail_view()
		self.assertEqual(detail_view.__name__, 'TestmodelDetailView')

	def test_update_view(self):
		update_view = self.builder.generate_update_view()
		self.assertEqual(update_view.__name__, 'TestmodelUpdateView')

	def test_table_pagination(self):
		tables2_pagination = self.builder.tables2_pagination
		self.assertEqual(tables2_pagination, 20)

		# test the default pagination
		self.builder.tables2_pagination = None
		list_view = self.builder.generate_list_view()
		self.assertEqual(list_view.table_pagination, 10)

	def test_tables2_feilds(self):
		tables2_feilds = self.builder.tables2_fields
		self.assertEqual(tables2_feilds,  ('name', 'email'))
예제 #4
0
urlpatterns = []

tables = connection.introspection.table_names()

if tables:
    for app_model, base_crud in registry.items():
        app, model = app_model.split('-')
        viewbuilder = ViewBuilder(app, model, base_crud)

        urls = []
        pluralized = helpers.plural(model)

        list_view = viewbuilder.generate_list_view()
        update_view = viewbuilder.generate_update_view()
        detail_view = viewbuilder.generate_detail_view()
        create_view = viewbuilder.generate_create_view()
        delete_view = viewbuilder.generate_delete_view()

        entries = [
            (r'^{}/{}/$', list_view.as_view(), '{}-{}-list'),
            (r'^{}/{}/(?P<pk>\d+)/$', detail_view.as_view(), '{}-{}-detail'),
            (r'^{}/{}/create/$', create_view.as_view(), '{}-{}-create'),
            (r'^{}/{}/(?P<pk>\d+)/update/$',
                update_view.as_view(),
                '{}-{}-update'),
            (r'^{}/{}/(?P<pk>\d+)/delete/$',
                delete_view.as_view(),
                '{}-{}-delete'),
            ]
class ViewBuilderTestCase(TestCase):
    def setUp(self):
        self.builder = ViewBuilder('tests', 'testmodel', TestModelCrud)

    def test_get_model_class(self):
        model_class = self.builder.get_model_class
        self.assertEqual(model_class.__name__, "TestModel")

    def test_list_view(self):
        list_view = self.builder.generate_list_view()
        self.assertEqual(list_view.__name__, "TestmodelListView")
        self.assertEqual(list_view.table_pagination, {'per_page': self.builder.tables2_pagination})

    def test_create_view(self):
        create_view = self.builder.generate_create_view()
        self.assertEqual(create_view.__name__, 'TestmodelCreateView')

    def test_detail_view(self):
        detail_view = self.builder.generate_detail_view()
        self.assertEqual(detail_view.__name__, 'TestmodelDetailView')

    def test_update_view(self):
        update_view = self.builder.generate_update_view()
        self.assertEqual(update_view.__name__, 'TestmodelUpdateView')

    def test_table_pagination(self):
        tables2_pagination = self.builder.tables2_pagination
        self.assertEqual(tables2_pagination, 20)

        # test the default pagination
        self.builder.tables2_pagination = None
        list_view = self.builder.generate_list_view()
        self.assertEqual(list_view.table_pagination, {'per_page': 10})

    def test_tables2_feilds(self):
        tables2_feilds = self.builder.tables2_fields
        self.assertEqual(tables2_feilds,  ('name', 'email'))

    def test_custom_list_view_permission(self):
        # test custom permission
        self.builder.permissions = dict(list='mycustom_list_perm')
        self.assertEqual(
            self.builder.view_permission('list'),
            'mycustom_list_perm')

    def test_default_list_view_permission(self):
        # test auto generated (default) permission
        self.assertEqual(
            self.builder.view_permission('list'),
            'tests.testmodel_list')

    def test_check_crud_views(self):
        self.builder.generate_crud()
        generated_views = [
            view_type for view_type in self.builder.classes.keys()]
        expected_views = [
            'TestmodelCreateView',
            'TestmodelListView',
            'TestmodelDetailView',
            'TestmodelUpdateView',
            'TestmodelDeleteView'
        ]
        self.assertEqual(sorted(generated_views), sorted(expected_views))
예제 #6
0
    url(r'^$', crudlist_view, name='crud-index'),
]

tables = connection.introspection.table_names()

if 'django_content_type' in tables:
    for app_model, base_crud in registry.items():

        app, model, postfix_url = app_model.split('-', 2)
        viewbuilder = ViewBuilder(app, model, base_crud)

        urls = []

        list_view = viewbuilder.generate_list_view()
        update_view = viewbuilder.generate_update_view()
        detail_view = viewbuilder.generate_detail_view()
        create_view = viewbuilder.generate_create_view()
        delete_view = viewbuilder.generate_delete_view()

        entries = [
            (r'^{}/{}/$', list_view.as_view(), '{}-{}-list'),
            (r'^{}/{}/create/$', create_view.as_view(), '{}-{}-create'),
            (r'^{}/{}/(?P<pk>\w+)/$', detail_view.as_view(), '{}-{}-detail'),
            (r'^{}/{}/(?P<pk>\w+)/update/$', update_view.as_view(),
             '{}-{}-update'),
            (r'^{}/{}/(?P<pk>\w+)/delete/$', delete_view.as_view(),
             '{}-{}-delete'),
        ]

        for entry in entries:
            address = entry[0].format(app, postfix_url)