Beispiel #1
0
def edit_news(request, news_id):
    """
    view untuk mengedit berita
    """
    news = get_object_or_404(News, id=news_id, user=request.user, active=True)
    if request.POST:
        form = CreateNewsForm(request.POST, instance=news)
        if form.is_valid():
            news.user = request.user
            news.title = form.cleaned_data['title']
            news.content = form.cleaned_data['content']
            news.category = form.cleaned_data['category']
            news.enable_comment = form.cleaned_data['enable_comment']
            news.location = form.cleaned_data['location']
            news.save()
            news.images.clear()
            news.images.add(*request.POST.getlist('images'))
            messages.info(request, _('News "%s" updated') % news.title)
            return HttpResponseRedirect(reverse('user_news'))
    else:
        form = CreateNewsForm(instance=news)
    return render_to_response('news/edit_news.html',
            {'form': form,
                'news': news},
            context_instance=RequestContext(request))
Beispiel #2
0
def create_news(request):
    """
    view untuk pembuatan berita
    """
    if not request.user.has_perm('news.add_news'):
        messages.error(request, _("Unvalidated user can not create news"))
        return HttpResponseRedirect(reverse('validate'))
    if request.POST:
        form = CreateNewsForm(request.POST)
        if form.is_valid():
            news = News()
            news.user = request.user
            news.title = form.cleaned_data['title']
            news.content = form.cleaned_data['content']
            news.category = form.cleaned_data['category']
            news.enable_comment = form.cleaned_data['enable_comment']
            news.location = form.cleaned_data['location']
            news.save()
            news.images.add(*request.POST.getlist('images'))
            p = Point(news=news, user=request.user)
            p.save()
            messages.info(request, _('A news %s created') % news.title)
            return HttpResponseRedirect(reverse('user_news'))
    else:
        form = CreateNewsForm()
    return render_to_response('news/create_news.html',
            {'form': form},
            context_instance=RequestContext(request))