소스 검색

[ADD] initial commit

Gogs 7 년 전
커밋
faa1cdf741

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+*.pyc
+.sonarlint

+ 0 - 0
api/__init__.py


+ 8 - 0
api/apps.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class ApiConfig(AppConfig):
+    name = 'api'

+ 1 - 0
api/resources/__init__.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

+ 0 - 0
api/resources/jwt_resource.py


+ 20 - 0
api/resources/request_resource.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.resources import ModelResource
+from tastypie.authorization import Authorization
+from core.models.request import Request
+
+'''
+'''
+class RequestResource(ModelResource):
+    class Meta:
+        queryset = Request.objects.all()
+        authorization = Authorization()
+        always_return_data = True
+        
+    def dehydrate_status(self, bundle):
+        return [
+            bundle.obj.status,
+            bundle.obj.get_status_display()
+        ]
+

+ 12 - 0
api/resources/task_resource.py

@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.resources import ModelResource
+from tastypie.authorization import Authorization
+from core.models.task import Task
+
+'''
+'''
+class TaskResource(ModelResource):
+    class Meta:
+        queryset = Task.objects.all()
+        authorization = Authorization()

+ 11 - 0
api/urls.py

@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.conf.urls import url
+from tastypie.api import Api
+
+from api.resources.request_resource import RequestResource
+from api.resources.task_resource import TaskResource
+
+v1_api = Api(api_name='v1')
+v1_api.register(RequestResource())
+v1_api.register(TaskResource())

+ 14 - 0
api/utils/jwt_authentication.py

@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.authentication import Authentication
+
+class JWTAuthentication(Authentication):
+    '''
+    '''
+    def is_authenticated(self, request, **kwargs):
+        return True
+
+    '''
+    '''
+    def get_identifier(self, request):
+        return request.user.username

+ 9 - 0
api/utils/jwt_token.py

@@ -0,0 +1,9 @@
+'''
+'''
+def create_token(self, username, password):
+    pass
+
+'''
+'''
+def check_token(self, parameter_list):
+    pass

+ 17 - 0
api/views.py

@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.http import JsonResponse
+
+'''
+'''
+def get_token(request):
+    return JsonResponse({
+        'error': 'Under construction'
+    })
+
+'''
+'''
+def verify_token(request):
+    return JsonResponse({
+        'error': 'Under construction'
+    })

+ 0 - 0
core/__init__.py


+ 8 - 0
core/apps.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class CoreConfig(AppConfig):
+    name = 'core'

+ 44 - 0
core/migrations/0001_initial.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11 on 2018-02-23 17:10
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Request',
+            fields=[
+                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
+                ('createAt', models.DateTimeField(auto_now_add=True)),
+                ('updateAt', models.DateTimeField(auto_now=True)),
+                ('name', models.CharField(max_length=35)),
+                ('status', models.CharField(choices=[('O', 'Abierto'), ('R', 'Rechazado'), ('P', 'Procesando'), ('D', 'Hecho'), ('E', 'Error')], default='O', max_length=1)),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+        migrations.CreateModel(
+            name='Task',
+            fields=[
+                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
+                ('name', models.CharField(max_length=35)),
+                ('createAt', models.DateTimeField(auto_now_add=True)),
+                ('updateAt', models.DateTimeField(auto_now=True)),
+                ('playbook_name', models.CharField(max_length=35)),
+                ('last_execution', models.DateTimeField()),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+    ]

+ 35 - 0
core/migrations/0002_auto_20180223_1856.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11 on 2018-02-23 18:56
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='request',
+            old_name='createAt',
+            new_name='create_at',
+        ),
+        migrations.RenameField(
+            model_name='request',
+            old_name='updateAt',
+            new_name='update_at',
+        ),
+        migrations.RenameField(
+            model_name='task',
+            old_name='createAt',
+            new_name='create_at',
+        ),
+        migrations.RenameField(
+            model_name='task',
+            old_name='updateAt',
+            new_name='update_at',
+        ),
+    ]

+ 0 - 0
core/migrations/__init__.py


+ 2 - 0
core/models/__init__.py

@@ -0,0 +1,2 @@
+from .request import Request
+from .task import Task

+ 16 - 0
core/models/base.py

