Beispiel #1
0
def test(request):
    """ Use for rapid testing of new pages."""

    story = get_object_or_404(Story, id=1)
    if story.webfacetstory.all():
        webfacet = get_object_or_404(WebFacet, story=story)
        webfacet_images = WebFacet.get_webfacet_images(webfacet)
    else:
        webfacet_images = []
    if story.printfacetstory.all():
        printfacet = get_object_or_404(PrintFacet, story=story)
        printfacet_images = PrintFacet.get_printfacet_images(printfacet)
    else:
        printfacet_images = []
    if story.audiofacetstory.all():
        audiofacet = get_object_or_404(AudioFacet, story=story)
        audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
    else:
        audiofacet_images = []
    if story.videofacetstory.all():
        videofacet = get_object_or_404(VideoFacet, story=story)
        videofacet_images = VideoFacet.get_videofacet_images(videofacet)
    else:
        videofacet_images =[]
    storydownloadform = StoryDownloadForm(story=story)

    return render(request, 'editorial/test.html', {
        'story': story,
        'webfacet_images': webfacet_images,
        'printfacet_images': printfacet_images,
        'audiofacet_images': audiofacet_images,
        'videofacet_images': videofacet_images,
        'storydownloadform': storydownloadform,
        })
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        self.story = kwargs.pop('story')
        super(StoryDownloadForm, self).__init__(*args, **kwargs)

        if self.story.webfacetstory.all():
            webfacet = self.story.webfacetstory.all()[0]
            self.fields['webfacet_images'].queryset = WebFacet.get_webfacet_images(webfacet)
        if self.story.printfacetstory.all():
            printfacet = self.story.printfacetstory.all()[0]
            self.fields['printfacet_images'].queryset = PrintFacet.get_printfacet_images(printfacet)
        if self.story.audiofacetstory.all():
            audiofacet = self.story.audiofacetstory.all()[0]
            self.fields['audiofacet_images'].queryset = AudioFacet.get_audiofacet_images(audiofacet)
        if self.story.videofacetstory.all():
            videofacet = self.story.videofacetstory.all()[0]
            self.fields['videofacet_images'].queryset = VideoFacet.get_videofacet_images(videofacet)
Beispiel #3
0
def story_detail(request, pk):
    """ The detail page for a story.

    Displays the story's planning notes, discussion, assets, share and collaboration status
    and sensivity status. From here the user can also see any facets, edit them and add new ones.
    """

    story = get_object_or_404(Story, pk=pk)
    storynoteform = StoryNoteForm()
    storynotes = StoryNote.objects.filter(story=story)
    storycommentform = StoryCommentForm()
    storydiscussion = get_object_or_404(Discussion, id=story.discussion.id)
    storycomments = Comment.objects.filter(discussion=storydiscussion).order_by('-date')
    notes = StoryNote.objects.filter(story=story)
    images = Organization.get_org_image_library(request.user.organization)

# ------------------------------ #
#           webfacet             #
# ------------------------------ #

    # create these here for efficiency
    webform=WebFacetForm()
    webcommentform=WebFacetCommentForm()
    webfacet_imageform=ImageAssetForm()

    try:
        webfacet = get_object_or_404(WebFacet, story=story)
        print "WEBFACET CREDIT", webfacet.credit.all()

        # IF WEBFACET EXISTS DO ALL OF THE FOLLOWING
        # rebind webform to include webfacet instance
        webform = WebFacetForm(instance=webfacet)
        # retrieve discussion and comments
        webfacetdiscussion = get_object_or_404(Discussion, id=webfacet.discussion.id)
        webcomments = Comment.objects.filter(discussion=webfacetdiscussion).order_by('-date')[:3]
        # retrieve history
        webhistory = webfacet.edit_history.all()[:5]
        # update an existing webfacet
        if request.method == "POST":
            print "WF Try If Post"
            if 'webform' in request.POST:
                print "WF Try If Post If webform"
                webform = WebFacetForm(data=request.POST, instance=webfacet)
                #import pdb; pdb.set_trace()
                if webform.is_valid():
                    print "WF Try If Post If Webform Valid"
                    webform.save()
                    print "webfacet updated"
                    return redirect('story_detail', pk=story.pk)
    except:
        print "WF Except"
    # except WebFacet.DoesNotExist:
        # display form and save a new webfacet
        webcomments = []
        webhistory = []
        if request.method == "POST":
            print "WF Except Post"
            if 'webform' in request.POST:
                print "WF Except Post If webform"
                webform = WebFacetForm(request.POST or None)
                if webform.is_valid():
                    # #import pdb; pdb.set_trace()
                    print "WF Except Post If webform Valid"
                    webfacet = webform.save(commit=False)
                    print "webfacet = webform.save(commit=False)"
                    webfacet.story = story
                    webfacet.owner = request.user
                    webfacet.organization = request.user.organization
                    webfacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    webfacet.discussion = discussion
                    webfacet.save()
                    webform.save_m2m()
                    print "webfacet created"
                    # create history of the webfacet
                    webhistory = webfacet.edit_history.all()[:5]
                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           printfacet           #
# ------------------------------ #

    # create these here for efficiency
    printform=PrintFacetForm()
    printcommentform=PrintFacetCommentForm()
    printfacet_imageform=ImageAssetForm()

    try:
        print "PF Try"
        printfacet = get_object_or_404(PrintFacet, story=story)
        # IF PRINTFACET EXISTS DO ALL OF THE FOLLOWING
        printform = PrintFacetForm(instance=printfacet)
        # retrieve discussion and comments
        printfacetdiscussion = get_object_or_404(Discussion, id=printfacet.discussion.id)
        printcomments = Comment.objects.filter(discussion=printfacetdiscussion).order_by('-date')[:3]
        # retrieve history
        printhistory = printfacet.edit_history.all()[:5]
        # update an existing printfacet
        if request.method == "POST":
            print "PF Try If Post"
            if 'printform' in request.POST:
                print "PF Try If Post If printform"
                #import pdb; pdb.set_trace()
                printform = PrintFacetForm(data=request.POST, instance=printfacet)
                if printform.is_valid():
                    print "PF Try If Post If printform Valid"
                    printform.save()
                    print "printfacet updated"
                    return redirect('story_detail', pk=story.pk)
    except:
        print "PF Except"
    # except PrintFacet.DoesNotExist:
        # display form and save a new printfacet
        printcomments = []
        printhistory = []
        if request.method == "POST":
            print "PF Except If Post"
            if 'printform' in request.POST:
                print "PF Except If Post If printform"
                # #import pdb; pdb.set_trace()
                printform = PrintFacetForm(request.POST or None)
                if printform.is_valid():
                    print "PF Except If Post If printform Valid"
                    printfacet = printform.save(commit=False)
                    print "printfacet = printform.save(commit=False)"
                    printfacet.story = story
                    printfacet.owner = request.user
                    printfacet.organization = request.user.organization
                    printfacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    printfacet.discussion = discussion
                    printfacet.save()
                    printform.save_m2m()
                    print "printfacet created"
                    # create history of the printfacet
                    printhistory = printfacet.edit_history.all()[:5]
                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           audiofacet           #
# ------------------------------ #

    # create these here for efficiency
    audioform=AudioFacetForm()
    audiocommentform=AudioFacetCommentForm()
    audiofacet_imageform=ImageAssetForm()

    try:
        print "AF Try"
        audiofacet = get_object_or_404(AudioFacet, story=story)
        print "AUDIOFACET CREDIT: ", audiofacet.credit.all()
        # IF WEBFACET EXISTS DO ALL OF THE FOLLOWING
        audioform = AudioFacetForm(instance=audiofacet)
        # retrieve discussion and comments
        audiofacetdiscussion = get_object_or_404(Discussion, id=audiofacet.discussion.id)
        audiocomments = Comment.objects.filter(discussion=audiofacetdiscussion).order_by('-date')[:3]
        # retrieve history
        audiohistory = audiofacet.edit_history.all()[:5]
        # update an existing audiofacet
        if request.method == "POST":
            print "AF Try If Post"
            if 'audioform' in request.POST:
                print "AF Try If Post If Audioform"
                # #import pdb; pdb.set_trace()
                audioform = AudioFacetForm(data=request.POST, instance=audiofacet)
                if audioform.is_valid():
                    print "AF Try If Post If Audioform Valid"
                    audioform.save()
                    print "audiofacet updated"
                    return redirect('story_detail', pk=story.pk)
    except:
        print "AF Except"
    # except AudioFacet.DoesNotExist:
        # display form and save a new audiofacet
        audiocomments = []
        audiohistory = []
        if request.method == "POST":
            print "AF Except If Post"
            if 'audioform' in request.POST:
                print "AF Except If Post If Audioform"
                # #import pdb; pdb.set_trace()
                audioform = AudioFacetForm(request.POST or None)
                if audioform.is_valid():
                    print "AF Except If Post If Audioform Valid"
                    audiofacet = audioform.save(commit=False)
                    print "audiofacet = audioform.save(commit=False)"
                    audiofacet.story = story
                    audiofacet.owner = request.user
                    audiofacet.organization = request.user.organization
                    audiofacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    audiofacet.discussion = discussion
                    audiofacet.save()
                    audioform.save_m2m()
                    print "audiofacet created"
                    # create history of the audiofacet
                    audiohistory = audiofacet.edit_history.all()[:5]
                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           videofacet           #
# ------------------------------ #

    # create these here for efficiency
    videoform=VideoFacetForm()
    videocommentform=VideoFacetCommentForm()
    videofacet_imageform=ImageAssetForm()

    try:
        print "VF Try"
        videofacet = get_object_or_404(VideoFacet, story=story)
        # IF WEBFACET EXISTS DO ALL OF THE FOLLOWING
        videoform = VideoFacetForm(instance=videofacet)
        # retrieve discussion and comments
        videofacetdiscussion = get_object_or_404(Discussion, id=videofacet.discussion.id)
        videocomments = Comment.objects.filter(discussion=videofacetdiscussion).order_by('-date')[:3]
        # retrieve history
        videohistory = videofacet.edit_history.all()[:5]
        # update an existing videofacet
        if request.method == "POST":
            print "VF Try If Post"
            if 'videoform' in request.POST:
                print "VF Try If Post If Videoform"
                # # #import pdb; pdb.set_trace()
                videoform = VideoFacetForm(data=request.POST, instance=videofacet)
                if videoform.is_valid():
                    print "VF Try If Post If Videoform Valid"
                    videoform.save()
                    print "videofacet updated"
                    return redirect('story_detail', pk=story.pk)
    except:
        print "VF Except If Post If Videoform Valid"
    # except VideoFacet.DoesNotExist:
        # display form and save a new videofacet
        videocomments = []
        videohistory = []
        if request.method == "POST":
            print "VF Except If Post"
            if 'videoform' in request.POST:
                print "VF Except If Post If Videoform"
                videoform = VideoFacetForm(request.POST or None)
                if videoform.is_valid():
                    # #import pdb; pdb.set_trace()
                    print "VF Except If Post If Videoform Valid"
                    videofacet = videoform.save(commit=False)
                    print "videofacet = videoform.save(commit=False)"
                    videofacet.story = story
                    videofacet.owner = request.user
                    videofacet.organization = request.user.organization
                    videofacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("VF")
                    videofacet.discussion = discussion
                    videofacet.save()
                    videoform.save_m2m()
                    print "videofacet created"
                    # create history of the videofacet
                    videohistory = videofacet.edit_history.all()[:5]
                    return redirect('story_detail', pk=story.pk)

    # ------------------------------ #
    #        Download Options        #
    # ------------------------------ #
    if story.webfacetstory.all():
        webfacet = get_object_or_404(WebFacet, story=story)
        webfacet_images = WebFacet.get_webfacet_images(webfacet)
    else:
        webfacet_images = []
    if story.printfacetstory.all():
        printfacet = get_object_or_404(PrintFacet, story=story)
        printfacet_images = PrintFacet.get_printfacet_images(printfacet)
    else:
        printfacet_images = []
    if story.audiofacetstory.all():
        audiofacet = get_object_or_404(AudioFacet, story=story)
        audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
    else:
        audiofacet_images = []
    if story.videofacetstory.all():
        videofacet = get_object_or_404(VideoFacet, story=story)
        videofacet_images = VideoFacet.get_videofacet_images(videofacet)
    else:
        videofacet_images =[]
    storydownloadform = StoryDownloadForm(story=story)

    return render(request, 'editorial/storydetail.html', {
        'story': story,
        'storydownloadform': storydownloadform,
        'storynoteform': storynoteform,
        'storynotes': storynotes,
        'storycommentform': storycommentform,
        'storycomments': storycomments,
        'webform': webform,
        'webcomments': webcomments,
        'webhistory': webhistory,
        'webcommentform': webcommentform,
        'printform': printform,
        'printcomments': printcomments,
        'printhistory': printhistory,
        'printcommentform': printcommentform,
        'audioform': audioform,
        'audiocomments': audiocomments,
        'audiohistory': audiohistory,
        'audiocommentform': audiocommentform,
        'videoform': videoform,
        'videocomments': videocomments,
        'videohistory': videohistory,
        'videocommentform': videocommentform,
        'webfacet_imageform': webfacet_imageform,
        'printfacet_imageform': printfacet_imageform,
        'audiofacet_imageform': audiofacet_imageform,
        'videofacet_imageform': videofacet_imageform,
        'images': images,
        'webfacet_images': webfacet_images,
        'printfacet_images': printfacet_images,
        'audiofacet_images': audiofacet_images,
        'videofacet_images': videofacet_images,
        })
