create nodes throw terminal

This commit is contained in:
MardanovTimur 2019-03-23 06:24:51 +03:00
parent 45104749a0
commit f44babe153

View File

@ -12,15 +12,14 @@ INSTALLED_APPS = [app for app in settings.INSTALLED_APPS if 'django' not in app]
PY_FILES = ['node.py', 'edge.py', '__init__.py', 'lib.py', 'resolvers.py']
pythonic_init = """
from .node import {model_name}Node
pythonic_init = """from .node import {model_name}Node
"""
pythonic_node = """
#encoding=utf-8
pythonic_node = """#encoding=utf-8
from lazy_import import lazy_module, lazy_callable
from graphene_django import DjangoObjectType
from graphene_django.relationship import EdgeNode # edge initialization
from graphene.relay import Node
# lazy_modules imports
@ -35,9 +34,9 @@ class {model_name}Node(DjangoObjectType):
)
model = {model_name}
neomodel_filter_fields = {
neomodel_filter_fields = {{
# announce here dynamic filtering
}
}}
only_fields = ()
exclude_fields = ()
@ -78,6 +77,7 @@ class CommandArguments(BaseCommand):
"--app-module-models",
type=str,
dest="app_module_models",
default="models",
help="Choose the module of models",
)
parser.add_argument(
@ -93,7 +93,7 @@ class Command(CommandArguments):
help = "Django-GraphQL management module"
can_import_settings = True
def interpretate_model_to_graphqQL(self,
def interpretate_model_to_graphQL(self,
model,
out_application,
application,
@ -112,6 +112,7 @@ class Command(CommandArguments):
package_path = os.path.join(output_path, package_dir)
if os.path.exists(package_dir):
raise CommandError('Files for %s model already exists' % package_dir.capitalize())
try:
print("Create path environment %s" % package_dir)
os.mkdir(package_path)
for file_name in PY_FILES:
@ -121,7 +122,11 @@ class Command(CommandArguments):
model_module=app_module_models,
model_name=model.__name__))
elif file_name == '__init__.py':
file.write(pythonic_init.format(model.__name__))
file.write(pythonic_init.format(model_name=model.__name__))
else:
file.write("")
except:
pass
@ -142,40 +147,8 @@ class Command(CommandArguments):
if out_application not in INSTALLED_APPS:
raise CommandError('Application %s does\'nt exists' % out_application)
for model in models:
self.intepretate_model_to_graphQL(model,
self.interpretate_model_to_graphQL(model,
out_application,
application,
app_module_models)
# options_schema = options.get("schema")
# if options_schema and type(options_schema) is str:
# module_str, schema_name = options_schema.rsplit(".", 1)
# mod = importlib.import_module(module_str)
# schema = getattr(mod, schema_name)
# elif options_schema:
# schema = options_schema
# else:
# schema = graphene_settings.SCHEMA
# out = options.get("out") or graphene_settings.SCHEMA_OUTPUT
# if not schema:
# raise CommandError(
# "Specify schema on GRAPHENE.SCHEMA setting or by using --schema"
# )
# indent = options.get("indent")
# schema_dict = {"data": schema.introspect()}
# if out == '-':
# self.stdout.write(json.dumps(schema_dict, indent=indent))
# else:
# self.save_file(out, schema_dict, indent)
# style = getattr(self, "style", None)
# success = getattr(style, "SUCCESS", lambda x: x)
# self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out))