Beispiel #1
0
def view_posts_draft(request):
    """
    Displays a list of ideas, the form to add / update ideas, and writing posts
    """
    idea = None
    idea_id = request.GET.get('idea_id', 0)

    if idea_id:
        idea = get_object_or_404(Idea, pk=idea_id)

    if request.method == 'POST':
        form = IdeaForm(request.POST, instance=idea, request=request)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('posts_draft'))
    else:
        form = IdeaForm(instance=idea)

    ideas_list = Idea.objects.select_related().filter(status=1) \
        .order_by('-rating_ratio')

    news_list = News.objects.filter(status=1) \
                    .order_by('-updated_at', '-created_at') \
                    .select_related('category', 'last_version', 'created_by', \
                                    'updated_by', 'last_version__author') \
                    .prefetch_related('versions', 'versions__author')

    last_revisions = Version.objects.select_related().filter(news__status=1) \
        .order_by('-created_at')[:10]

    last_comments = ThreadedComment.objects.filter(object_pk__in=news_list) \
        .select_related().order_by('-created_at')[:10]

    return render(request, 'posts_draft.html', {
        'ideas_list': ideas_list, 'news_list': news_list,
        'last_revisions': last_revisions, 'form': form, 'idea_id': idea_id
    })
Beispiel #2
0
def idea_submit(request):
    if request.method == "POST":
        if request.POST.has_key("part1"):
                idea_form = IdeaForm(initial={'description': request.POST['description']})
        else:
            idea_form = IdeaForm(request.POST)
            if idea_form.is_valid():
                title = idea_form.cleaned_data["title"]
                description = idea_form.cleaned_data["description"]
                tags = idea_form.cleaned_data["tags"]
                saveObj = idea_form.save(commit=False)
                saveObj.author = request.user
                saveObj.save()
                return HttpResponseRedirect("/")
    else:
        idea_form = IdeaForm()
    return render_to_response('idea/idea_submit.html', locals(), context_instance=RequestContext(request))