예제 #1
0
파일: views.py 프로젝트: marrog/wste
def add_news(request):
    user_group = check_user_group(request)
    warning = "Nie masz uprawnień do dodawania wiadomości"
    if not request.user.is_authenticated() or user_group not in ('instruktor', 'pracownik dziekanatu',):
        return render_to_response('archiwum/message.html', {'warning' : warning, 'user_group' : user_group,}, context_instance = RequestContext(request))
    if request.method == "POST":
        form = NewsForm(data=request.POST)
        if form.is_valid():
            form.save(author=request.user)
            return HttpResponseRedirect('/')
    else:
        form = NewsForm()
    return render_to_response('archiwum/add_news.html', {'form': form, 'user_group': user_group,}, context_instance = RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: marrog/wste
def edit_news(request, news_id):
    user_group = check_user_group(request)
    form = NewsForm(instance=News.objects.get(id=news_id))
    if request.method == "POST":
        form = NewsForm(request.POST, instance=News.objects.get(id=news_id))
        if form.is_valid():
            if request.POST.get('cancel'):
               return HttpResponseRedirect('/')
            elif request.POST.get('delete'):
                news = News.objects.get(id=news_id)
                news.delete()
                return HttpResponseRedirect('/')
            else:
                form.save(author=request.user)
            return HttpResponseRedirect('/')
        else:
            return render_to_response('archiwum/edit_news.html', {'form':form, 'user_group':user_group,}, context_instance = RequestContext(request))
    else:
        form = NewsForm(instance=News.objects.get(id=news_id))
        return render_to_response('archiwum/edit_news.html', {'form':form, 'user_group':user_group,}, context_instance = RequestContext(request))