Esempio n. 1
0
    def handle(self, *args, **options):
        app_name = args[0]
        module = importlib.import_module(app_name)
        path = os.path.dirname(module.__file__) + os.sep
        
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/controllers', path + 'controllers', update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/templates', path + '/templates', update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/static', path + '/static', update=True)
        
        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/urls.py', path, update=True)
        
        urls_edit = CodeEditor(path + 'urls.py')
        urls_edit.replace_all('app', app_name)
        urls_edit.commit()
        project_path = os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))
        main_urls_edit = CodeEditor(project_path + os.sep + 'urls.py')
        main_urls_edit.insert_line("    (r'', include('%s'))," % (app_name + '.urls'), after='urlpatterns')
        main_urls_edit.commit()
        
        settings_edit = CodeEditor(project_path + os.sep + 'settings.py')
        settings_edit.insert_line("    '%s'," % app_name, 'INSTALLED_APPS')
        settings_edit.commit()
        # TODO urls.py edit: urlpatterns += (controller_method_resource_pattern, route(controller))
        # TODO settings.py edit: app

        
Esempio n. 2
0
    def handle(self, *args, **options):
        app_name = args[0].split('.')[0]
        module = importlib.import_module(app_name)
        path = os.path.dirname(module.__file__) + os.sep
        model_class = get_class(args[0])
        controller = model_class.__name__.lower()

        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/templates/sample', path + '/templates/' + controller , update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/templates/common', path + '/templates/common', update=True)
        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/controllers/sample.py', path + '/controllers/' + controller + '.py', update=True)

        controller_edit = CodeEditor(path + '/controllers/' + controller + '.py')
        controller_edit.replace_all('from djangobp.scaffold.model.models import Sample', 'from %s import %s' % (model_class.__module__, model_class.__name__))
        controller_edit.replace_all('Sample',  model_class.__name__)
        controller_edit.commit()