refactor create in abstract (Comment)

master/v0.1.0
TBS093A 2020-08-28 17:37:23 +02:00
parent 57045abea7
commit 572e9cdf31
1 changed files with 23 additions and 5 deletions

View File

@ -34,11 +34,6 @@ class ObjectAbstract(models.Model):
if model.modelIsTrigger(model): if model.modelIsTrigger(model):
newObject.setActualTime() newObject.setActualTime()
newObject.save() newObject.save()
if model.modelIsSubject(model) and model.newCommentInNewSubject(objectDict):
newComment = Comments(subject = newObject)
newComment.fromDict(objectDict['comment'])
newComment.save()
return HttpResponse(f"{model.__name__}/{Comments}: Add new Objects: {newObject.toDict()} and {newComment.toDict()}")
return HttpResponse(f"{model.__name__}: Add new Object: {newObject.toDict()}") return HttpResponse(f"{model.__name__}: Add new Object: {newObject.toDict()}")
@classmethod @classmethod
@ -324,6 +319,7 @@ class Subjects(ObjectAbstract):
def __saveObject(threadID, objectDict): def __saveObject(threadID, objectDict):
newObject = Subjects() newObject = Subjects()
newObject.fromDict(objectDict) newObject.fromDict(objectDict)
newObject.setParentID(threadID)
newComment = Comments(subject = newObject) newComment = Comments(subject = newObject)
newComment.fromDict(objectDict['comment']) newComment.fromDict(objectDict['comment'])
@ -369,6 +365,28 @@ class Comments(ObjectAbstract):
"subject_id": self.subject.id, "subject_id": self.subject.id,
"subject_name": self.subject.name} "subject_name": self.subject.name}
# Get One Comment
# Create Comment
@classmethod
def addObject(request, subjectID, privilige):
if checkSession(request, privilige):
object = jsonLoad(request)
return self.__saveObject(self, parentID, object)
else:
return HttpResponse("No Permission")
def __saveObject(subjectID, objectDict):
newObject = Comments()
newObject.fromDict(objectDict)
newObject.setParentID(subject)
newObject.save()
return HttpResponse(f"Add new Comment: {newObject.toDict()}")
# Update Comment
# Delete Comment
class Ratings(ObjectAbstract): class Ratings(ObjectAbstract):
value = models.IntegerField() value = models.IntegerField()