def run(): constants = globals.Constants() print('make migrations:') process_make_migrations = subprocess.Popen(r'python manage.py makemigrations', cwd=constants.goBack + constants.targetDestination) make_migrations_output = process_make_migrations.communicate()[0] print(make_migrations_output) print('migrate:') process_migrate = subprocess.Popen(r'python manage.py migrate', cwd=constants.goBack + constants.targetDestination) process_migrate_output = process_migrate.communicate()[0] print(process_migrate_output)
import os from jinja2 import Environment, FileSystemLoader import globals constants = globals.Constants() def render_template(template_filename, context): path = os.path.dirname(os.path.abspath(__file__)) print(os.path.join(path, '..', constants.targetDestination + "app\\")) template_environment = Environment( extensions=['jinja2.ext.loopcontrols'], autoescape=False, loader=FileSystemLoader( os.path.join(path, '..', constants.targetDestination + "app\\")), trim_blocks=False) return template_environment.get_template(template_filename).render(context) def create_views_py_file(parsed_model, mapper): filename = constants.goBack + constants.targetDestination + "app\\" + "views.py" context = {'m_models': parsed_model, 'm_mapper': mapper} with open(filename, 'w') as f: python_models = render_template('views.py.jinja2', context) f.write(python_models)