mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
Get tastypie relationships operational, consolidate resources into one file for easier sharing
This commit is contained in:
parent
b7133ca35a
commit
0758a28c08
@ -2,10 +2,6 @@
|
||||
|
||||
from defaults import *
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@domain.com'),
|
||||
)
|
||||
|
||||
@ -1 +1,42 @@
|
||||
from organizations import *
|
||||
from tastypie.resources import ModelResource, ALL
|
||||
from tastypie.authentication import BasicAuthentication
|
||||
from tastypie import fields, utils
|
||||
from lib.api.auth import AcomAuthorization
|
||||
#from django.conf.urls import url
|
||||
import lib.main.models as models
|
||||
|
||||
class Organizations(ModelResource):
|
||||
|
||||
class Meta:
|
||||
# related fields...
|
||||
queryset = models.Organization.objects.all()
|
||||
resource_name = 'organizations'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
#filtering = {
|
||||
# 'projects': ALL
|
||||
#}
|
||||
|
||||
users = fields.ToManyField('lib.api.resources.Users', 'users', related_name='organizations', blank=True, help_text='list of all organization users')
|
||||
admins = fields.ToManyField('lib.api.resources.Users', 'admins', related_name='admin_of_organizations', blank=True, help_text='list of administrator users')
|
||||
projects = fields.ToManyField('lib.api.resources.Projects', 'projects', related_name='organizations', blank=True, help_text='list of projects')
|
||||
|
||||
class Users(ModelResource):
|
||||
|
||||
class Meta:
|
||||
queryset = models.User.objects.all()
|
||||
resource_name = 'users'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
class Projects(ModelResource):
|
||||
|
||||
|
||||
class Meta:
|
||||
queryset = models.Project.objects.all()
|
||||
resource_name = 'projects'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
organizations = fields.ToManyField('lib.api.resources.Organizations', 'organizations', help_text='which organizations is this project in?')
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
# myapp/api.py
|
||||
|
||||
from tastypie.resources import ModelResource
|
||||
from tastypie.authentication import BasicAuthentication
|
||||
from tastypie import fields #, utils
|
||||
|
||||
from lib.api.auth import AcomAuthorization
|
||||
from lib.api.resources.projects import Projects
|
||||
from lib.api.resources.users import Users
|
||||
|
||||
import lib.main.models as models
|
||||
|
||||
class Organizations(ModelResource):
|
||||
|
||||
users = fields.ToManyField(Users, 'users')
|
||||
admins = fields.ToManyField(Users, 'admins')
|
||||
projects = fields.ToManyField(Projects, 'projects')
|
||||
|
||||
class Meta:
|
||||
queryset = models.Organization.objects.all()
|
||||
resource_name = 'organizations'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
# myapp/api.py
|
||||
|
||||
from tastypie.resources import ModelResource
|
||||
from tastypie.authentication import BasicAuthentication
|
||||
from lib.api.auth import AcomAuthorization
|
||||
import lib.main.models as models
|
||||
|
||||
class Projects(ModelResource):
|
||||
|
||||
class Meta:
|
||||
queryset = models.Project.objects.all()
|
||||
resource_name = 'projects'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
# myapp/api.py
|
||||
|
||||
from tastypie.resources import ModelResource
|
||||
from tastypie.authentication import BasicAuthentication
|
||||
from lib.api.auth import AcomAuthorization
|
||||
import lib.main.models as models
|
||||
|
||||
class Users(ModelResource):
|
||||
|
||||
class Meta:
|
||||
queryset = models.User.objects.all()
|
||||
resource_name = 'users'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
from django.conf import settings
|
||||
from django.conf.urls import *
|
||||
from tastypie.api import Api
|
||||
from lib.api.resources import Organizations
|
||||
from lib.api.resources import Projects
|
||||
from lib.api.resources import Users
|
||||
from lib.api.resources import *
|
||||
|
||||
v1_api = Api(api_name='v1')
|
||||
v1_api.register(Organizations())
|
||||
v1_api.register(Projects())
|
||||
v1_api.register(Users())
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'', include(v1_api.urls)),
|
||||
)
|
||||
|
||||
@ -49,7 +49,13 @@ class Collection(object):
|
||||
def __init__(self):
|
||||
|
||||
self.response = get(self.base_url())
|
||||
self.data = json.loads(self.response.text)
|
||||
print "---"
|
||||
print self.response.text
|
||||
print "---"
|
||||
try:
|
||||
self.data = json.loads(self.response.text)
|
||||
except Exception, e:
|
||||
raise e
|
||||
self.meta = self.data['meta']
|
||||
self.objects = self.data['objects']
|
||||
self.meta = self.data['meta']
|
||||
@ -158,8 +164,9 @@ try:
|
||||
last_project = list(Projects())[-1]
|
||||
|
||||
last_project.update(dict(description="new project!!!!", name="new project!!!!", organization=last_org.resource_uri))
|
||||
print ">> it was added here: %s to %s>>" % (last_project.resource_uri, last_org.resource_uri)
|
||||
Organizations().print_display()
|
||||
|
||||
|
||||
print "*** showing the orgs"
|
||||
Organizations().print_display()
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ for setting in dir(global_settings):
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user