Beispiel #1
0
def dashboard(request):
    """ Returns user's unique dashboard.

    Displays new comments since last_login from any discussions including user.
    Ex: Felicity S. replied to Series: "Palmer Tech Innovation Conference" discussion
    Displays table of new content created since last_login
    Displays any content with deadlines sameday/next day for any content where user is part of team.
    Displays log of other user activity since last_login
    Ex: Oliver Q. added "Dhark Indicted" to Story: "Star City Organized Crime Leader Arrested"
    """
    # get user organization
    organization = request.user.organization
    # query for new comments since last_login from any discussions the user has participated in
    recent_comments = User.recent_comments(request.user)
    # if no new comments, display 10 most recent older comments
    older_comments = User.inbox_comments(request.user)[:10]

    if organization:
        # retrieve all organization comments
        all_comments = Organization.get_org_comments(organization)
        # query for new stories shared to network
        networks = Organization.get_org_networks(organization)
        # facets where run_date=today
        running_today = Organization.get_org_stories_running_today(organization)
        # facets where due_edit=today
        edit_today = Organization.get_org_stories_due_for_edit_today(organization)
    else:
        all_comments = []
        networks = []
        running_today = []
        edit_today = []

    shared_networkstories = []
    for network in networks:
        stories = Network.get_network_shared_stories(network)
        shared_networkstories.extend(stories)
    shared_networkstories = [story for story in shared_networkstories if story.organization != organization]
    networkstories = set(shared_networkstories)

    # query for any new content created since last_login
    new_stories = Story.objects.filter(creation_date__gte=request.user.last_login)[:8]
    # if no new stories, display 10 most recent stories
    old_stories = Story.objects.filter(organization = request.user.organization)[:10]

    copied_shared_stories = StoryCopyDetail.objects.filter(original_org=request.user.organization)
    # TODO: query for other user activity since last_login

    return render(request, 'editorial/dashboard.html', {
        'networks': networks,
        'recent_comments': recent_comments,
        'older_comments': older_comments,
        'all_comments': all_comments,
        'new_stories': new_stories,
        'old_stories': old_stories,
        'running_today': running_today,
        'edit_today': edit_today,
        'shared_networkstories': shared_networkstories,
        'copied_shared_stories': copied_shared_stories,
    })
Beispiel #2
0
def story_edit(request, pk):
    """ Edit story page. """

    organization = request.user.organization
    org_partners = Organization.get_org_networks(organization)

    story = get_object_or_404(Story, pk=pk)

    if request.method == "POST":
        storyform = StoryForm(data=request.POST, instance=story, request=request)
        if storyform.is_valid():
            storyform.save()

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

            return redirect('story_detail', pk=story.id)
    else:
        storyform = StoryForm(instance=story, request=request)

    return render(request, 'editorial/storyedit.html', {
        'story': story,
        'storyform': storyform,
        'org_partners': org_partners,
    })
Beispiel #3
0
def network_list(request):
    """ Table of networks your org is member of."""

    organization = request.user.organization
    network_list = Organization.get_org_networks(organization)

    return render(request, 'editorial/networklist.html', {'network_list': network_list})
Beispiel #4
0
    def get_queryset(self):
        """Return network stories."""

        organization = self.request.user.organization
        networks = Organization.get_org_networks(organization)

        shared_networkstories = []
        for network in networks:
            stories = network.get_network_shared_stories()
            shared_networkstories.extend(stories)
        shared_networkstories = [
            story for story in shared_networkstories
            if story.organization != organization
        ]
        networkstories = set(shared_networkstories)

        # get list of stories an organization has copied
        org_copied_content = organization.get_org_copied_content()

        # temp attribute showing whether the user org has already copied a story
        for story in networkstories:
            if story in org_copied_content:
                story.already_picked_up = True
            else:
                story.already_picked_up = False

        return networkstories