Beispiel #4
0
def create_download(request, pk):
    """ Process download form to collect objects and create download file."""

    # get the story and associated facets no matter what options are selected
    story_id = request.POST.get('story')
    print "StoryID: ", story_id
    story = get_object_or_404(Story, id=pk)
    webfacet = story.webfacetstory.all()
    printfacet = story.printfacetstory.all()
    audiofacet = story.audiofacetstory.all()
    videofacet = story.videofacetstory.all()
    if webfacet:
        webfacet = webfacet[0]
    if printfacet:
        printfacet = printfacet[0]
    if audiofacet:
        audiofacet = audiofacet[0]
    if videofacet:
        videofacet = videofacet[0]

    # Set up zip file
    fp = StringIO()
    z = ZipFile(fp, mode="w")

    # ------------------------------ #
    #          IF SELECT ALL         #
    # ------------------------------ #

    # if select_all is chosen, then all items will be downloaded
    select_all = request.POST.get('select_all')
    print "select all: ", select_all

    if select_all:
        # collect all images
        all_images = []
        if webfacet:
            webfacet_images = WebFacet.get_webfacet_images(webfacet)
            all_images.extend(webfacet_images)
        if printfacet:
            printfacet_images = PrintFacet.get_printfacet_images(printfacet)
            all_images.extend(printfacet_images)
        if audiofacet:
            audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
            all_images.extend(audiofacet_images)
        if videofacet:
            videofacet_images = VideoFacet.get_videofacet_images(videofacet)
            all_images.extend(videofacet_images)
        print "ALL Images: ", all_images

        # Zip up all facets and assets including story metadata
        #TODO Add zip up here of any items that exist
        # storymeta.txt
        # webfacet.txt
        # printfacet.txt
        # audiofacet.txt
        # videofacet.txt
        # images.txt
        # image1.jpg

    # user can also select download all items associated with certain facets
    # ------------------------------ #
    #        IF WEBFACET ALL         #
    # ------------------------------ #
    webfacet_sa = request.POST.get('webfacet_sa')
    print "WSA: ", webfacet_sa

    if webfacet_sa:
        webfacet_images = WebFacet.get_webfacet_images(webfacet)
        print "webfacet_images ", webfacet_images

        print "Zip up all webfacet content and assets"
        #TODO Add zip up here
        # storymeta.txt
        # webfacet.txt
        # images.txt
        # image1.jpg

    # ------------------------------ #
    #       IF PRINTFACET ALL        #
    # ------------------------------ #
    printfacet_sa = request.POST.get('printfacet_sa')
    print "PSA: ", printfacet_sa

    if printfacet_sa:
        printfacet_images = PrintFacet.get_printfacet_images(printfacet)
        print "printfacet_images: ", printfacet_images
        print "Zip up all printfacet content and assets"
        #TODO Add zip up here
        # storymeta.txt
        # printfacet.txt
        # images.txt
        # image1.jpg

    # ------------------------------ #
    #       IF AUDIOFACET ALL        #
    # ------------------------------ #
    audiofacet_sa = request.POST.get('audiofacet_sa')
    print "ASA: ", audiofacet_sa

    if audiofacet_sa:
        audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
        print "audiofacet_images: ", audiofacet_images
        print "Zip up all audiofacet content and assets"
        #TODO Add zip up here
        # storymeta.txt
        # audiofacet.txt
        # images.txt
        # image1.jpg

    # ------------------------------ #
    #       IF VIDEOFACET ALL        #
    # ------------------------------ #
    videofacet_sa = request.POST.get('videofacet_sa')
    print "VDS: ", videofacet_sa

    if videofacet_sa:
        videofacet_images = VideoFacet.get_videofacet_images(videofacet)
        print "videofacet_images", videofacet_images
        print "Zip up all videofacet content and assets"
        #TODO Add zip up here
        # storymeta.txt
        # videofacet.txt
        # images.txt
        # image1.jpg

    else:
    # if not select all OR facet select all, then user chooses the facet and the images
    # ------------------------------ #
    #      IF WEBFACET SPECIFIC      #
    # ------------------------------ #
        webfacet_only = request.POST.get('webfacet')
        if webfacet_only:
            print "Zip up webfacet content and meta."
            #TODO Add zip up here
            # storymeta.txt
            # webfacet.txt
    # ------------------------------ #
    #    IF PRINTFACET SPECIFIC      #
    # ------------------------------ #
        printfacet_only = request.POST.get('printfacet')
        if printfacet_only:
            print "Zip up printfacet content and meta."
            #TODO Add zip up here
            # storymeta.txt
            # printfacet.txt
    # ------------------------------ #
    #      IF AUDIOFACET SPECIFIC    #
    # ------------------------------ #
        audiofacet_only = request.POST.get('audiofacet')
        if audiofacet_only:
            print "Zip up audiofacet content and meta."
            #TODO Add zip up here
            # storymeta.txt
            # audiofacet.txt
    # ------------------------------ #
    #      IF VIDEOFACET SPECIFIC    #
    # ------------------------------ #
        videofacet_only = request.POST.get('videofacet')
        if videofacet_only:
            print "Zip up videofacet content and meta."
            #TODO Add zip up here
            # storymeta.txt
            # videofacet.txt
    # ------------------------------ #
    #       IF SPECIFIC IMAGES       #
    # ------------------------------ #
        # if not select all, then user chooses the facet and the images
        images = request.POST.getlist('images')
        images = ImageAsset.objects.filter(pk__in=images)
        print "Images: ", images
        if images:
            print "Zip up images and image meta."
            #TODO Add zip up here
            # imagemeta.txt
            # image1.jpg
            #image2.jpg

    # ------------------------------ #
    #         Create download        #
    # ------------------------------ #




    return redirect('story_detail', pk=story.pk)
Beispiel #5
0
def copy_network_story(request, pk):
    """ Copy a story and related facets. """

    original_story = get_object_or_404(Story, pk=pk)
    original_org = original_story.organization

    original_webfacet = original_story.webfacetstory.all()
    original_printfacet = original_story.printfacetstory.all()
    original_audiofacet = original_story.audiofacetstory.all()
    original_videofacet = original_story.videofacetstory.all()

    user = request.user
    organization = request.user.organization
    partner = request.user.organization

    if request.method == "POST":

        #Create a copy of the story and a storycopydetail record
        copied_story = Story.copy_story(original_story)
        copied_story.owner = user
        copied_story.organization = organization
        copied_story.save()
        partner_story = copied_story
        story_copy_record = StoryCopyDetail.objects.create_story_copy_record(
            original_org=original_org,
            partner=partner,
            original_story=original_story,
            partner_story=partner_story
            )
        print "Story Copied"

        # Create copy of facets if they exist
        if original_webfacet:
            print original_webfacet[0]
            copied_webfacet = WebFacet.copy_webfacet(original_webfacet[0])
            copied_webfacet.story = partner_story
            copied_webfacet.owner = user
            copied_webfacet.organization = organization
            copied_webfacet.save()
            partner_webfacet = copied_webfacet
            webfacet_copy_record = WebFacetCopyDetail.objects.create_webfacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_webfacet=original_webfacet[0],
                partner_webfacet=partner_webfacet
            )
            print "Webfacet Copied"

        if original_printfacet:
            print original_printfacet[0]
            copied_printfacet = PrintFacet.copy_printfacet(original_printfacet[0])
            copied_printfacet.story = partner_story
            copied_printfacet.owner = user
            copied_printfacet.organization = organization
            copied_printfacet.save()
            partner_printfacet = copied_printfacet
            printfacet_copy_record = PrintFacetCopyDetail.objects.create_printfacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_printfacet=original_printfacet,
                partner_printfacet=partner_printfacet
            )
            print "Printfacet Copied"

        if original_audiofacet:
            print original_audiofacet[0]
            copied_audiofacet = AudioFacet.copy_audiofacet(original_audiofacet[0])
            copied_audiofacet.story = partner_story
            copied_audiofacet.owner = user
            copied_audiofacet.organization = organization
            copied_audiofacet.save()
            partner_audiofacet = copied_audiofacet
            audiofacet_copy_record = AudioFacetCopyDetail.objects.create_audiofacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_audiofacet=original_audiofacet,
                partner_audiofacet=partner_audiofacet
            )
            print "Audiofacet Copied"

        if original_videofacet:
            print original_videofacet[0]
            copied_videofacet = VideoFacet.copy_videofacet(original_videofacet[0])
            copied_videofacet.story = partner_story
            copied_videofacet.owner = user
            copied_videofacet.organization = organization
            copied_videofacet.save()
            partner_videofacet = copied_videofacet
            videofacet_copy_record = VideoFacetCopyDetail.objects.create_videofacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_videofacet=original_videofacet,
                partner_videofacet=partner_videofacet
            )
            print "Videofacet Copied"

    return redirect('network_stories')
Beispiel #6
0
def story_detail(request, pk):
    """ The detail page for a story.

    Displays the story's planning notes, discussion, assets, share and collaboration status
    and sensivity status. From here the user can also see any facets, edit them and add new ones.
    """

    story = get_object_or_404(Story, pk=pk)
    storynoteform = StoryNoteForm()
    storynotes = StoryNote.objects.filter(story=story)
    storycommentform = StoryCommentForm()
    storydiscussion = get_object_or_404(Discussion, id=story.discussion.id)
    storycomments = Comment.objects.filter(discussion=storydiscussion).order_by('-date')

    notes = StoryNote.objects.filter(story=story)

    images = Organization.get_org_image_library(request.user.organization)
    documents = Organization.get_org_document_library(request.user.organization)
    audiofiles = Organization.get_org_audio_library(request.user.organization)
    videos = Organization.get_org_video_library(request.user.organization)

    imageassetform=ImageAssetForm()
    documentassetform=DocumentAssetForm()
    audioassetform=AudioAssetForm()
    videoassetform=VideoAssetForm()

# ------------------------------ #
#           webfacet             #
# ------------------------------ #

    # create these here for efficiency
    webform=WebFacetForm(request=request, story=story)
    webcommentform=WebFacetCommentForm()

    try:
        webfacet = get_object_or_404(WebFacet, story=story)
        # IF WEBFACET EXISTS DO ALL OF THE FOLLOWING
        webform = WebFacetForm(instance=webfacet, request=request, story=story)
        # retrieve discussion and comments
        webfacetdiscussion = get_object_or_404(Discussion, id=webfacet.discussion.id)
        webcomments = Comment.objects.filter(discussion=webfacetdiscussion).order_by('-date')[:3]
        # retrieve history
        webhistory = webfacet.edit_history.all()[:5]
        # update an existing webfacet
        if request.method == "POST":
            if 'webform' in request.POST:
                webform = WebFacetForm(data=request.POST, instance=webfacet, request=request, story=story)
                if webform.is_valid():
                    webform.save()
                    # record action for activity stream
                    action.send(request.user, verb="edited", action_object=webfacet)

                    return redirect('story_detail', pk=story.pk)
    except:
        # except WebFacet.DoesNotExist:
        # display form and save a new webfacet
        webcomments = []
        webhistory = []
        if request.method == "POST":
            if 'webform' in request.POST:
                webform = WebFacetForm(data=request.POST, request=request, story=story)
                if webform.is_valid():
                    webfacet = webform.save(commit=False)
                    webfacet.story = story
                    webfacet.owner = request.user
                    webfacet.organization = request.user.organization
                    webfacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    webfacet.discussion = discussion
                    webfacet.save()
                    webform.save_m2m()
                    # create history of the webfacet
                    webhistory = webfacet.edit_history.all()[:5]
                    # record action for activity stream
                    action.send(request.user, verb="created", action_object=webfacet)

                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           printfacet           #
# ------------------------------ #

    # create these here for efficiency
    printform=PrintFacetForm(request=request, story=story)
    printcommentform=PrintFacetCommentForm()

    try:
        printfacet = get_object_or_404(PrintFacet, story=story)
        # IF PRINTFACET EXISTS DO ALL OF THE FOLLOWING
        printform = PrintFacetForm(instance=printfacet, request=request, story=story)
        # retrieve discussion and comments
        printfacetdiscussion = get_object_or_404(Discussion, id=printfacet.discussion.id)
        printcomments = Comment.objects.filter(discussion=printfacetdiscussion).order_by('-date')[:3]
        # retrieve history
        printhistory = printfacet.edit_history.all()[:5]
        # update an existing printfacet
        if request.method == "POST":
            if 'printform' in request.POST:
                printform = PrintFacetForm(data=request.POST, instance=printfacet, request=request, story=story)
                if printform.is_valid():
                    printform.save()
                    # record action for activity stream
                    action.send(request.user, verb="edited", action_object=printfacet)

                    return redirect('story_detail', pk=story.pk)
    except:
        # except PrintFacet.DoesNotExist:
        # display form and save a new printfacet
        printcomments = []
        printhistory = []
        if request.method == "POST":
            if 'printform' in request.POST:
                printform = PrintFacetForm(data=request.POST, request=request, story=story)
                if printform.is_valid():
                    printfacet = printform.save(commit=False)
                    printfacet.story = story
                    printfacet.owner = request.user
                    printfacet.organization = request.user.organization
                    printfacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    printfacet.discussion = discussion
                    printfacet.save()
                    printform.save_m2m()
                    # create history of the printfacet
                    printhistory = printfacet.edit_history.all()[:5]
                    # record action for activity stream
                    action.send(request.user, verb="created", action_object=printfacet)

                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           audiofacet           #
