Esempio n. 1
0
    def generate_detail_view(self):
        name = model_class_form(self.model + 'DetailView')
        detail_args = dict(
            model=self.get_model_class,
            template_name='object_detail.html'
            )

        detail_class = type(name, (CrudBuilderMixin, DetailView), detail_args)
        self.classes[name] = detail_class
        return detail_class
Esempio n. 2
0
    def generate_delete_view(self):
        name = model_class_form(self.model + 'DeleteView')
        delete_args = dict(
            model=self.get_model_class,
            template_name='object_delete.html',
            success_url=reverse_lazy('{}-{}-list'.format(self.app, self.model))
            )

        delete_class = type(name, (CrudBuilderMixin, DeleteView), delete_args)
        self.classes[name] = delete_class
        return delete_class
Esempio n. 3
0
    def generate_create_view(self):
        name = model_class_form(self.model + 'CreateView')
        create_args = dict(
            form_class=self.get_actual_form(),
            model=self.get_model_class,
            template_name='object_create.html',
            success_url=reverse_lazy('{}-{}-list'.format(self.app, self.model))
            )

        create_class = type(name, (CrudBuilderMixin, CreateView), create_args)
        self.classes[name] = create_class
        return create_class
Esempio n. 4
0
    def generate_list_view(self):
        name = model_class_form(self.model + 'ListView')
        list_args = dict(
            model=self.get_model_class,
            context_object_name=plural(self.model),
            template_name='object_list.html',
            table_class=self.get_actual_table(),
            context_table_name='table_objects',
            table_pagination=self.tables2_pagination or 10
            )

        list_class = type(
            name,
            (BaseListViewMixin, SingleTableView),
            list_args
            )
        self.classes[name] = list_class
        return list_class
Esempio n. 5
0
    def generate_table(self):
        model_class = self.get_model_class()
        detail_url_name = '{}-{}-detail'.format(self.app, self.model)

        main_attrs = dict(
            id=tables.LinkColumn(detail_url_name, args=[A('pk')])
            )

        meta_attrs = dict(
            model=model_class,
            fields=('id',) + self.tables2_fields if self.tables2_fields else ('id',),
            attrs={
                "class": self.tables2_css_class,
                "empty_text": "No {} exist".format(plural(self.model))
            })

        main_attrs['Meta'] = type('Meta', (), meta_attrs)
        klass = type(
            model_class_form(self.model + 'Table'),
            (tables.Table,),
            main_attrs
            )
        return klass