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 userLabbookUpdateForm(request, subject_url=None): if (request.method == 'POST'): image_form = ImageFormLabbook() timelike_form = TimelikeFormLabbook() data_form = DataFormLabbook() text_form = ParagraphFormLabbook() update_form = UpdateFormLabbook(request.POST) if update_form.is_valid(): changedNode = StructureNode.objects.get(pk=int(request.POST['parentID'])) changedNode.title = request.POST['updateFormTitle'] changedNode.tag_set.clear() tagList = hashTagParser(request.POST['updateFormTag']) restrictedTagListSave(request, changedNode, tagList) return HttpResponseRedirect('/user/labbook/') else: if (subject_url): labbook_list = StructureNode.objects.filter(isLabnote = True, author=request.user).exclude(content_type = None).order_by('-pubDate').filter(tag__name__iexact=subject_url) else: labbook_list = StructureNode.objects.filter(isLabnote = True, author=request.user).exclude(content_type = None).order_by('-pubDate') return render(request, '_user/labbook.html', {'labbook_list': labbook_list, 'textForm': text_form, 'imageForm': image_form, 'timelikeForm':timelike_form,'dataForm': data_form, 'subject_url':subject_url, 'updateForm':update_form})
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 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 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 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'])