Skip to content
Snippets Groups Projects
Commit ed12fff1 authored by root's avatar root
Browse files

Update serializers

parent f32ca846
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -26,23 +26,23 @@ class Construct(StructuredNode): ...@@ -26,23 +26,23 @@ class Construct(StructuredNode):
}, },
} }
@property # @property
def serialize_connections(self): # def serialize_connections(self):
return [ # return [
{ # {
'nodes_type': 'OCF', # 'nodes_type': 'OCF',
'nodes_related': self.serialize_relationships(self.ocf.all()), # 'nodes_related': self.serialize_relationships(self.ocf.all()),
}, # },
{ # {
'nodes_type': 'StorageHost', # 'nodes_type': 'StorageHost',
'nodes_related': self.serialize_relationships(self.storagehost.all()), # 'nodes_related': self.serialize_relationships(self.storagehost.all()),
}, # },
{ # {
'nodes_type': 'ComputingHost', # 'nodes_type': 'ComputingHost',
'nodes_related': self.serialize_relationships(self.computinghost.all()), # 'nodes_related': self.serialize_relationships(self.computinghost.all()),
}, # },
{ # {
'nodes_type': 'User', # 'nodes_type': 'User',
'nodes_related': self.serialize_relationships(self.user.all()), # 'nodes_related': self.serialize_relationships(self.user.all()),
}, # },
] # ]
...@@ -3,4 +3,18 @@ from uuid import uuid4 ...@@ -3,4 +3,18 @@ from uuid import uuid4
class PDBFile(StructuredNode): class PDBFile(StructuredNode):
uuid=StringProperty(unique_index=True, default=uuid4) uuid=StringProperty(unique_index=True, default=uuid4)
coordinates_filetype=StringProperty() coordinates_filetype=StringProperty()
\ No newline at end of file
@property
def serialize(self):
"""
Serializer for node properties
"""
return {
'node_properties': {
'uuid': self.uuid,
'coordinates_filetype': self.coordinates_filetype,
},
}
\ No newline at end of file
No preview for this file type
No preview for this file type
# """
# api application controllers to perform CRUD operations on the Construct model
# """
# # Import python and django libraries
# import json
# # import logging
# from django.http import JsonResponse
# from django.views.decorators.csrf import csrf_exempt
# # Import models
# from api.models.construct_model import Construct
# # logger = logging.getLogger('dataproc')
# # logger.info("IN SHOW SAVE")
# # Define CRUD functions
# @csrf_exempt
# def indexConstruct(request):
# """
# Get all constructs
# """
# if request.method=='GET':
# try:
# constructs=Construct.nodes.all()
# response=[]
# for construct in constructs :
# obj= {
# "uuid": construct.uuid,
# "name": construct.name,
# }
# response.append(obj)
# # response=json.dumps(constructs.__porperties__)
# return JsonResponse(response, safe=False)
# # return response
# except:
# return JsonResponse({"error": "Error occurred"}, safe=False)
# @csrf_exempt
# def showConstruct(request):
# """
# Get one construct by name
# """
# if request.method=='GET':
# name=request.GET.get('name', ' ')
# try:
# construct=Construct.nodes.get(name=name)
# return JsonResponse(construct.serialize, safe=False)
# except :
# return JsonResponse({"error":"Error occurred"}, safe=False)
# @csrf_exempt
# def storeConstruct(request):
# """
# Create one construct
# """
# if request.method=='POST':
# json_data=json.loads(request.body)
# name=json_data['name']
# try:
# construct=Construct(name=name)
# construct.save()
# return JsonResponse({"uuid": construct.uuid})
# except :
# return JsonResponse({"error":"Error occurred"}, safe=False)
# @csrf_exempt
# def updateConstruct(request):
# """
# Update one construct
# """
# if request.method=='PUT':
# json_data=json.loads(request.body)
# name=json_data['name']
# uuid=json_data['uuid']
# try:
# construct=Construct.nodes.get(uuid=uuid)
# construct.name=name
# construct.save()
# return JsonResponse({"uuid": construct.uuid, "name": name}, safe=False)
# except:
# return JsonResponse({"error":"Error occurred"}, safe=False)
# @csrf_exempt
# def destroyConstruct(request):
# """
# Delete one construct by uuid
# """
# if request.method=='DELETE':
# json_data=json.loads(request.body)
# uuid=json_data['uuid']
# try:
# construct=Construct.nodes.get(uuid=uuid)
# construct.delete()
# return JsonResponse({"success": "Construct deleted"}, safe=False)
# except:
# return JsonResponse({"error":"Error occurred"}, safe=False)
""" """
api application controllers to perform CRUD operations on the Construct model api application controllers to perform CRUD operations on the User model
""" """
# Import python and django libraries # Import python and django libraries
...@@ -43,7 +152,9 @@ def showConstruct(request): ...@@ -43,7 +152,9 @@ def showConstruct(request):
name=request.GET.get('name', ' ') name=request.GET.get('name', ' ')
try: try:
construct=Construct.nodes.get(name=name) construct=Construct.nodes.get(name=name)
return JsonResponse({"uuid": construct.uuid, "name": construct.name}, safe=False) # return JsonResponse({"uuid": user.uuid, "name": user.name}, safe=False)
# return JsonResponse({user}, safe=False)
return JsonResponse(construct.serialize, safe=False)
except : except :
return JsonResponse({"error":"Error occurred"}, safe=False) return JsonResponse({"error":"Error occurred"}, safe=False)
...@@ -94,8 +205,8 @@ def destroyConstruct(request): ...@@ -94,8 +205,8 @@ def destroyConstruct(request):
json_data=json.loads(request.body) json_data=json.loads(request.body)
uuid=json_data['uuid'] uuid=json_data['uuid']
try: try:
construct=Construct.nodes.get(uuid=uuid) user=User.nodes.get(uuid=uuid)
construct.delete() user.delete()
return JsonResponse({"success": "Construct deleted"}, safe=False) return JsonResponse({"success": "Construct deleted"}, safe=False)
except: except:
return JsonResponse({"error":"Error occurred"}, safe=False) return JsonResponse({"error":"Error occurred"}, safe=False)
...@@ -23,11 +23,8 @@ def indexUser(request): ...@@ -23,11 +23,8 @@ def indexUser(request):
users=User.nodes.all() users=User.nodes.all()
response=[] response=[]
for user in users : for user in users :
obj= { node=user.serialize
"uuid": user.uuid, response.append(node)
"name": user.name,
}
response.append(obj)
return JsonResponse(response, safe=False) return JsonResponse(response, safe=False)
except: except:
return JsonResponse({"error": "Error occurred"}, safe=False) return JsonResponse({"error": "Error occurred"}, safe=False)
...@@ -43,8 +40,7 @@ def showUser(request): ...@@ -43,8 +40,7 @@ def showUser(request):
name=request.GET.get('name', ' ') name=request.GET.get('name', ' ')
try: try:
user=User.nodes.get(name=name) user=User.nodes.get(name=name)
return JsonResponse({"uuid": user.uuid, "name": user.name}, safe=False) return JsonResponse(user.serialize, safe=False)
# return JsonResponse({user}, safe=False)
except : except :
return JsonResponse({"error":"Error occurred"}, safe=False) return JsonResponse({"error":"Error occurred"}, safe=False)
...@@ -61,7 +57,7 @@ def storeUser(request): ...@@ -61,7 +57,7 @@ def storeUser(request):
try: try:
user=User(name=name) user=User(name=name)
user.save() user.save()
return JsonResponse({"uuid": user.uuid}) return JsonResponse(user.serialize)
except : except :
return JsonResponse({"error":"Error occurred"}, safe=False) return JsonResponse({"error":"Error occurred"}, safe=False)
...@@ -80,7 +76,7 @@ def updateUser(request): ...@@ -80,7 +76,7 @@ def updateUser(request):
user=User.nodes.get(uuid=uuid) user=User.nodes.get(uuid=uuid)
user.name=name user.name=name
user.save() user.save()
return JsonResponse({"uuid": user.uuid, "name": name}, safe=False) return JsonResponse(user.serialize, safe=False)
except: except:
return JsonResponse({"error":"Error occurred"}, safe=False) return JsonResponse({"error":"Error occurred"}, safe=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment