Browse Source

[FIX] base implementation

Gogs 7 years ago
parent
commit
99155aa527

+ 18 - 2
api/resources/user_resource.py

@@ -1,13 +1,29 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
-from tastypie.resources import ModelResource
+from tastypie import fields
+from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
 from tastypie.authorization import Authorization
 from django.contrib.auth.models import User
+from api.resources.group_resource import GroupResource
 
 '''
 '''
 class UserResource(ModelResource):
+    groups = fields.ToManyField(GroupResource, 'groups')
+
     class Meta:
         queryset = User.objects.all()
         authorization = Authorization()
-        always_return_data = True
+        always_return_data = True
+        # filtering = {
+        #     'slug': ALL,
+        #     'groups': ALL_WITH_RELATIONS,
+        #     'created': ['exact', 'range', 'gt', 'gte', 'lt', 'lte'],
+        # }
+
+    '''
+    '''
+    def obj_create(self, bundle, **kwargs):
+        print(bundle)
+        print(kwargs)
+        return super(UserResource, self).obj_create(bundle)

+ 3 - 3
api/utils/jwt_token.py

@@ -1,9 +1,11 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
+
 from django.conf import settings
 from django.contrib.auth import authenticate
 from django.contrib.auth.models import User
 from django.utils.crypto import constant_time_compare
+
 import jwt
 
 '''
@@ -66,12 +68,10 @@ def get_username(token):
 def check_token(token):
     payload = explode_token(token)
 
-    print(payload)
-
     user = User.objects.get(pk=payload['uid'])
 
     # Check if exists user
     if not user:
         return False
 
-    return constant_time_compare(user.password, payload['password'])
+    return constant_time_compare(user.password, payload['password'])

+ 1 - 0
core/__init__.py

@@ -0,0 +1 @@
+from .models import User

+ 8 - 0
core/admin.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.contrib import admin
+from django.contrib.auth.admin import UserAdmin
+from .models import User
+
+admin.site.register(User, UserAdmin)

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

@@ -1,44 +0,0 @@
-# -*- 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,
-            },
-        ),
-    ]

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

@@ -1,35 +0,0 @@
-# -*- 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',
-        ),
-    ]

+ 3 - 2
core/models/__init__.py

@@ -1,2 +1,3 @@
-from .request import Request
-from .task import Task
+from .user import User
+# from .request import Request
+# from .task import Task

+ 1 - 1
core/models/base.py

@@ -7,7 +7,7 @@ import uuid
 '''
 class Base(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
-    name = models.CharField(max_length=35)
+    name = models.CharField(max_length=35, blank=False)
     create_at = models.DateTimeField(auto_now_add=True)
     update_at = models.DateTimeField(auto_now=True)
 

+ 6 - 7
core/models/request.py

@@ -4,15 +4,14 @@ from django.db import models
 from .base import Base
 
 REQUEST_STATUSES = (
-    ('O', 'Abierto'),
-    ('R', 'Rechazado'),
-    ('P', 'Procesando'),
-    ('D', 'Hecho'),
-    ('E', 'Error'),
+    (1, 'Abierto'),
+    (2, 'Rechazado'),
+    (3, 'Procesando'),
+    (4, 'Hecho'),
+    (5, 'Error'),
 )
 
 '''
 '''
 class Request(Base):
-    name = models.CharField(max_length=35)
-    status = models.CharField(max_length=1, choices=REQUEST_STATUSES, default='O')
+    status = models.PositiveSmallIntegerField(choices=REQUEST_STATUSES, default=1)

+ 7 - 0
core/models/user.py

@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.contrib.auth.models import AbstractUser
+
+class User(AbstractUser):
+    pass

BIN
db.sqlite3


+ 4 - 39
odoo_control/settings.py

@@ -1,34 +1,12 @@
-"""
-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
+ALLOWED_HOSTS = ['*']
 
 INSTALLED_APPS = [
     'django.contrib.admin',
@@ -37,6 +15,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'django_extensions',
     'tastypie',
     'core.apps.CoreConfig',
     'api.apps.ApiConfig',
@@ -73,10 +52,6 @@ TEMPLATES = [
 
 WSGI_APPLICATION = 'odoo_control.wsgi.application'
 
-
-# Database
-# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
-
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
@@ -84,10 +59,6 @@ DATABASES = {
     }
 }
 
-
-# Password validation
-# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
-
 AUTH_PASSWORD_VALIDATORS = [
     {
         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
@@ -103,11 +74,9 @@ AUTH_PASSWORD_VALIDATORS = [
     },
 ]
 
+AUTH_USER_MODEL = 'core.models.user.User'
 
-# Internationalization
-# https://docs.djangoproject.com/en/1.11/topics/i18n/
-
-LANGUAGE_CODE = 'en-us'
+LANGUAGE_CODE = 'es-PY'
 
 TIME_ZONE = 'UTC'
 
@@ -117,10 +86,6 @@ USE_L10N = True
 
 USE_TZ = True
 
-
-# Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/1.11/howto/static-files/
-
 STATIC_URL = '/static/'
 
 TASTYPIE_DEFAULT_FORMATS = ['json', 'xml']