fix errors in AbstractCRUD & integrate with app
parent
6a32881c6a
commit
f7c5d3ae8a
|
|
@ -5,6 +5,7 @@ from .utilities import *
|
||||||
|
|
||||||
class ValidationUtils():
|
class ValidationUtils():
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def fromDict(self, dict):
|
def fromDict(self, dict):
|
||||||
self.__dict__.update(dict)
|
self.__dict__.update(dict)
|
||||||
|
|
||||||
|
|
@ -78,6 +79,7 @@ class AbstractGet(AbstractUtilsCRUD):
|
||||||
"""
|
"""
|
||||||
return HttpResponse(self.__getAllByParentID(parentID))
|
return HttpResponse(self.__getAllByParentID(parentID))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def __getAllByParentID(self, parentID):
|
def __getAllByParentID(self, parentID):
|
||||||
list = [
|
list = [
|
||||||
x.toDict()
|
x.toDict()
|
||||||
|
|
@ -109,12 +111,14 @@ class AbstractCreate(AbstractUtilsCRUD):
|
||||||
else:
|
else:
|
||||||
return HttpResponse("No Permission")
|
return HttpResponse("No Permission")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def _validateUnique(self, userDict):
|
def _validateUnique(self, userDict):
|
||||||
"""
|
"""
|
||||||
use validate in override this method
|
use validate in override this method
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def _saveObject(self, objectDict):
|
def _saveObject(self, objectDict):
|
||||||
"""
|
"""
|
||||||
save object without parent
|
save object without parent
|
||||||
|
|
@ -132,13 +136,14 @@ class AbstractCreate(AbstractUtilsCRUD):
|
||||||
object = jsonLoad(request)
|
object = jsonLoad(request)
|
||||||
if checkSession(request, privilige):
|
if checkSession(request, privilige):
|
||||||
if self._validateUnique(object):
|
if self._validateUnique(object):
|
||||||
return self._saveObject(parentID, object)
|
return self._saveObjectWithParent(parentID, object)
|
||||||
else:
|
else:
|
||||||
return HttpResponse("Object Is Already Exist")
|
return HttpResponse("Object Is Already Exist")
|
||||||
else:
|
else:
|
||||||
return HttpResponse("No Permission")
|
return HttpResponse("No Permission")
|
||||||
|
|
||||||
def _saveObject(self, parentID, objectDict):
|
@classmethod
|
||||||
|
def _saveObjectWithParent(self, parentID, objectDict):
|
||||||
"""
|
"""
|
||||||
save object with parent & subject + comment & set trigger time
|
save object with parent & subject + comment & set trigger time
|
||||||
"""
|
"""
|
||||||
|
|
@ -152,15 +157,18 @@ class AbstractCreate(AbstractUtilsCRUD):
|
||||||
newObject.save()
|
newObject.save()
|
||||||
return HttpResponse(f"Add new Object: {newObject.toDict()}")
|
return HttpResponse(f"Add new Object: {newObject.toDict()}")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def _createFirstComment(self, newSubject, objectDict):
|
def _createFirstComment(self, newSubject, objectDict):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def _setActualTimeTrigger(self):
|
def _setActualTimeTrigger(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class AbstractUpdate(AbstractUtilsCRUD):
|
class AbstractUpdate(AbstractUtilsCRUD):
|
||||||
"""
|
"""
|
||||||
This class have a abstract `update`
|
This class have a abstract `update`
|
||||||
|
|
@ -174,6 +182,7 @@ class AbstractUpdate(AbstractUtilsCRUD):
|
||||||
else:
|
else:
|
||||||
return HttpResponse("No Permission")
|
return HttpResponse("No Permission")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def _updateObject(self, objectDict, objectID):
|
def _updateObject(self, objectDict, objectID):
|
||||||
objectOld = self._objectFactory().objects.get(pk = objectID)
|
objectOld = self._objectFactory().objects.get(pk = objectID)
|
||||||
objectOld.fromDict(objectDict)
|
objectOld.fromDict(objectDict)
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -18,11 +18,11 @@ def checkTriggerNotification():
|
||||||
|
|
||||||
# Exchange POST Methods
|
# Exchange POST Methods
|
||||||
|
|
||||||
def addTrigger(request, userID):
|
def addTrigger(request):
|
||||||
return Triggers.addObject(request, userID, 1)
|
return Triggers.addObject(request, 1)
|
||||||
|
|
||||||
def addTransaction(request, userID):
|
def addTransaction(request):
|
||||||
return Transactions.addObject(request, userID, 1)
|
return Transactions.addObject(request, 1)
|
||||||
|
|
||||||
def Prognosis(request, time, price):
|
def Prognosis(request, time, price):
|
||||||
return ExchangeVO.createActualPrognosis(request, time, price, 1)
|
return ExchangeVO.createActualPrognosis(request, time, price, 1)
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,7 @@ class Threads(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Threads
|
return Threads
|
||||||
|
|
||||||
# Create Thread (validation)
|
# Create Thread (validation)
|
||||||
|
|
@ -257,7 +257,7 @@ class Subjects(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Subjects
|
return Subjects
|
||||||
|
|
||||||
# Create Subject ( create new subject + comment ones )
|
# Create Subject ( create new subject + comment ones )
|
||||||
|
|
@ -297,7 +297,7 @@ class Comments(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Comments
|
return Comments
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -325,7 +325,7 @@ class Ratings(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Ratings
|
return Ratings
|
||||||
|
|
||||||
# Create Ratings (validate)
|
# Create Ratings (validate)
|
||||||
|
|
@ -368,7 +368,7 @@ class Transactions(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Transactions
|
return Transactions
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -396,7 +396,7 @@ class Triggers(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Triggers
|
return Triggers
|
||||||
|
|
||||||
# Create Trigger (set actual time)
|
# Create Trigger (set actual time)
|
||||||
|
|
@ -424,5 +424,5 @@ class Notifications(AbstractCRUD):
|
||||||
|
|
||||||
# Object Factory for abstract
|
# Object Factory for abstract
|
||||||
|
|
||||||
def objectFactory():
|
def _objectFactory():
|
||||||
return Notifications
|
return Notifications
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ def transactions(request, userID):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return getUserTransactions(request, userID)
|
return getUserTransactions(request, userID)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
return addTransaction(request, userID)
|
return addTransaction(request)
|
||||||
else:
|
else:
|
||||||
return HttpResponse('Bad Request Method')
|
return HttpResponse('Bad Request Method')
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ def triggers(request, userID):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return getUserTriggers(request, userID)
|
return getUserTriggers(request, userID)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
return addTrigger(request, userID)
|
return addTrigger(request)
|
||||||
else:
|
else:
|
||||||
return HttpResponse('Bad Request Method')
|
return HttpResponse('Bad Request Method')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue