##### # This python file is used to generate js files for redux import os from django import template ############ # Need to do this first so that Django template engine is working import django from django.conf import settings settings.configure(TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['.'], # if you want the templates from a file 'APP_DIRS': False, # we have no apps }, ]) django.setup() ########## current_dir = os.path.dirname(os.path.realpath(__file__)) templates_dir = current_dir + '/templates/' saving_dir = os.path.realpath(current_dir + "/../src/generated/") if not os.path.exists(saving_dir): os.makedirs(saving_dir) templates = [ 'action-types', 'actions', 'reducers' ] contexts = [ { 'NAME': 'UNIVERSITIES', 'name': 'universities' }, { 'NAME': 'COUNTRIES', 'name': 'countries' }, { 'NAME': 'MAIN_CAMPUS', 'name': 'mainCampus' } ] def read_file(file): with open(file, "r") as myfile: return myfile.read() def write_file(file, data): with open(file, 'w') as the_file: the_file.write(data) for filename in templates: t = template.Template( read_file(os.path.join(templates_dir, filename + '.tpl'))) output = "" for tmpC in contexts: c = template.Context(tmpC) output += t.render(c) + "\n\n" write_file(os.path.join(saving_dir, filename + '.js'), output)