clixdev
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: clixdev | ||
| Version: 0.3.8.6 | ||
| Version: 0.3.9.0 | ||
| Summary: https://clix.dev command line tool. | ||
@@ -5,0 +5,0 @@ Author-email: Eris Verne <erisverne7@gmail.com> |
+11
-2
@@ -7,3 +7,3 @@ [build-system] | ||
| name = "clixdev" | ||
| version = "0.3.8.6" | ||
| version = "0.3.9.0" | ||
| authors = [ | ||
@@ -17,3 +17,12 @@ { name="Eris Verne", email="erisverne7@gmail.com" }, | ||
| dependencies = [ | ||
| "requests" | ||
| "requests", | ||
| "termcolor", | ||
| "Django", | ||
| "Pillow", | ||
| "sqlparse", | ||
| "urllib3", | ||
| "certifi", | ||
| "asgiref", | ||
| "charset-normalizer", | ||
| "idna" | ||
| ] | ||
@@ -20,0 +29,0 @@ classifiers = [ |
| Metadata-Version: 2.1 | ||
| Name: clixdev | ||
| Version: 0.3.8.6 | ||
| Version: 0.3.9.0 | ||
| Summary: https://clix.dev command line tool. | ||
@@ -5,0 +5,0 @@ Author-email: Eris Verne <erisverne7@gmail.com> |
| requests | ||
| termcolor | ||
| Django | ||
| Pillow | ||
| sqlparse | ||
| urllib3 | ||
| certifi | ||
| asgiref | ||
| charset-normalizer | ||
| idna |
+226
-122
@@ -5,140 +5,244 @@ import os | ||
| import requests | ||
| # from pathlib import Path | ||
| from .trace import MANAGE, WSGI, SETTINGS, BASE_SETTINGS, VIEWS, BASE_MODELS, APP_URLS, DEF | ||
| # URLS, REQUIREMENTS, README, ADMIN | ||
| from .trace import MANAGE, WSGI, SETTINGS, BASE_SETTINGS, VIEWS, BASE_MODELS, APP_URLS | ||
| class Commands: | ||
| def __init__(self, terminal_token, project_token, path, *args, **kwargs): | ||
| self.args = args | ||
| self.kwargs = kwargs | ||
| self.user_dir = path | ||
| self.project_token = project_token | ||
| self.terminal_token = terminal_token | ||
| self.messages = [] | ||
| def generate(terminal_token, project_token, *args): | ||
| try: | ||
| _dir = os.getcwd() | ||
| _res = requests.post('http://localhost:8000/api/package/sync', | ||
| data=json.dumps({ | ||
| 'terminal_token': terminal_token, | ||
| 'project_token': project_token, | ||
| 'local_path': _dir + '/' + args[0] + '/' if args[0] else _dir + '/', | ||
| })).json() | ||
| # returns True if project already exists | ||
| def generate(self): | ||
| try: | ||
| _dir = os.getcwd() | ||
| _res = requests.post('https://clix.dev/api/package/generate', | ||
| data=json.dumps({ | ||
| 'terminal_token': self.terminal_token, | ||
| 'project_token': self.project_token, | ||
| 'local_path': _dir + '/' + self.user_dir + '/' if self.user_dir else _dir + '/', | ||
| })).json() | ||
| project_name = _res.get('misc').get('project_name') | ||
| working_dir = _dir + '/' + args[0] + '/' + project_name + '/' if args[0] else _dir + '/' + project_name + '/' | ||
| # TODO some logic needed here | ||
| if os.path.exists(working_dir): | ||
| shutil.rmtree(working_dir) | ||
| os.makedirs(working_dir) | ||
| base_file_tree = { | ||
| 'manage.py': MANAGE(project_name), | ||
| project_name + '/': [('__init__.py', ''), ('wsgi.py', WSGI(project_name)), ('settings.py', SETTINGS(_res.get('settings'),))], | ||
| 'db.sqlite3': '', | ||
| } | ||
| # , ('urls.py', URLS(_res.get('apps'))) | ||
| # 'README.md': README(), | ||
| # 'requirements.txt': REQUIREMENTS(), | ||
| # 'static/': [], | ||
| # 'templates/': [], removed at beta | ||
| # 'templates/admin/': [('base_site.html', """{% extends "admin/base_site.html" %}{% load static %}{% block extrahead %}<link rel="stylesheet" href="https://api.clix.dev/static/admin.css" type="text/css" />{% endblock %}""")], | ||
| if _res == False: | ||
| print('Please check your tokens and try again.\n') | ||
| return False | ||
| # generating base file tree | ||
| for k, v in base_file_tree.items(): | ||
| if type(v) is str: | ||
| with open(working_dir + k, 'w') as ff: | ||
| ff.write(base_file_tree.get(k)) | ||
| else: | ||
| os.mkdir(working_dir + k) | ||
| for f in v: | ||
| with open(working_dir + k + f[0], 'w') as ff: | ||
| ff.write(f[1]) | ||
| # generate apps | ||
| # removed ('urls.py', APP_URLS(app)), ('models.py', MODELS(app)), ('admin.py', ADMIN(app)), ('apps.py', f"from django.apps import AppConfig\n\n\nclass AppConfig(AppConfig):\n\tname = '{app.get('name')}'"), ('tests.py', 'from django.test import TestCase'), because of beta | ||
| # removed 'migrations/': [('__init__.py', '')] for beta | ||
| for app in _res.get('apps'): | ||
| file_extensions = { | ||
| '': [('__init__.py', ''), ('views.py', VIEWS(app))], | ||
| if _res.get('misc').get('project_path'): | ||
| if _res.get('misc').get('project_name') != _res.get('misc').get('last_generated_name'): | ||
| if os.path.exists(_res.get('misc').get('project_path') + _res.get('misc').get('last_generated_name') + "/"): | ||
| # rename project | ||
| os.chdir(_res.get('misc').get('project_path')) | ||
| os.rename(_res.get('misc').get('last_generated_name'), _res.get('misc').get('project_name')) | ||
| print('Warning: Project renamed. Please sync your project.') | ||
| return True | ||
| elif _res.get('misc').get('project_name') == _res.get('misc').get('last_generated_name'): | ||
| if os.path.exists(_res.get('misc').get('project_path') + _res.get('misc').get('project_name') + "/"): | ||
| print('\nWarning: Project already exists. Please sync your project instead.\n') | ||
| return True | ||
| print('\nGeneration started.') | ||
| project_name = _res.get('misc').get('project_name') | ||
| working_dir = _dir + '/' + self.user_dir + '/' + project_name + '/' if self.user_dir else _dir + '/' + project_name + '/' | ||
| # TODO some logic needed here | ||
| if os.path.exists(working_dir): | ||
| shutil.rmtree(working_dir) | ||
| os.makedirs(working_dir) | ||
| base_file_tree = { | ||
| 'manage.py': MANAGE(project_name), | ||
| project_name + '/': [('__init__.py', ''), ('wsgi.py', WSGI(project_name)), ('settings.py', SETTINGS(_res.get('settings'),))], | ||
| 'db.sqlite3': '', | ||
| } | ||
| # TODO can make this much simpler | ||
| for k, v in file_extensions.items(): | ||
| working_d = working_dir + 'clix' + '/' + k | ||
| os.mkdir(working_d) | ||
| for file_name, file_content in v: | ||
| with open(working_d + file_name, 'w') as ff: | ||
| ff.write(file_content) | ||
| # ('urls.py', URLS(_res.get('apps'))) | ||
| # 'README.md': README(), | ||
| # 'requirements.txt': REQUIREMENTS(), | ||
| # 'static/': [], | ||
| # 'templates/': [], removed at beta | ||
| # 'templates/admin/': [('base_site.html', """{% extends "admin/base_site.html" %}{% load static %}{% block extrahead %}<link rel="stylesheet" href="https://api.clix.dev/static/admin.css" type="text/css" />{% endblock %}""")], | ||
| sync(terminal_token, project_token, args) | ||
| # generating base file tree | ||
| for k, v in base_file_tree.items(): | ||
| if type(v) is str: | ||
| with open(working_dir + k, 'w') as ff: | ||
| ff.write(base_file_tree.get(k)) | ||
| else: | ||
| os.mkdir(working_dir + k) | ||
| for f in v: | ||
| with open(working_dir + k + f[0], 'w') as ff: | ||
| ff.write(f[1]) | ||
| # generate apps | ||
| # removed ('urls.py', APP_URLS(app)), ('models.py', MODELS(app)), ('admin.py', ADMIN(app)), ('apps.py', f"from django.apps import AppConfig\n\n\nclass AppConfig(AppConfig):\n\tname = '{app.get('name')}'"), ('tests.py', 'from django.test import TestCase'), because of beta | ||
| # removed 'migrations/': [('__init__.py', '')] for beta | ||
| for app in _res.get('apps'): | ||
| file_extensions = { | ||
| '': [('__init__.py', ''), ('views.py', VIEWS(app))], | ||
| } | ||
| # TODO can make this much simpler | ||
| for k, v in file_extensions.items(): | ||
| working_d = working_dir + 'clix' + '/' + k | ||
| os.mkdir(working_d) | ||
| for file_name, file_content in v: | ||
| with open(working_d + file_name, 'w') as ff: | ||
| ff.write(file_content) | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| raise Exception('base template error') | ||
| self.sync() | ||
| print('Generation successful.\n') | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| # raise Exception('base template error') | ||
| print('Something went wrong; please try again.\n') | ||
| return False | ||
| # creates clixdev.__path__/apps/clix/* | ||
| def sync(terminal_token, project_token, *args): | ||
| _res = requests.post('http://localhost:8000/api/package/sync', | ||
| data=json.dumps({ | ||
| 'terminal_token': terminal_token, | ||
| 'project_token': project_token, | ||
| })).json() | ||
| import clixdev | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps'): | ||
| os.mkdir(clixdev.__path__[0] + '/apps/clix/migrations') | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps/clix'): | ||
| os.mkdir(clixdev.__path__[0] + '/apps/clix/migrations') | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps/clix/migrations'): | ||
| os.mkdir(clixdev.__path__[0] + '/apps/clix/migrations') | ||
| f = open(clixdev.__path__[0] + '/apps' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps' + '/__init__.py', 777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/__init__.py', 777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix/migrations' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix/migrations' + '/__init__.py', 777) | ||
| # sync doesn't remove a function if you remove it from the dashboard | ||
| # sync does remove the endpoint url tho | ||
| def sync(self): | ||
| try: | ||
| _res = requests.post('https://clix.dev/api/package/sync', | ||
| data=json.dumps({ | ||
| 'terminal_token': self.terminal_token, | ||
| 'project_token': self.project_token, | ||
| })).json() | ||
| if _res == False: | ||
| print('Please check your tokens and try again.\n') | ||
| return False | ||
| _project_dir = _res.get('misc').get('last_generated_name') | ||
| # write urls based on _res -> api.clix.dev | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/urls.py', 'w') | ||
| f.write(APP_URLS(_res.get('apps')[0])) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/urls.py', 777) | ||
| if _res.get('misc').get('project_path'): | ||
| if _res.get('misc').get('project_name') != _project_dir: | ||
| if os.path.exists(_res.get('misc').get('project_path') + _project_dir + "/"): | ||
| # rename project | ||
| os.chdir(_res.get('misc').get('project_path')) | ||
| os.rename(_project_dir, _res.get('misc').get('project_name')) | ||
| print('Warning: Project renamed.') | ||
| _project_dir = _res.get('misc').get('project_name') | ||
| # SYNC | ||
| elif os.path.exists(_res.get('misc').get('project_path') + _res.get('misc').get('project_name') + "/"): | ||
| _project_dir = _res.get('misc').get('project_name') | ||
| # SYNC | ||
| else: | ||
| print('Error: Project cannot be found. Please generate your project first.') | ||
| return False | ||
| elif _res.get('misc').get('project_name') == _project_dir: | ||
| if not os.path.exists(_res.get('misc').get('project_path') + _res.get('misc').get('project_name') + "/"): | ||
| print("no project") | ||
| return False | ||
| # else: | ||
| # SYNC | ||
| else: | ||
| print('Error: Project cannot be found. Please generate your project first.') | ||
| return False | ||
| print('Sync started.') | ||
| import clixdev | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps'): | ||
| os.makedirs(clixdev.__path__[0] + '/apps/clix/migrations', 0o777) | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps/clix'): | ||
| os.makedirs(clixdev.__path__[0] + '/apps/clix/migrations', 0o777) | ||
| if not os.path.exists(clixdev.__path__[0] + '/apps/clix/migrations'): | ||
| os.makedirs(clixdev.__path__[0] + '/apps/clix/migrations', 0o777) | ||
| f = open(clixdev.__path__[0] + '/apps' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps' + '/__init__.py', 0o777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/models.py', 'w') | ||
| f.write(BASE_MODELS(_res.get('apps')[0])) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/models.py', 777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/settings.py', 'w') | ||
| f.write(BASE_SETTINGS(_res.get('misc').get('project_name'), _res.get('misc').get('secret_key'))) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/settings.py', 777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/__init__.py', 0o777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix/migrations' + '/__init__.py', 'w') | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix/migrations' + '/__init__.py', 0o777) | ||
| # urls | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/urls.py', 'w') | ||
| f.write(APP_URLS(_res.get('apps')[0])) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/urls.py', 0o777) | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/apps.py', 'w') | ||
| f.write("""from django.apps import AppConfig\n\nclass AppConfig(AppConfig):\n\tname = 'clixdev.apps.clix'\n""") | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/apps.py', 777) | ||
| # models | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/models.py', 'w') | ||
| f.write(BASE_MODELS(_res.get('apps')[0])) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/models.py', 0o777) | ||
| # settings | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/settings.py', 'w') | ||
| f.write(BASE_SETTINGS(_res.get('misc').get('project_name'), _res.get('misc').get('secret_key'))) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/settings.py', 0o777) | ||
| # import clix | ||
| os.chmod('/Users/ramtinmir/Programing/Clix/cli/project_1/clix' + '/views.py', 777) | ||
| f = open(_res.get('misc').get('project_path') + '/clix/views.py', 'r+') | ||
| lines = f.readlines() | ||
| has_def = False | ||
| for row in lines: | ||
| word = 'def X4D20C' | ||
| if row.find(word) == 0: | ||
| has_def = True | ||
| if not has_def: | ||
| f.write(f"""\n@csrf_exempt\ndef X4D20C(request, *args, **kwargs):\n\t# body = json.loads(request.body)\n\n\treturn JsonResponse({{}})\n\n""") | ||
| f.close() | ||
| # apps | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/apps.py', 'w') | ||
| f.write("""from django.apps import AppConfig\n\nclass AppConfig(AppConfig):\n\tname = 'clixdev.apps.clix'\n""") | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/apps.py', 0o777) | ||
| # not sure about views yet | ||
| f = open(clixdev.__path__[0] + '/apps/clix' + '/validators.py', 'w') | ||
| f.write(json.dumps("""[{"name": "API", "base_url": "api", "endpoints": [{"misc": {"endpoint_id": "ae0937d9-95e4-4ea1-9ff5-76312209e948", "is_draft": false, "token": "rcxxday", "name": "Get all users", "description": "The description", "base_url": "api"}, "request": {"method": "GET", "host": "localhost", "uri": "users/all"}, "headers": {"authorization": true, "body": {"0": ["auth-token", "str"]}}, "params": {"0": ["id", "uuid"]}, "body": {"type": "none", "payload": {}}, "response": {"code": "200", "message": "OK"}}], "models": [{"table_name": "User", "fields": {"0": ["D372D1", "id", "UUIDField", null, null, false, false, false, true, true], "1": ["F8B9D7", "f_name", "CharField", null, null, true, true, true, false, false], "2": ["D0BA20", "l_name", "CharField", null, null, true, true, true, false, false], "3": ["21341C", "created_at", "DateTimeField", null, null, false, false, true, false, false]}}]}]""")) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/validators.py', 777) | ||
| # TODO | ||
| if os.path.exists(_res.get('misc').get('project_path') + _project_dir + "/" + 'clix/views.py'): | ||
| f = open(_res.get('misc').get('project_path') + _project_dir + "/" + 'clix/views.py', 'r+') | ||
| content = f.read() | ||
| missing_def = [] | ||
| for endpoint in _res.get('apps')[0].get('endpoints'): | ||
| if 'def ' + endpoint.get('misc').get('token') not in content: | ||
| missing_def.append(endpoint) | ||
| for md in missing_def: | ||
| f.write(DEF(md)) | ||
| f.close() | ||
| else: | ||
| print('Error: Views cannot be found.') | ||
| return False | ||
| f = open(clixdev.__path__[0] + '/apps/clix/validations.json', 'w') | ||
| f.write(json.dumps(_res.get('validations'))) | ||
| f.close() | ||
| os.chmod(clixdev.__path__[0] + '/apps/clix' + '/validations.json', 0o777) | ||
| return True | ||
| print('Sync successful.') | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| # raise Exception('base template error') | ||
| print('Something went wrong; please try again.\n') | ||
| return False | ||
| def docs(self): | ||
| try: | ||
| _res = requests.post('https://clix.dev/api/package/docs', | ||
| data=json.dumps({ | ||
| 'terminal_token': self.terminal_token, | ||
| 'project_token': self.project_token, | ||
| })).json() | ||
| if _res == False: | ||
| print('Please check your tokens and try again.\n') | ||
| return False | ||
| print('Docs started.') | ||
| if _res.get('misc').get('project_path') and os.path.exists(_res.get('misc').get('project_path')): | ||
| f = open(_res.get('misc').get('project_path') + '/docs.json', 'w') | ||
| f.write(json.dumps(_res.get('docs'), indent=4)) | ||
| f.close() | ||
| os.chmod(_res.get('misc').get('project_path') + '/docs.json', 0o777) | ||
| else: | ||
| print('Error: Project cannot be found. Please generate your project first.') | ||
| return False | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| return False | ||
@@ -5,3 +5,2 @@ import os | ||
| from django.http import JsonResponse | ||
| # from clixdev.apps.clix import validators | ||
@@ -14,10 +13,3 @@ | ||
| def __call__(self, request): | ||
| print("custom middleware before next middleware/view") | ||
| # print( | ||
| # request.method, | ||
| # request.path, | ||
| # request.body, | ||
| # request.headers, | ||
| # request.content_type, | ||
| # ) | ||
| # print("\ncustom middleware before next middleware/view") | ||
@@ -28,66 +20,26 @@ # has_errors = False | ||
| # "headers": [], | ||
| # "params": [], | ||
| # "body": [], | ||
| # } | ||
| # wrk_dr = "/usr/local/.clix/CDBCB8/" | ||
| # import clixdev | ||
| # wrk_dr = clixdev.__path__[0] + "/apps/clix/" | ||
| # if not os.path.exists(wrk_dr): | ||
| # raise Exception('Please Sync your project') | ||
| # if not os.path.exists(wrk_dr) or \ | ||
| # not os.path.exists(wrk_dr + '/' + prj_tkn) or \ | ||
| # not os.path.exists(wrk_dr + '/' + prj_tkn + '/' + '_urls.txt') or \ | ||
| # not os.path.exists(wrk_dr + '/' + prj_tkn + '/' + '_models.txt') or \ | ||
| # not os.path.exists(wrk_dr + '/' + prj_tkn + '/' + '_validators.txt'): | ||
| # raise Exception('Sync your project using: clixdev sync') | ||
| # f = open(wrk_dr + '_validators.txt') | ||
| # app = json.load(f) | ||
| # f = open(wrk_dr + 'validations.json') | ||
| # validations = json.load(f) | ||
| # f.close() | ||
| # app = json.loads(app)[0] | ||
| # request = detecting correct endpoint details based on Request URI (if not in list pass) | ||
| """ | ||
| Sudo code: | ||
| if uri: | ||
| if method: | ||
| check headers (1.exist 2.type check) | ||
| check params (1.exist 2.type check) | ||
| check body* | ||
| check response* | ||
| else: | ||
| error method not allowed | ||
| else: | ||
| let django handle (endpoint doesn't exist) | ||
| """ | ||
| # validating request method | ||
| # if str(request.method) != str(app['endpoints'][0]['request']['method']): | ||
| # has_errors = True | ||
| # errors['request'].append( | ||
| # f"request {request.method} is not allowed") | ||
| # validating request headers | ||
| # for header in list(app['endpoints'][0]['headers']['body'].values()): | ||
| # if header[0] not in request.headers.keys(): | ||
| # has_errors = True | ||
| # errors['headers'].append( | ||
| # f"{header[0]} is missing from headers") | ||
| # else: | ||
| # if type(request.headers.keys()) != header[1]: | ||
| # for v in validations: | ||
| # if str(request.META['PATH_INFO']) == '/' + v[1] + '/' + v[2]: | ||
| # if str(request.META['REQUEST_METHOD']) == str(v[0]): | ||
| # for header in v[3]: | ||
| # h = 'HTTP_' + header[0].replace('-', '_').upper() | ||
| # if h not in request.META.keys(): | ||
| # has_errors = True | ||
| # errors['headers'].append(f"header {header[0]} is missing") | ||
| # pass | ||
| # else: | ||
| # has_errors = True | ||
| # errors['headers'].append( | ||
| # f"{header[0]} should be {header[1]}") | ||
| # errors['request'].append(f"request {request.META['REQUEST_METHOD']} is not allowed") | ||
| # validating request body type & payload | ||
| # for body_payload in list(app['endpoints'][0]['body']['payload'].values()): | ||
| # if body_payload[0] not in request.body.keys(): | ||
| # has_errors = True | ||
| # errors['body'].append("") | ||
| # validating request params | ||
| # for param in list(app['endpoints'][0]['params'].values()): | ||
| # if param[0] not in request.headers.keys(): | ||
| # has_errors = True | ||
| # errors['params'].append("") | ||
| # if has_errors: | ||
@@ -97,4 +49,4 @@ # return JsonResponse({"errors": errors}) if settings.DEBUG else JsonResponse(False, safe=False) | ||
| response = self.get_response(request) | ||
| print("custom middleware after response or previous middleware") | ||
| # print("custom middleware after response or previous middleware\n") | ||
| return response |
+20
-10
@@ -0,22 +1,32 @@ | ||
| import os | ||
| from termcolor import colored | ||
| def terminal(): | ||
| try: | ||
| def colored_text(text, color): | ||
| return colored(str(text), str(color)) | ||
| import argparse | ||
| parser = argparse.ArgumentParser(prog="clixdev", description="Clix.dev command line tool.") | ||
| parser.add_argument('action', choices=['generate', 'sync']) | ||
| parser.add_argument('terminal_token', type=str) | ||
| parser.add_argument('project_token', type=str) | ||
| parser.add_argument('-dir', type=str, required=False) | ||
| parser = argparse.ArgumentParser(prog="clixdev", usage=colored_text("\rusage: clixdev (--help -h) [generate, sync, docs] <token1> <token2> (--path -p)", "yellow"), | ||
| description=colored_text("The Command Line Interface for Clix (clix.dev). run clixdev -h for more.", 'green'), epilog=colored_text("What can be better? Tell us https://clix.dev/contact", "grey")) | ||
| parser.add_argument('action', choices=['generate', 'sync', 'docs'], help="""You can use this cli to generate a new project, sync your project as you develop, and create a simple documentation for your project.""", metavar=colored_text("action\t", "cyan")) | ||
| parser.add_argument('terminal_token', help='The 6 character token in your account page at clix.dev.', type=str) | ||
| parser.add_argument('project_token', help='The 6 character token in your projects page at clix.dev.', type=str) | ||
| parser.add_argument('-p', '--path', dest="path", help="Please specify an optional path to your Clix project.", type=lambda p: p if os.path.isdir(p) else NotADirectoryError(p), required=False, metavar='') | ||
| args = parser.parse_args() | ||
| if args.action == 'generate': | ||
| from .commands import generate | ||
| return generate(args.terminal_token, args.project_token, args.dir) | ||
| from .commands import Commands | ||
| return Commands(args.terminal_token, args.project_token, args.path, args).generate() | ||
| if args.action == 'sync': | ||
| from .commands import sync | ||
| return sync(args.terminal_token, args.project_token, args.dir) | ||
| from .commands import Commands | ||
| return Commands(args.terminal_token, args.project_token, args.path, args).sync() | ||
| if args.action == 'docs': | ||
| from .commands import Commands | ||
| return Commands(args.terminal_token, args.project_token, args.path, args).docs() | ||
| return False | ||
| except Exception as e: | ||
| print(e) | ||
| return False | ||
| return False |
+34
-17
@@ -175,14 +175,29 @@ def MANAGE(proj_name): | ||
| """) | ||
| # removed for beta | ||
| # \t#### Add Your Logic Here #### | ||
| # \tif request.method == '{req.get('method')}': | ||
| # \t\t\treturn JsonResponse({{ | ||
| # \t\t\t\t{responses} | ||
| # \t\t\t}}, safe=False) | ||
| # \t\texcept Exception as e: | ||
| # \t\t\treturn JsonResponse(False, safe=False) | ||
| # \treturn JsonResponse(False, safe=False) | ||
| return '\n'.join(defs) | ||
| def DEF(endpoint): | ||
| misc = endpoint['misc'] | ||
| req = endpoint['request'] | ||
| response = endpoint.get('response') | ||
| responses = ''.join([f'"{k}": "{v}",' for k, v in response.items()]) if len(response.items()) > 0 else '' | ||
| csrf = '@csrf_exempt\n' if req.get('host') == 'localhost' else '' | ||
| header_code = '\theaders = request.headers' if len(endpoint.get('headers').get('body').items()) > 0 else '' | ||
| params_code = '\n\tparams = kwargs.items()' if len(endpoint.get('params').items()) > 0 and header_code != '' else '\tparams = kwargs.items()' if len(endpoint.get('params').items()) > 0 and header_code == '' else '' | ||
| body_code = '\n\tbody = json.loads(request.body)' if len(endpoint.get('body').get('payload')) > 0 and (header_code != '' or params_code != '') else '\tbody = json.loads(request.body)' if len(endpoint.get('body').get('payload')) > 0 and params_code == '' else '' | ||
| _def = f""" | ||
| # Name: {endpoint.get('misc').get('name')} | ||
| # Headers: {', '.join([header[0]+'('+header[1]+')' for header in endpoint.get('headers').get('body').values() if header[0] and header[1]])} | ||
| # Params: {', '.join([param[0]+'('+param[1]+')' for param in endpoint.get('params').values() if param[0] and param[1]])} | ||
| # Body: {', '.join([payload[0]+'('+payload[1]+')' for payload in endpoint.get('body').get('payload').values() if payload[0] and payload[1]])} | ||
| {csrf}def {misc.get('token')}(request, *args, **kwargs): | ||
| {header_code}{params_code}{body_code} | ||
| \treturn JsonResponse({{{responses}}})\n\n""" | ||
| return _def | ||
| def BASE_MODELS(app): | ||
@@ -199,3 +214,3 @@ app_name = app.get('name') | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -205,3 +220,3 @@ elif type == 'JSONField': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -211,3 +226,3 @@ elif type == 'DateTimeField': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -217,3 +232,3 @@ elif type == 'CharField': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -223,3 +238,3 @@ elif type == 'EmailField': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -229,3 +244,3 @@ elif type == 'ImageField': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -235,3 +250,3 @@ elif len(type.split('.')) > 1 and type.split('.')[1] == 'id': | ||
| _class += f', default="{field[3]}"' if field[3] else '' | ||
| _class += f', verbose="{field[4]}"' if field[4] else '' | ||
| _class += f', verbose_name="{field[4]}"' if field[4] else '' | ||
| _class += ')\n' | ||
@@ -242,3 +257,3 @@ else: | ||
| _class += f'\tclass Meta:\n\t\tapp_label = "clix"' | ||
| _class += '\n' | ||
| _class += '\n\n\n' | ||
@@ -252,2 +267,3 @@ return f"""import uuid | ||
| # preparing to remove due to beta | ||
@@ -273,2 +289,3 @@ def APP_URLS(app): | ||
| def REQUIREMENTS(): | ||
@@ -275,0 +292,0 @@ return """""" |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
31962
21.54%498
14.48%