Beispiel #5
0
def network_stories(request):
    """ Displays a filterable table of stories marked as shared/ready to share by any
    organizations that a user's organization is a part of.

    Initial display organizes content by story>facet>est. run date
    Filterable by story name, facet type, facet name, due for edit, est. run date, credit,
    editor, status.

    Stories marked as share appear but are greyed out/inaccessible until the owner marks
    them as Ready to Share. (This is so partners know it will exist and can plan to incorporate
    it once it becomes available.)
    """

    org_id = request.user.organization_id
    organization = get_object_or_404(Organization, id=org_id)

    networks = Organization.get_org_networks(organization)

    shared_networkstories = []
    for network in networks:
        stories = Network.get_network_shared_stories(network)
        shared_networkstories.extend(stories)

    networkstories = set(shared_networkstories)

    return render(request, 'editorial/networkstories.html', {
        'networkstories': networkstories,
        })
Beispiel #6
0
def story_new(request):
    """ Create story page. """

    organization = request.user.organization
    org_partners = Organization.get_org_networks(organization)

    series = Series.objects.all()
    if request.method == "POST":
        storyform = StoryForm(request.POST, request=request)
        #import pdb; pdb.set_trace()
        if storyform.is_valid():
            story = storyform.save(commit=False)
            story.owner = request.user
            story.organization = request.user.organization
            discussion = Discussion.objects.create_discussion("STO")
            story.discussion = discussion
            story.save()
            storyform.save_m2m()

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

            return redirect('story_detail', pk=story.pk)
    else:
        storyform = StoryForm(request=request)
    return render(request, 'editorial/storynew.html', {
        'storyform': storyform,
        'series': series,
        'org_partners': org_partners,
        })
Beispiel #7
0
def org_detail(request, pk):
    """ The public profile of an organization.

    Visible to users/organizations in the same networks.
    Displays the organization's name, logo, description, team members, most recent
    shared content, admin email addresses.
    """

    organization = get_object_or_404(Organization, pk=pk)
    organizationnoteform = OrganizationNoteForm()
    organizationnotes = OrganizationNote.objects.filter(organization=organization)[:5]
    users = Organization.get_org_users(organization)
    organizationcomments = Comment.objects.filter(discussion=organization.discussion).order_by("-date")
    organizationcommentform = OrganizationCommentForm()

    return render(
        request,
        "editorial/organizationdetail.html",
        {
            "organization": organization,
            "organizationnoteform": organizationnoteform,
            "organizationnotes": organizationnotes,
            "organizationcomments": organizationcomments,
            "organizationcommentform": organizationcommentform,
        },
    )
Beispiel #8
0
def collaborations(request):
    """ Return dashboard of series and stories that are part of a collaboration.
    """

    series_collaborations = Series.objects.filter(collaborate=True)
    story_collaborations = Organization.get_org_collaborative_content(request.user.organization)

    return render(request, 'editorial/collaborations.html', {
        'series_collaborations': series_collaborations,
        'story_collaborations': story_collaborations,
    })
Beispiel #9
0
def comments_html(request, comment_type):
    """Return comment feeds."""

    print "comment type: ", comment_type
    # returns all comments involving any user of an Organization
    all_comments = Organization.get_org_user_comments(request.user.organization)

    if comment_type=="organization":
    # returns all comments made for an Organization
        comments = Organization.get_org_comments(request.user.organization)
    elif comment_type=="network":
    # returns all comments for any networks an Organization is part of
        comments = Organization.get_network_comments(request.user.organization)
    elif comment_type=="story":
    # returns all comments for any story of an Organization
        comments = Organization.get_story_comments(request.user.organization)
    elif comment_type=="series":
    # returns all comments for any series of an Organization
        comments = Organization.get_series_comments(request.user.organization)
    elif comment_type=="facet":
    # returns all comments for any facets of stories of an Organization
        comments = Organization.get_facet_comments(request.user.organization)

    comments_html = render_to_string('inbox-comments.html', {
                            'comments': comments,
                            'comment_type': comment_type,
    })

    return HttpResponse(comments_html)