# ------------------------------ #

    # create these here for efficiency
    audioform=AudioFacetForm(request=request, story=story)
    audiocommentform=AudioFacetCommentForm()

    try:
        audiofacet = get_object_or_404(AudioFacet, story=story)
        # IF AUDIOFACET EXISTS DO ALL OF THE FOLLOWING
        audioform = AudioFacetForm(instance=audiofacet, request=request, story=story)
        # retrieve discussion and comments
        audiofacetdiscussion = get_object_or_404(Discussion, id=audiofacet.discussion.id)
        audiocomments = Comment.objects.filter(discussion=audiofacetdiscussion).order_by('-date')[:3]
        # retrieve history
        audiohistory = audiofacet.edit_history.all()[:5]
        # update an existing audiofacet
        if request.method == "POST":
            if 'audioform' in request.POST:
                audioform = AudioFacetForm(data=request.POST, instance=audiofacet, request=request, story=story)
                if audioform.is_valid():
                    audioform.save()

                    # record action for activity stream
                    action.send(request.user, verb="edited", action_object=audiofacet)

                    return redirect('story_detail', pk=story.pk)
    except:
        # except AudioFacet.DoesNotExist:
        # display form and save a new audiofacet
        audiocomments = []
        audiohistory = []
        if request.method == "POST":
            if 'audioform' in request.POST:
                audioform = AudioFacetForm(data=request.POST, request=request, story=story)
                if audioform.is_valid():
                    audiofacet = audioform.save(commit=False)
                    audiofacet.story = story
                    audiofacet.owner = request.user
                    audiofacet.organization = request.user.organization
                    audiofacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("WF")
                    audiofacet.discussion = discussion
                    audiofacet.save()
                    audioform.save_m2m()
                    # create history of the audiofacet
                    audiohistory = audiofacet.edit_history.all()[:5]
                    # record action for activity stream
                    action.send(request.user, verb="created", action_object=audiofacet)

                    return redirect('story_detail', pk=story.pk)

# ------------------------------ #
#           videofacet           #
# ------------------------------ #

    # create these here for efficiency
    videoform=VideoFacetForm(request=request, story=story)
    videocommentform=VideoFacetCommentForm()

    try:
        videofacet = get_object_or_404(VideoFacet, story=story)
        # IF WEBFACET EXISTS DO ALL OF THE FOLLOWING
        videoform = VideoFacetForm(instance=videofacet, request=request, story=story)
        # retrieve discussion and comments
        videofacetdiscussion = get_object_or_404(Discussion, id=videofacet.discussion.id)
        videocomments = Comment.objects.filter(discussion=videofacetdiscussion).order_by('-date')[:3]
        # retrieve history
        videohistory = videofacet.edit_history.all()[:5]
        # update an existing videofacet
        if request.method == "POST":
            if 'videoform' in request.POST:
                videoform = VideoFacetForm(data=request.POST, instance=videofacet, request=request, story=story)
                if videoform.is_valid():
                    videoform.save()
                    # record action for activity stream
                    action.send(request.user, verb="edited", action_object=videofacet)
                    return redirect('story_detail', pk=story.pk)
    except:
        # except VideoFacet.DoesNotExist:
        # display form and save a new videofacet
        videocomments = []
        videohistory = []
        if request.method == "POST":
            if 'videoform' in request.POST:
                videoform = VideoFacetForm(data=request.POST, request=request, story=story)
                if videoform.is_valid():
                    videofacet = videoform.save(commit=False)
                    videofacet.story = story
                    videofacet.owner = request.user
                    videofacet.organization = request.user.organization
                    videofacet.creation_date = timezone.now()
                    discussion = Discussion.objects.create_discussion("VF")
                    videofacet.discussion = discussion
                    videofacet.save()
                    videoform.save_m2m()
                    # create history of the videofacet
                    videohistory = videofacet.edit_history.all()[:5]
                    # record action for activity stream
                    action.send(request.user, verb="created", action_object=videofacet)

                    return redirect('story_detail', pk=story.pk)

    # ------------------------------ #
    #        Download Options        #
    # ------------------------------ #
    if story.webfacetstory.all():
        webfacet = get_object_or_404(WebFacet, story=story)
        webfacet_images = WebFacet.get_webfacet_images(webfacet)
        webfacet_documents = WebFacet.get_webfacet_documents(webfacet)
        webfacet_audio = WebFacet.get_webfacet_audio(webfacet)
        webfacet_video = WebFacet.get_webfacet_video(webfacet)
    else:
        webfacet_images = []
        webfacet_documents = []
        webfacet_audio = []
        webfacet_video = []

    if story.printfacetstory.all():
        printfacet = get_object_or_404(PrintFacet, story=story)
        printfacet_images = PrintFacet.get_printfacet_images(printfacet)
        printfacet_documents = PrintFacet.get_printfacet_documents(printfacet)
        printfacet_audio = PrintFacet.get_printfacet_audio(printfacet)
        printfacet_video = PrintFacet.get_printfacet_video(printfacet)
    else:
        printfacet_images = []
        printfacet_documents = []
        printfacet_audio = []
        printfacet_video = []

    if story.audiofacetstory.all():
        audiofacet = get_object_or_404(AudioFacet, story=story)
        audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
        audiofacet_documents = AudioFacet.get_audiofacet_documents(audiofacet)
        audiofacet_audio = AudioFacet.get_audiofacet_audio(audiofacet)
        audiofacet_video = AudioFacet.get_audiofacet_video(audiofacet)
    else:
        audiofacet_images = []
        audiofacet_documents = []
        audiofacet_audio = []
        audiofacet_video = []

    if story.videofacetstory.all():
        videofacet = get_object_or_404(VideoFacet, story=story)
        videofacet_images = VideoFacet.get_videofacet_images(videofacet)
        videofacet_documents = VideoFacet.get_videofacet_documents(videofacet)
        videofacet_audio = VideoFacet.get_videofacet_audio(videofacet)
        videofacet_video = VideoFacet.get_videofacet_video(videofacet)
    else:
        videofacet_images = []
        videofacet_documents = []
        videofacet_audio = []
        videofacet_video = []

    storydownloadform = StoryDownloadForm(story=story)

    return render(request, 'editorial/storydetail.html', {
        'story': story,
        'storydownloadform': storydownloadform,
        'storynoteform': storynoteform,
        'storynotes': storynotes,
        'storycommentform': storycommentform,
        'storycomments': storycomments,
        'webform': webform,
        'webcomments': webcomments,
        'webhistory': webhistory,
        'webcommentform': webcommentform,
        'printform': printform,
        'printcomments': printcomments,
        'printhistory': printhistory,
        'printcommentform': printcommentform,
        'audioform': audioform,
        'audiocomments': audiocomments,
        'audiohistory': audiohistory,
        'audiocommentform': audiocommentform,
        'videoform': videoform,
        'videocomments': videocomments,
        'videohistory': videohistory,
        'videocommentform': videocommentform,
        'images': images,
        'imageassetform': imageassetform,
        'documentassetform': documentassetform,
        'audioassetform': audioassetform,
        'videoassetform': videoassetform,
        'webfacet_images': webfacet_images,
        'printfacet_images': printfacet_images,
        'audiofacet_images': audiofacet_images,
        'videofacet_images': videofacet_images,
        'documents': documents,
        'webfacet_documents': webfacet_documents,
        'printfacet_documents': printfacet_documents,
        'audiofacet_documents': audiofacet_documents,
        'videofacet_documents': videofacet_documents,
        'audiofiles': audiofiles,
        'webfacet_audio': webfacet_audio,
        'printfacet_audio': printfacet_audio,
        'audiofacet_audio': audiofacet_audio,
        'videofacet_audio': videofacet_audio,
        'videos': videos,
        'webfacet_video': webfacet_video,
        'printfacet_video': printfacet_video,
        'audiofacet_video': audiofacet_video,
        'videofacet_video': videofacet_video,
        })
Beispiel #7
0
def copy_network_story(request, pk):
    """ Copy a story and related facets. """

    original_story = get_object_or_404(Story, pk=pk)
    original_org = original_story.organization

    original_webfacet = original_story.webfacetstory.all()
    original_printfacet = original_story.printfacetstory.all()
    original_audiofacet = original_story.audiofacetstory.all()
    original_videofacet = original_story.videofacetstory.all()

    user = request.user
    organization = request.user.organization
    partner = request.user.organization

    # record action for activity story_team
    # action.send(request.user, verb="picked up", action_object=original_story)

    if request.method == "POST":

        # Create a copy of the story and a storycopydetail record
        copied_story = Story.copy_story(original_story)
        copied_story.owner = user
        copied_story.organization = organization
        copied_story.save()
        story_copy_record = StoryCopyDetail.objects.create_story_copy_record(
            original_org=original_org,
            partner=partner,
            original_story=original_story,
            partner_story=copied_story
            )

        # Create copy of facets if they exist
        # Copy the WebFacet
        if original_webfacet:
            print original_webfacet[0]
            copied_webfacet = WebFacet.copy_webfacet(original_webfacet[0])
            copied_webfacet.story = copied_story
            copied_webfacet.owner = user
            copied_webfacet.organization = organization
            copied_webfacet.save()
            webfacet_copy_record = WebFacetCopyDetail.objects.create_webfacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_webfacet=original_webfacet[0],
                partner_webfacet=copied_webfacet
            )

            # create copy of webfacet images
            original_webfacet_images = WebFacet.get_webfacet_images(original_webfacet[0])
            for image in original_webfacet_images:
                copied_image = ImageAsset.copy_image(image)
                copied_image.owner = user
                copied_image.organization = organization
                copied_image.save()
                imageasset_copy_record = ImageAssetCopyDetail.objects.create_imageasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_imageasset=image,
                    partner_imageasset=copied_image
                )
                # add image to copied webfacet
                copied_webfacet.image_assets.add(copied_image)
                copied_webfacet.save()

            # create copy of webfacet documents
            original_webfacet_documents = WebFacet.get_webfacet_documents(original_webfacet[0])
            for document in original_webfacet_documents:
                copied_document = DocumentAsset.copy_document(document)
                copied_document.owner = user
                copied_document.organization = organization
                copied_document.save()
                documentasset_copy_record = DocumentAssetCopyDetail.objects.create_documentasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_documentasset=document,
                    partner_documentasset=copied_document
                )
                # add document to copied webfacet
                copied_webfacet.document_assets.add(copied_document)
                copied_webfacet.save()


            # create copy of webfacet audio
            original_webfacet_audiofiles = WebFacet.get_webfacet_audio(original_webfacet[0])
            for audio in original_webfacet_audiofiles:
                copied_audio = AudioAsset.copy_audio(audio)
                copied_audio.owner = user
                copied_audio.organization = organization
                copied_audio.save()
                audioasset_copy_record = AudioAssetCopyDetail.objects.create_audioasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_audioasset=audio,
                    partner_audioasset=copied_audio
                )
                # add audio to copied webfacet
                copied_webfacet.audio_assets.add(copied_audio)
                copied_webfacet.save()

            # create copy of webfacet video
            # original_webfacet_video = WebFacet.get_webfacet_video(original_webfacet[0])
            for video in original_webfacet_videos:
                copied_video = VideoAsset.copy_video(video)
                copied_video.owner = user
                copied_video.organization = organization
                copied_video.save()
                videoasset_copy_record = VideoAssetCopyDetail.objects.create_videoasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_videoasset=video,
                    partner_videoasset=copied_video
                )
                # add video to copied webfacet
                copied_webfacet.video_assets.add(copied_video)
                copied_webfacet.save()

        # Copy the PrintFacet
        if original_printfacet:
            print original_printfacet[0]
            copied_printfacet = PrintFacet.copy_printfacet(original_printfacet[0])
            copied_printfacet.story = copied_story
            copied_printfacet.owner = user
            copied_printfacet.organization = organization
            copied_printfacet.save()
            printfacet_copy_record = PrintFacetCopyDetail.objects.create_printfacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_printfacet=original_printfacet,
                partner_printfacet=copied_printfacet
            )

            # create copy of printfacet images
            original_printfacet_images = PrintFacet.get_printfacet_images(original_printfacet[0])
            for image in original_printfacet_images:
                copied_image = ImageAsset.copy_image(image)
                copied_image.owner = user
                copied_image.organization = organization
                copied_image.save()
                imageasset_copy_record = ImageAssetCopyDetail.objects.create_imageasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_imageasset=image,
                    partner_imageasset=copied_image
                )
                # add image to copied printfacet
                copied_printfacet.image_assets.add(copied_image)
                copied_printfacet.save()

            # create copy of printfacet documents
            original_printfacet_documents = PrintFacet.get_printfacet_documents(original_printfacet[0])
            for document in original_printfacet_documents:
                copied_document = DocumentAsset.copy_document(document)
                copied_document.owner = user
                copied_document.organization = organization
                copied_document.save()
                documentasset_copy_record = DocumentAssetCopyDetail.objects.create_documentasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_documentasset=document,
                    partner_documentasset=copied_document
                )
                # add document to copied printfacet
                copied_printfacet.document_assets.add(copied_document)
                copied_printfacet.save()


            # create copy of printfacet audio
            original_printfacet_audiofiles = PrintFacet.get_printfacet_audio(original_printfacet[0])
            for audio in original_printfacet_audios:
                copied_audio = AudioAsset.copy_audio(audio)
                copied_audio.owner = user
                copied_audio.organization = organization
                copied_audio.save()
                audioasset_copy_record = AudioAssetCopyDetail.objects.create_audioasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_audioasset=audio,
                    partner_audioasset=copied_audio
                )
                # add audio to copied printfacet
                copied_printfacet.audio_assets.add(copied_audio)
                copied_printfacet.save()

            # create copy of printfacet video
            original_printfacet_video = PrintFacet.get_printfacet_video(original_printfacet[0])
            for video in original_printfacet_videos:
                copied_video = VideoAsset.copy_video(video)
                copied_video.owner = user
                copied_video.organization = organization
                copied_video.save()
                videoasset_copy_record = VideoAssetCopyDetail.objects.create_videoasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_videoasset=video,
                    partner_videoasset=copied_video
                )
                # add video to copied printfacet
                copied_printfacet.video_assets.add(copied_video)
                copied_printfacet.save()

        # Copy the AudioFacet
        if original_audiofacet:
            print original_audiofacet[0]
            copied_audiofacet = AudioFacet.copy_audiofacet(original_audiofacet[0])
            copied_audiofacet.story = copied_story
            copied_audiofacet.owner = user
            copied_audiofacet.organization = organization
            copied_audiofacet.save()
            audiofacet_copy_record = AudioFacetCopyDetail.objects.create_audiofacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_audiofacet=original_audiofacet,
                partner_audiofacet=copied_audiofacet
            )
            print "Audiofacet Copied"

            # create copy of audiofacet images
            original_audiofacet_images = AudioFacet.get_audiofacet_images(original_audiofacet[0])
            for image in original_audiofacet_images:
                copied_image = ImageAsset.copy_image(image)
                copied_image.owner = user
                copied_image.organization = organization
                copied_image.save()
                imageasset_copy_record = ImageAssetCopyDetail.objects.create_imageasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_imageasset=image,
                    partner_imageasset=copied_image
                )
                # add image to copied audiofacet
                copied_audiofacet.image_assets.add(copied_image)
                copied_audiofacet.save()

            # create copy of audiofacet documents
            original_audiofacet_documents = AudioFacet.get_audiofacet_documents(original_audiofacet[0])
            for document in original_audiofacet_documents:
                copied_document = DocumentAsset.copy_document(document)
                copied_document.owner = user
                copied_document.organization = organization
                copied_document.save()
                documentasset_copy_record = DocumentAssetCopyDetail.objects.create_documentasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_documentasset=document,
                    partner_documentasset=copied_document
                )
                # add document to copied audiofacet
                copied_audiofacet.document_assets.add(copied_document)
                copied_audiofacet

            # create copy of audiofacet audio
            original_audiofacet_audiofiles = AudioFacet.get_audiofacet_audio(original_audiofacet[0])
            for audio in original_audiofacet_audios:
                copied_audio = AudioAsset.copy_audio(audio)
                copied_audio.owner = user
                copied_audio.organization = organization
                copied_audio.save()
                audioasset_copy_record = AudioAssetCopyDetail.objects.create_audioasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_audioasset=audio,
                    partner_audioasset=copied_audio
                )
                # add audio to copied audiofacet
                copied_audiofacet.audio_assets.add(copied_audio)
                copied_audiofacet.save()

            # create copy of audiofacet video
            original_audiofacet_video = AudioFacet.get_audiofacet_video(original_audiofacet[0])
            for video in original_audiofacet_videos:
                copied_video = VideoAsset.copy_video(video)
                copied_video.owner = user
                copied_video.organization = organization
                copied_video.save()
                videoasset_copy_record = VideoAssetCopyDetail.objects.create_videoasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_videoasset=video,
                    partner_videoasset=copied_video
                )
                # add video to copied audiofacet
                copied_audiofacet.video_assets.add(copied_video)
                copied_audiofacet.save()

        # Copy the VideoFacet
        if original_videofacet:
            print original_videofacet[0]
            copied_videofacet = VideoFacet.copy_videofacet(original_videofacet[0])
            copied_videofacet.story = copied_story
            copied_videofacet.owner = user
            copied_videofacet.organization = organization
            copied_videofacet.save()
            videofacet_copy_record = VideoFacetCopyDetail.objects.create_videofacet_copy_record(
                original_org=original_org,
                partner=partner,
                original_videofacet=original_videofacet,
                partner_videofacet=copied_videofacet
            )
            print "Videofacet Copied"


            # create copy of videofacet images
            original_videofacet_images = VideoFacet.get_videofacet_images(original_videofacet[0])
            for image in original_videofacet_images:
                copied_image = ImageAsset.copy_image(image)
                copied_image.owner = user
                copied_image.organization = organization
                copied_image.save()
                imageasset_copy_record = ImageAssetCopyDetail.objects.create_imageasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_imageasset=image,
                    partner_imageasset=copied_image
                )
                # add image to copied videofacet
                partner_videofacet.image_assets.add(copied_image)
                partner_videofacet.save()

            # create copy of videofacet documents
            original_videofacet_documents = VideoFacet.get_videofacet_documents(original_videofacet[0])
            for document in original_videofacet_documents:
                copied_document = DocumentAsset.copy_document(document)
                copied_document.owner = user
                copied_document.organization = organization
                copied_document.save()
                documentasset_copy_record = DocumentAssetCopyDetail.objects.create_documentasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_documentasset=document,
                    partner_documentasset=copied_document
                )
                # add document to copied videofacet
                partner_documentasset.document_assets.add(copied_document)
                partner_documentasset.save()


            # create copy of videofacet audio
            original_videofacet_audiofiles = VideoFacet.get_videofacet_audio(original_videofacet[0])
            for audio in original_videofacet_audiofiles:
                copied_audio = AudioAsset.copy_audio(audio)
                copied_audio.owner = user
                copied_audio.organization = organization
                copied_audio.save()
                audioasset_copy_record = AudioAssetCopyDetail.objects.create_audioasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_audioasset=audio,
                    partner_audioasset=copied_audio
                )
                # add audio to copied audiofacet
                partner_audioasset.audio_assets.add(copied_audio)
                partner_audioasset.save()

            # create copy of videofacet video
            original_videofacet_video = VideoFacet.get_videofacet_video(original_videofacet[0])
            for video in original_videofacet_videos:
                copied_video = VideoAsset.copy_video(video)
                copied_video.owner = user
                copied_video.organization = organization
                copied_video.save()
                videoasset_copy_record = VideoAssetCopyDetail.objects.create_videoasset_copy_record(
                    original_org=original_org,
                    partner=partner,
                    original_videoasset=video,
                    partner_videoasset=copied_video
                )
                # add video to copied videofacet
                partner_videoasset.video_assets.add(copied_video)
                partner_videoasset.save()



    return redirect('network_stories')
