def DataTest(s, h, publish, words): numberOfExperiments = random.randint(s, h) print(numberOfExperiments) for x in range(1, numberOfExperiments+1): print(x) tempExp = StructureNode(title=words + "experiment" + str(x), slug=words + "experiment" + str(x), isPublished=publish, position=x) tempExp.save() numberOfArticles = random.randint(1, 5) for y in range(1, numberOfArticles+1): tempArt = StructureNode(title= words + "experiment" + str(x)+"Article" + str(y), slug="article" + str(y), parent_id=tempExp.id, isPublished=publish, position=y) tempArt.save() tempArt.rating.rating = random.randint(1,50) tempArt.rating.save() numberOfSubparts = random.randint(1,10) for z in range(1, numberOfSubparts+1): tempContent = StructureNode(title=words + "experiment" + str(x)+"Article" + str(y)+"Content" + str(z), slug="content" + str(z), parent_id=tempArt.id, content_type=GetObjectType(random.randint(1,3)), object_id = 1, isPublished=publish, position=z) tempContent.save()
def DataTestWithComments(h, words): numberOfExperiments = random.randint(1, h) print(numberOfExperiments) for x in range(1, numberOfExperiments+1): tempExp = StructureNode(title=words + "experiment" + str(x), slug=words + "experiment" + str(x), isPublished=True, position=x) tempExp.save() numberOfArticles = random.randint(1, 5) for y in range(1, numberOfArticles+1): tempArt = StructureNode(title= words + "experiment" + str(x)+"Article" + str(y), parent_id=tempExp.id, isPublished=True, position=y) tempArt.save() tempArt.rating.rating = random.randint(1,50) tempArt.rating.save() numberOfSubparts = random.randint(1,10) for z in range(1, numberOfSubparts+1): tempContent = StructureNode(title=words + "experiment" + str(x)+"Article" + str(y)+"Content" + str(z), parent_id=tempArt.id, content_type=GetObjectType(random.randint(1,3)), object_id = 1, isPublished=True, position=z) tempContent.save() numberofComments = random.randint(1,5) for w in range(1, numberofComments+1): tempComment = StructureNode(title=words + "experiment" + str(x) + "Article" + str(y) + "Content" + str(z) + "Comment" + str(w), parent_id=tempContent.id, isPublished=False, position=w) tempComment.save() for xx in range(1, numberofComments+1): print("xx=" + str(xx)) tempCommentContent = StructureNode(title=words + "experiment" + str(x) + "Article" + str(y) + "Content" + str(z) + "Comment" + str(w) +"Content" + str(xx), parent_id=tempComment.id, content_type=GetObjectType(3), object_id = 1, isPublished=False, position=xx) tempCommentContent.save()
def dataFormLabbookSave(request): if (DataFormLabbook(request.POST).is_valid()): tempDataset = Dataset() tempDataset.data = datasetFormatter(request.POST) tempDataset.save() tempStructureNode = StructureNode() tempStructureNode.title = request.POST['dataFormTitle'] tempStructureNode.author = request.user tempStructureNode.content_type = ContentType.objects.get_for_model(Dataset) tempStructureNode.object_id = tempDataset.id tempStructureNode.isPublished = False tempStructureNode.position = getPositionForRoots() tempStructureNode.isComment = False tempStructureNode.isLabnote = True tempStructureNode.save() tagList = hashTagParser(request.POST['dataFormTag']) restrictedTagListSave(request, tempStructureNode, tagList) print("something is valid") return True else: print("nothing is ever valid data") return False
def timelikeFormLabbookSave(request): if (TimelikeFormLabbook(request.POST, request.FILES).is_valid()): tempTimelike = Timelike() if (request.POST.get('timelikeFormLinkSource',False)): tempTimelike.linkSource = request.POST['timelikeFormLinkSource'] if (request.FILES.get('timelikeFormLocalSource', False)): tempTimelike.localSource = request.FILES['timelikeFormLocalSource'] tempTimelike.save() tempStructureNode = StructureNode() tempStructureNode.title = request.POST['timelikeFormTitle'] tempStructureNode.author = request.user tempStructureNode.content_type = ContentType.objects.get_for_model(Timelike) tempStructureNode.object_id = tempTimelike.id tempStructureNode.isPublished = False tempStructureNode.position = getPositionForRoots() tempStructureNode.isComment = False tempStructureNode.isLabnote = True tempStructureNode.save() tagList = hashTagParser(request.POST['timelikeFormTag']) restrictedTagListSave(request, tempStructureNode, tagList) print("something is valid") return True else: print("nothing is ever valid") return False
def userPublish(request): labbook_imageNode_list = StructureNode.objects.filter(isLabnote = True, author=request.user, content_type__model='image') #when filtering model must be lower case. labbook_timelikeNode_list = StructureNode.objects.filter(isLabnote = True, author=request.user, content_type__model='timelike') labbook_dataNode_list = StructureNode.objects.filter(isLabnote = True, author=request.user, content_type__model='dataset') publishForm = PublishForm() if (request.method == 'POST'): print(request.POST) publishForm = PublishForm(request.POST) if (publishForm.is_valid()): experimentNode = StructureNode() experimentNode.title = request.POST['publishFormTitle'] experimentNode.author = request.user experimentNode.isPublished = True experimentNode.position = getPositionForRoots() experimentNode.save() tagList = hashTagParser(request.POST['publishFormTag']) restrictedTagListSave(request, experimentNode, tagList) for sectionNodeIndex in range(0, int(request.POST['numberOfSections'])): sectionNode = StructureNode() sectionNode.title = request.POST['section_title_'+str(sectionNodeIndex)] sectionNode.parent = experimentNode sectionNode.author = request.user sectionNode.isPublished = True sectionNode.position = sectionNodeIndex + 1 sectionNode.save() restrictedTagListSave(request, sectionNode, tagList) for contentNodeIndex in range(0, int(request.POST['numberOfContentSections_'+str(sectionNodeIndex)])): contentNode = StructureNode() contentNode.title = request.POST['section_title_'+str(sectionNodeIndex)] +"_content_"+str(contentNodeIndex) contentNode.parent = sectionNode contentNode.author = request.user contentNode.isPublished = True contentNode.position = contentNodeIndex +1 if (request.POST['contentType_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] == "textContent"): tempParagraph = Paragraph() tempParagraph.text = request.POST['text_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] tempParagraph.save() contentNode.content_type = ContentType.objects.get_for_model(Paragraph) contentNode.object_id = tempParagraph.id contentNode.save() elif (request.POST['contentType_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] == "imageContent"): contentNode.content_type = ContentType.objects.get_for_model(Image) if (request.POST.get('imageInputLinkSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): tempImage = Image() tempImage.linkSource = request.POST['imageInputLinkSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] tempImage.save() contentNode.object_id = tempImage.id print("first") elif (request.FILES.get('imageInputLocalSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): tempImage = Image() tempImage.localSource = request.FILES['imageInputLocalSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] tempImage.save() contentNode.object_id = tempImage.id print("second") elif (request.POST.get('imageInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['imageInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)]) print("third") contentNode.save() elif (request.POST['contentType_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] == "timelikeContent"): contentNode.content_type = ContentType.objects.get_for_model(Timelike) if (request.POST.get('timelikeInputLinkSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): tempTimelike = Timelike() tempTimelike.linkSource = request.POST['timelikeInputLinkSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] tempTimelike.save() contentNode.object_id = tempTimelike.id print("first") elif (request.FILES.get('timelikeInputLocalSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): tempTimelike = Timelike() tempTimelike.localSource = request.FILES['timelikeInputLocalSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] tempTimelike.save() contentNode.object_id = tempTimelike.id print("second") elif (request.POST.get('timelikeInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['timelikeInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)]) print("third") contentNode.save() elif (request.POST['contentType_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)] == "dataContent"): contentNode.content_type = ContentType.objects.get_for_model(Dataset) if (request.POST.get('dataInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['dataInputLabbookSource_section_content_'+str(sectionNodeIndex)+"_"+str(contentNodeIndex)]) contentNode.save() restrictedTagListSave(request, contentNode, tagList) return render(request, '_user/publish.html', {'publishForm':publishForm, 'labbook_imageNode_list': labbook_imageNode_list, 'labbook_timelikeNode_list': labbook_timelikeNode_list, 'labbook_dataNode_list': labbook_dataNode_list, })
def textFormLabbookSave(request): if (ParagraphFormLabbook(request.POST).is_valid()): tempParagraph = Paragraph() tempParagraph.text = request.POST['textFormText'] tempParagraph.save() tempStructureNode = StructureNode() tempStructureNode.title = request.POST['textFormTitle'] tempStructureNode.author = request.user tempStructureNode.content_type = ContentType.objects.get_for_model(Paragraph) tempStructureNode.object_id = tempParagraph.id tempStructureNode.isPublished = False tempStructureNode.position = getPositionForRoots() tempStructureNode.isComment = False tempStructureNode.isLabnote = True tempStructureNode.save() tagList = hashTagParser(request.POST['textFormTag']) restrictedTagListSave(request, tempStructureNode, tagList) print("something is valid") return True else: print("nothing is ever valid") return False
def submitComment(request): if (request.method == 'POST'): print(request.POST) publishForm = PublishForm(request.POST) if (publishForm.is_valid()): tagList = hashTagParser(request.POST['publishFormTag']) commentNode = StructureNode() commentNode.title= request.POST['publishFormTitle'] commentNode.parent_id = int(request.POST['sectionParent']) commentNode.author = request.user commentNode.isComment = True commentNode.position = getPositionForComments(request) commentNode.save() restrictedTagListSave(request, commentNode, tagList) for contentNodeIndex in range(0, int(request.POST['numberOfContentSections_'+str(0)])): contentNode = StructureNode() contentNode.title = request.POST['publishFormTitle'] +"_content_"+str(contentNodeIndex) contentNode.parent = commentNode contentNode.author = request.user contentNode.isComment = True contentNode.position = contentNodeIndex +1 if (request.POST['contentType_section_content_'+str(0)+"_"+str(contentNodeIndex)] == "textContent"): tempParagraph = Paragraph() tempParagraph.text = request.POST['text_section_content_'+str(0)+"_"+str(contentNodeIndex)] tempParagraph.save() contentNode.content_type = ContentType.objects.get_for_model(Paragraph) contentNode.object_id = tempParagraph.id contentNode.save() elif (request.POST['contentType_section_content_'+str(0)+"_"+str(contentNodeIndex)] == "imageContent"): contentNode.content_type = ContentType.objects.get_for_model(Image) if (request.POST.get('imageInputLinkSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): tempImage = Image() tempImage.linkSource = request.POST['imageInputLinkSource_section_content_'+str(0)+"_"+str(contentNodeIndex)] tempImage.save() contentNode.object_id = tempImage.id print("first") elif (request.FILES.get('imageInputLocalSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): tempImage = Image() tempImage.localSource = request.FILES['imageInputLocalSource_section_content_'+str(0)+"_"+str(contentNodeIndex)] tempImage.save() contentNode.object_id = tempImage.id print("second") elif (request.POST.get('imageInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['imageInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex)]) print("third") contentNode.save() elif (request.POST['contentType_section_content_'+str(0)+"_"+str(contentNodeIndex)] == "timelikeContent"): contentNode.content_type = ContentType.objects.get_for_model(Timelike) if (request.POST.get('timelikeInputLinkSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): tempTimelike = Timelike() tempTimelike.linkSource = request.POST['timelikeInputLinkSource_section_content_'+str(0)+"_"+str(contentNodeIndex)] tempTimelike.save() contentNode.object_id = tempTimelike.id print("first") elif (request.FILES.get('timelikeInputLocalSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): tempTimelike = Timelike() tempTimelike.localSource = request.FILES['timelikeInputLocalSource_section_content_'+str(0)+"_"+str(contentNodeIndex)] tempTimelike.save() contentNode.object_id = tempTimelike.id print("second") elif (request.POST.get('timelikeInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['timelikeInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex)]) print("third") contentNode.save() elif (request.POST['contentType_section_content_'+str(0)+"_"+str(contentNodeIndex)] == "dataContent"): contentNode.content_type = ContentType.objects.get_for_model(Dataset) if (request.POST.get('dataInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex))): contentNode.object_id = int(request.POST['dataInputLabbookSource_section_content_'+str(0)+"_"+str(contentNodeIndex)]) contentNode.save() restrictedTagListSave(request, contentNode, tagList) return HttpResponseRedirect(request.POST['prevPage'])