Ejemplo n.º 1
0
def edit_media(request, slug):
    """
    Update existing article
    Command for sending articles comes from management.py
    """
    article = get_object_or_404(MediaItem, slug=slug)
    if request.method == 'POST':
        if request.user.get_profile().user_type == 'Reporter':
            form = Media_RForm(request.POST, request.FILES, instance=article)
            form.publish_date = datetime.datetime.now()
        elif request.user.get_profile().user_type == 'Editor':
            form = Media_EForm(request.POST, request.FILES, instance=article)
        else:
            form = Media_RForm(request.POST, request.FILES, instance=article)
        if form.is_valid():
            cleaned_text = replace_all(article.text)
            article.text = cleaned_text
            article = form.save()
            msg = "Media updated successfully"
            messages.success(request, msg, fail_silently=True)
            if request.user.get_profile().user_type == 'Editor':
                if article.is_published and article.send_now:
                    send_article(article, form)
                    msg = "Media published successfully"
                    messages.success(request, msg, fail_silently=True)
            elif request.user.get_profile().user_type == 'Reporter':
                ready_for_editor = form.cleaned_data['ready_for_editor']
                if ready_for_editor:
                    notify_editor(article)
                    msg = "Editor has been notified."
                    messages.success(request, msg, fail_silently=True)
            return redirect(article)
    else:
        if request.user.get_profile().user_type == 'Reporter':
            form = Media_RForm(instance=article, initial={'byline': article.author.get_profile().byline})
        elif request.user.get_profile().user_type == 'Editor':
            if article.email_text:
                form = Media_EForm(instance=article, initial={'email_text': article.email_text})
                form.fields['author'].queryset = UserProfile.objects.filter(Q(user_type = 'Reporter') | Q(user_type = 'Editor'))
            else:
                form = Media_EForm(instance=article,
                    initial={'byline': article.author.get_profile().byline,
                             'email_text': '<p>Editors/News Directors:</p><p></p><p>Thank you,</p><p>Nebraska News Service</p>'})
        else:
            form = Media_RForm()
    return render_to_response('story/media_form.html', 
                              { 
                                  'form': form,
                                  'article': article,
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def add_media(request):
    """
    Command for sending articles comes from management.py

    """
    if request.method == 'POST':
        if request.user.get_profile().user_type == 'Reporter':
            form = Media_RForm(request.POST, request.FILES or None)
            form.author = request.user
            form.publish_date = datetime.datetime.now()
        elif request.user.get_profile().user_type == 'Editor':
            form = Media_EForm(request.POST, request.FILES or None)
        else:
            form = Media_RForm()
        if form.is_valid():
            article = form.save(commit=False)
            article.author = request.user
            if article.is_published:
                article.publish_date = datetime.datetime.now()
            cleaned_text = replace_all(article.text)
            article.text = cleaned_text
            article.save()
            form.save_m2m()
            msg = "Media saved successfully" 
            messages.success(request, msg, fail_silently=True)
            if request.user.get_profile().user_type == 'Editor':
                if article.is_published and article.send_now:
                    send_article(article, form)
                    msg = "Media published successfully"
                    messages.success(request, msg, fail_silently=True)
            elif request.user.get_profile().user_type == 'Reporter':
                ready_for_editor = form.cleaned_data['ready_for_editor']
                if ready_for_editor:
                    notify_editor(article)
                    msg = "Editor has been notified."
                    messages.success(request, msg, fail_silently=True)
            return redirect(article)
    else:
        if request.user.get_profile().user_type == 'Reporter':
            form = Media_RForm(initial={'byline': request.user.get_profile().byline})
        elif request.user.get_profile().user_type == 'Editor':
            form = Media_EForm(initial={'byline': request.user.get_profile().byline,
                         'email_text': '<p>Editors/News Directors:</p><p></p><p>Thank you,</p><p>Nebraska News Service</p>'})
        else:
            form = Media_RForm()
    return render_to_response('story/media_form.html', 
                              { 'form': form },
                              context_instance=RequestContext(request))