@user_passes_test(lambda u: u.is_staff)
def schedule(request, id):
    """
    Schedule an article for publishing in the future.
    """
    article = get_object_or_404(Article, ~Q(status=Article.PUBLISHED), pk=id)
    try:
        scheduled_article = article.scheduledarticle
    except ScheduledArticle.DoesNotExist:
        scheduled_article = None
    if request.method == 'POST':
        form = ScheduledArticleForm(instance=scheduled_article, data=request.POST)
        if form.is_valid():
            scheduled_article = form.save(commit=False)
            scheduled_article.article = article
            scheduled_article.save()
            messages.info(request, "The article has been scheduled for publishing.")
            return redirect(article)
    else:
        form = ScheduledArticleForm(instance=scheduled_article)
    return render(request, 'form.html', {
        'title': 'Schedule "%s"' % article,
        'parent': {
            'title': article,
            'url': article.get_absolute_url(),
        },
        'description': "Select a date and time to publish the article.",
        'form': form,
        'action': 'Schedule',
    })
dataset/ETHPy150Open 2buntu/2buntu-blog/twobuntu/articles/views.py/schedule/original