Beispiel #8
0
def create_download(request, pk):
    """ Process download form to collect objects and create download file."""

    # get the story and associated facets no matter what options are selected
    story_id = request.POST.get('story')
    story = get_object_or_404(Story, id=pk)
    story_txt = Story.get_story_download(story)
    select_all_images = []
    image_txt = ""
    select_all_documents = []
    document_txt = ""
    select_all_audio = []
    audio_txt = ""

    if story.webfacetstory.all():
        webfacet = story.webfacetstory.all()[0]
        webfacet_images = WebFacet.get_webfacet_images(webfacet)
        webfacet_documents = WebFacet.get_webfacet_documents(webfacet)
        webfacet_audio = WebFacet.get_webfacet_audio(webfacet)
        select_all_images.extend(webfacet_images)
        select_all_documents.extend(webfacet_documents)
        select_all_audio.extend(webfacet_audio)
        webfacet_txt = WebFacet.get_webfacet_download(webfacet)
    if story.printfacetstory.all():
        printfacet = story.printfacetstory.all()[0]
        printfacet_images = PrintFacet.get_printfacet_images(printfacet)
        printfacet_documents = PrintFacet.get_printfacet_documents(printfacet)
        printfacet_audio = PrintFacet.get_printfacet_audio(printfacet)
        select_all_images.extend(printfacet_images)
        select_all_documents.extend(printfacet_documents)
        select_all_audio.extend(printfacet_audio)
        printfacet_txt = PrintFacet.get_printfacet_download(printfacet)
    if story.audiofacetstory.all():
        audiofacet = story.audiofacetstory.all()[0]
        audiofacet_images = AudioFacet.get_audiofacet_images(audiofacet)
        audiofacet_documents = AudioFacet.get_audiofacet_documents(audiofacet)
        audiofacet_audio = AudioFacet.get_audiofacet_audio(audiofacet)
        select_all_images.extend(audiofacet_images)
        select_all_documents.extend(audiofacet_documents)
        select_all_audio.extend(audiofacet_audio)
        audiofacet_txt = AudioFacet.get_audiofacet_download(audiofacet)
    if story.videofacetstory.all():
        videofacet = story.videofacetstory.all()[0]
        videofacet_images = VideoFacet.get_videofacet_images(videofacet)
        videofacet_documents = VideoFacet.get_videofacet_documents(videofacet)
        videofacet_audio = VideoFacet.get_videofacet_audio(videofacet)
        select_all_images.extend(videofacet_images)
        select_all_documents.extend(videofacet_documents)
        select_all_audio.extend(videofacet_audio)
        videofacet_txt = VideoFacet.get_videofacet_download(videofacet)

    # Set up zip file
    fp = StringIO()
    z = ZipFile(fp, mode="w")
    # Always Zip up story meta
    z.writestr("story.txt", story_txt)

    # ------------------------------ #
    #          IF SELECT ALL         #
    # ------------------------------ #
    # if select_all is chosen, then all items will be downloaded
    select_all = request.POST.get('select_all')
    print "select all: ", select_all

    if select_all:
        # Zip up all facets and assets including story metadata
        if story.webfacetstory.all():
            z.writestr("webstory.txt", webfacet_txt)
        if story.printfacetstory.all():
            z.writestr("printstory.txt", printfacet_txt)
        if story.audiofacetstory.all():
            z.writestr("audiostory.txt", audiofacet_txt)
        if story.videofacetstory.all():
            z.writestr("videostory.txt", videofacet_txt)
        for image in select_all_images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info
        for document in select_all_documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
        for audiofile in select_all_audio:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info

    # user can also select download all items associated with certain facets
    # ------------------------------ #
    #        IF WEBFACET ALL         #
    # ------------------------------ #
    webfacet_sa = request.POST.get('webfacet_sa')
    print "WSA: ", webfacet_sa

    if webfacet_sa:
        # Zip up story meta, webfacet content and webfacet images
        if story.webfacetstory.all():
            z.writestr("webstory.txt", webfacet_txt)
        for image in webfacet_images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info
        for document in webfacet_documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
        for audiofile in webfacet_audio:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info

    # ------------------------------ #
    #       IF PRINTFACET ALL        #
    # ------------------------------ #
    printfacet_sa = request.POST.get('printfacet_sa')
    print "PSA: ", printfacet_sa

    if printfacet_sa:
        # Zip up story meta, printfacet content and printfacet images
        if story.printfacetstory.all():
            z.writestr("printstory.txt", printfacet_txt)
        for image in printfacet_images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info
        for document in printfacet_documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
        for audiofile in printfacet_audio:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info


    # ------------------------------ #
    #       IF AUDIOFACET ALL        #
    # ------------------------------ #
    audiofacet_sa = request.POST.get('audiofacet_sa')
    print "ASA: ", audiofacet_sa

    if audiofacet_sa:
        # Zip up story meta, audiofacet content and audiofacet images
        if story.audiofacetstory.all():
            z.writestr("audiostory.txt", audiofacet_txt)
        for image in audiofacet_images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info
        for document in audiofacet_documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
        for audiofile in audiofacet_audio:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info


    # ------------------------------ #
    #       IF VIDEOFACET ALL        #
    # ------------------------------ #
    videofacet_sa = request.POST.get('videofacet_sa')
    print "VDS: ", videofacet_sa

    if videofacet_sa:
        # Zip up story meta, audiofacet content and audiofacet images
        if story.videofacetstory.all():
            z.writestr("videostory.txt", videofacet_txt)
        for image in videofacet_images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info
        for document in videofacet_documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
        for audiofile in videofacet_audio:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info


    # if not select all OR facet select all, then user chooses the facet and the images
    # ------------------------------ #
    #      IF WEBFACET SPECIFIC      #
    # ------------------------------ #
    webfacet_only = request.POST.get('webfacet')
    if webfacet_only:
        z.writestr("webstory.txt", webfacet_txt)

    # ------------------------------ #
    #    IF PRINTFACET SPECIFIC      #
    # ------------------------------ #
    printfacet_only = request.POST.get('printfacet')
    if printfacet_only:
        z.writestr("printstory.txt", printfacet_txt)

    # ------------------------------ #
    #      IF AUDIOFACET SPECIFIC    #
    # ------------------------------ #
    audiofacet_only = request.POST.get('audiofacet')
    if audiofacet_only:
        z.writestr("audiostory.txt", audiofacet_txt)

    # ------------------------------ #
    #      IF VIDEOFACET SPECIFIC    #
    # ------------------------------ #
    videofacet_only = request.POST.get('videofacet')
    if videofacet_only:
        z.writestr("videostory.txt", videofacet_txt)

    # ------------------------------ #
    #       IF SPECIFIC IMAGES       #
    # ------------------------------ #
    # if not select all or by facet, then user chooses specific images
    images = request.POST.getlist('images')
    images = ImageAsset.objects.filter(pk__in=images)
    print "Images: ", images
    if images:
        for image in images:
            z.writestr("{image}.jpg".format(image=image.asset_title), image.photo.read())
            new_info = ImageAsset.get_image_download_info(image)
            image_txt += new_info

    # ------------------------------ #
    #     IF SPECIFIC DOCUMENTS      #
    # ------------------------------ #
    # if not select all or by facet, then user chooses specific documents
    documents = request.POST.getlist('documents')
    documents = DocumentAsset.objects.filter(pk__in=documents)
    print "Documents: ", documents
    if documents:
        for document in documents:
            if document.doc_type == "PDF":
                z.writestr("{document}.pdf".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "WORD":
                z.writestr("{document}.docx".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "TXT":
                z.writestr("{document}.txt".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "CSV":
                z.writestr("{document}.csv".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info
            if document.doc_type == "XLS":
                z.writestr("{document}.xls".format(document=document.asset_title), document.document.read())
                new_info = DocumentAsset.get_document_download_info(document)
                document_txt += new_info

    # ------------------------------ #
    #       IF SPECIFIC AUDIO        #
    # ------------------------------ #
    # if not select all or by facet, then user chooses specific audiofiles

    audiofiles = request.POST.getlist('audiofiles')
    audiofiles = AudioAsset.objects.filter(pk__in=audiofiles)
    print "Audiofiles: ", audiofiles
    if audiofiles:
        for audiofile in audiofiles:
            if audiofile.audio_type == "MP3":
                z.writestr("{audiofile}.mp3".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info
            if audiofile.audio_type == "WAV":
                z.writestr("{audiofile}.wav".format(audiofile=document.asset_title), audiofile.audio.read())
                new_info = AudioAsset.get_audio_download_info(audiofile)
                audio_txt += new_info

    # ------------------------------ #
    #         Create download        #
    # ------------------------------ #
    #Take the final version of image_txt and write it.
    z.writestr("image.txt", image_txt)
    z.writestr("document.txt", document_txt)
    z.writestr("audio.txt", audio_txt)

    z.close()
    fp.seek(0)
    response = HttpResponse(fp, content_type='application/zip')
    fp.close()


    return response