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