Beispiel #1
0
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
Beispiel #2
0
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, })
Beispiel #3
0
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'])