Beispiel #10
0
def team_list(request):
    """ Return teams list.

    Displays team members from the user's own organization.
    Displays team members from any network that the user's organization is part of.
    """

    # the user's organization
    organization = request.user.organization
    networks = Organization.get_org_networks(organization)
    partners = Organization.get_org_collaborators(organization)

    # form for adding a new user to the team
    adduserform = AddUserForm()
    # only visible for admin users

    return render(request, 'editorial/team.html', {
        'organization': organization,
        'networks': networks,
        'partners': partners,
        'adduserform': adduserform,
        })
Beispiel #11
0
def include_logged_in_users(request):
    if request.user.is_authenticated():
        active_sessions = Session.objects.filter(expire_date__gte=timezone.now())
        user_id_list = []
        for session in active_sessions:
            data = session.get_decoded()
            user_id_list.append(data.get('_auth_user_id', None))
        # Query all logged in users based on id list
        current_users = User.objects.filter(id__in=user_id_list)
        if request.user.organization:
            org_users = Organization.get_org_users(request.user.organization)
        else:
            org_users = []
        return {'org_users': org_users,
                'current_users': current_users}
    else: return {}
Beispiel #12
0
def org_edit(request, pk):
    """ Edit organization page."""

    organization = get_object_or_404(Organization, pk=pk)
    team_members = Organization.get_org_users(organization)

    if request.method == "POST":
        orgform = OrganizationForm(request.POST, request.FILES, instance=organization)
        if orgform.is_valid():
            orgform.save()
            return redirect('org_detail', pk=organization.id)
    else:
        orgform = OrganizationForm(instance=organization)

    return render(request, 'editorial/organizationedit.html', {
            'organization': organization,
            'orgform': orgform,
            'team': team_members,
    })
Beispiel #13
0
    def get_queryset(self):
        """Returns list of querysets containing content a user is allowed to search.

        This is determined by a user's organization.
        """

        user_org = self.request.user.organization
        user = self.request.user

        # retrieve all content a user is allowed to search
        searchable_org_objects = Organization.get_org_searchable_content(user_org)
        searchable_user_objects = User.get_user_searchable_content(user)

        # unpack the querysets from the list of querysets returned
        series, stories, webfacets, printfacets, audiofacets, videofacets, imageassets, networknotes, orgnotes, seriesnotes, storynotes = (
            searchable_org_objects
        )
        usernotes = searchable_user_objects

        # pass all querysets to search method
        return watson.search(
            self.query,
            models=[
                series,
                stories,
                webfacets,
                printfacets,
                audiofacets,
                videofacets,
                imageassets,
                networknotes,
                orgnotes,
                seriesnotes,
                storynotes,
                usernotes,
            ],
        )
Beispiel #14
0
 def __init__(self, *args, **kwargs):
     self.request = kwargs.pop("request")
     super(AddAudioForm, self).__init__(*args, **kwargs)
     self.fields["audio"].queryset = Organization.get_org_audio_library(self.request.user.organization)
Beispiel #15
0
 def __init__(self, *args, **kwargs):
     self.request = kwargs.pop("request")
     super(AddImageForm, self).__init__(*args, **kwargs)
     self.fields['images'].queryset = Organization.get_org_image_library(self.request.user.organization)
Beispiel #16
0
 def __init__(self, *args, **kwargs):
     self.request = kwargs.pop("request")
     super(StoryForm, self).__init__(*args, **kwargs)
     self.fields['collaborate_with'].queryset = Organization.get_org_collaborators(self.request.user.organization)
     self.fields['team'].queryset = Organization.get_org_users(self.request.user.organization)
Beispiel #17
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,
        })
def include_logged_in_users(request):
    if request.user.is_authenticated():
        org_users = Organization.get_org_users(request.user.organization)
        return {'org_users': org_users}
    else: return {}
Beispiel #19
0
 def __init__(self, *args, **kwargs):
     self.request = kwargs.pop("request")
     super(AddVideoForm, self).__init__(*args, **kwargs)
     self.fields["documents"].queryset = Organization.get_org_video_library(self.request.user.organization)
Beispiel #20
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,
        })