Exemple #1
0
def add_post(request, space_name):

    """
    Create a new post. Only registered users belonging to a concrete group
    are allowed to create news. nly site administrators will be able to
    post news in the index page.
    """
    current_space = get_object_or_404(Space, url=space_name)
    form = NewsForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            form_uncommited = form.save(commit=False)
            form_uncommited.author = request.user

            # Get space id
            place = Space.objects.get(url=space_name)
            form_uncommited.space = place

            # This should not be necessay since the editor filters the
            # script tags
            #if "<script>" in form_uncommited.post_message:
            #    return "SCRIPT TAGS ARE NOT ALLOWED"
        
            form_uncommited.save()
            return redirect('/spaces/' + space_name)

    return render_to_response('news/post_add.html',
                              {'form': form, 'get_place': current_space},
                              context_instance = RequestContext(request))
Exemple #2
0
def add_news(request):

    """
    This is a DRY violation. This is a reimplementation of the news view
    located at apps.news.views
    """
    form = NewsForm(request.POST or None)

    if request.method == 'POST':
        form_uncommited = form.save(commit=False)
        form_uncommited.author = request.user
        form_uncommited.pub_index = True

        if form.is_valid():
            form_uncommited.save()
            messages.success(request, _('Post added successfully.'))
            return redirect('/')

    return render_to_response('news/post_add.html',
                              {'form': form},
                              context_instance=RequestContext(request))