Пример #1
0
    def handle(self):
        class_name = self.argument('name')
        view = View(App())
        class_directory = '{}{}.py'.format(self.base_directory, class_name)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        with open(class_directory, 'w+') as f:
            if view.exists(self.template):
                f.write(
                    view.render(self.template, {
                        'class': class_name.split('/')[-1]
                    }).rendered_template)
                self.info('{} Created Successfully!'.format(
                    self.scaffold_name))

        if self.option('migration'):
            model_name = class_name.lower() + 's'
            self.call('migration',
                      [('name', 'create_{}_table'.format(model_name)),
                       ('-c', model_name)])

        if self.option('seed'):
            seed_file = model_name
            seed_file = self.option('seed')

            self.call('seed', [('table', seed_file)])
Пример #2
0
    def handle(self):
        view = View(App())
        class_directory = 'databases/seeds/{}_table_seeder.py'.format(
            self.argument('table'))

        if not make_directory(class_directory):
            pass
            # return self.error('{0} Seeder Already Exists!'.format(self.argument('table')))

        conn = DB.get_schema_manager().list_table_columns(
            self.argument('table'))
        # docstring = '"""Model Definition (generated with love by Masonite) \n\n'
        # for name, column in conn.items():
        #     length = '({})'.format(column._length) if column._length else ''
        #     docstring += '{}: {}{} default: {}\n'.format(
        #         name, column.get_type(), length, column.get_default())

        f = open(class_directory, 'w+')
        if view.exists('scaffold/seed'):
            f.write(
                view.render('scaffold/seed', {
                    'table': self.argument('table'),
                    'columns': conn.items(),
                }).rendered_template)
            self.info('Seeder Created Successfully!')
            return f.close()
Пример #3
0
    def handle(self):
        class_name = self.argument('name') + self.postfix
        view = View(App())
        class_directory = '{}{}{}{}'.format(
            self.base_directory, class_name, self.suffix, self.file_extension)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        f = open(class_directory, 'w+')
        if view.exists(self.template):
            f.write(
                view.render(self.template, {
                            'class': class_name.split('/')[-1]}).rendered_template
            )
            self.info('{} Created Successfully!'.format(self.scaffold_name))
            return f.close()
    def handle(self):
        controller = self.argument('name')
        view = View(App())

        if not self.option('exact'):
            controller = controller + "Controller"

        if not make_directory('app/http/controllers/{0}.py'.format(controller)):
            return self.error('{0} Controller Exists!'.format(controller))

        with open('app/http/controllers/{0}.py'.format(controller), 'w+') as f:
            if view.exists('/masonite/snippets/scaffold/controller'):
                if self.option('resource'):
                    template = '/masonite/snippets/scaffold/controller_resource'
                else:
                    template = '/masonite/snippets/scaffold/controller'

                f.write(
                    view.render(
                        template, {'class': controller.split('/')[-1]}).rendered_template
                )

        self.info('Controller Created Successfully!')