@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.db import models
+import uuid
+
+'''
+'''
+class Base(models.Model):
+    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
+    name = models.CharField(max_length=35)
+    create_at = models.DateTimeField(auto_now_add=True)
+    update_at = models.DateTimeField(auto_now=True)
+
+    class Meta:
+        abstract = True
+

+ 18 - 0
core/models/request.py

@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.db import models
+from .base import Base
+
+REQUEST_STATUSES = (
+    ('O', 'Abierto'),
+    ('R', 'Rechazado'),
+    ('P', 'Procesando'),
+    ('D', 'Hecho'),
+    ('E', 'Error'),
+)
+
+'''
+'''
+class Request(Base):
+    name = models.CharField(max_length=35)
+    status = models.CharField(max_length=1, choices=REQUEST_STATUSES, default='O')

+ 10 - 0
core/models/task.py

@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from .base import Base
+from django.db import models
+
+'''
+'''
+class Task(Base):
+    playbook_name = models.CharField(max_length=35)
+    last_execution = models.DateTimeField()

BIN
db.sqlite3


+ 22 - 0
manage.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "odoo_control.settings")
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError:
+        # The above import may fail for some other reason. Ensure that the
+        # issue is really that Django is missing to avoid masking other
+        # exceptions on Python 2.
+        try:
+            import django
+        except ImportError:
+            raise ImportError(
+                "Couldn't import Django. Are you sure it's installed and "
+                "available on your PYTHONPATH environment variable? Did you "
+                "forget to activate a virtual environment?"
+            )
+        raise
+    execute_from_command_line(sys.argv)

+ 0 - 0
odoo_control/__init__.py


+ 126 - 0
odoo_control/settings.py

@@ -0,0 +1,126 @@
+"""
+Django settings for odoo_control project.
+
+Generated by 'django-admin startproject' using Django 1.11.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.11/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/1.11/ref/settings/
+"""
+
+import os
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = '^*&s%i#9p7tq(#%f)--#ki2*qx8=iv5173eg35$qupv8%+fyv7'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'tastypie',
+    'core.apps.CoreConfig',
+    'api.apps.ApiConfig',
+    'web.apps.WebConfig',
+]
+
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'odoo_control.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = 'odoo_control.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+    }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/1.11/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/1.11/howto/static-files/
+
+STATIC_URL = '/static/'
+
+PLAYBOOKS_PATH = '/home/robert/workspace/playbooks'

+ 11 - 0
odoo_control/urls.py

@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.conf.urls import url, include
+from django.contrib import admin
+
+from api.urls import v1_api
+
+urlpatterns = [
+    url(r'^admin/', admin.site.urls),
+    url(r'^api/', include(v1_api.urls)),
+]

+ 16 - 0
odoo_control/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for odoo_control project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "odoo_control.settings")
+
+application = get_wsgi_application()

+ 29 - 0
requirements.txt

@@ -0,0 +1,29 @@
+astroid==1.6.1
+backports.functools-lru-cache==1.5
+backports.ssl-match-hostname==3.5.0.1
+certifi==2018.1.18
+chardet==3.0.4
+configparser==3.5.0
+Django==1.11
+django-tastypie==0.14.0
+docker==3.0.1
+docker-pycreds==0.2.1
+enum34==1.1.6
+futures==3.2.0
+idna==2.6
+ipaddress==1.0.19
+isort==4.3.4
+lazy-object-proxy==1.3.1
+mccabe==0.6.1
+pkg-resources==0.0.0
+PyJWT==1.5.3
+pylint==1.8.2
+python-dateutil==2.6.1
+python-mimeparse==1.6.0
+pytz==2018.3
+requests==2.18.4
+singledispatch==3.4.0.3
+six==1.11.0
+urllib3==1.22
+websocket-client==0.46.0
+wrapt==1.10.11

+ 0 - 0
web/__init__.py


+ 6 - 0
web/admin.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.contrib import admin
+
+# Register your models here.

+ 8 - 0
web/apps.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class WebConfig(AppConfig):
+    name = 'web'

+ 0 - 0
web/migrations/__init__.py


+ 6 - 0
web/models.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models
+
+# Create your models here.

+ 6 - 0
web/tests.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.test import TestCase
+
+# Create your tests here.

+ 6 - 0
web/views.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.shortcuts import render
+
+# Create your views here.