@login_required()
def suggest(request):
    error_message = None
    env = common_env()

    if request.method == 'POST':
        form = SuggestCharityForm(request.POST)
        if form.is_valid():
            try:
                charity = Charity(
                        name=form.cleaned_data['name'],
                        url=form.cleaned_data['url'],
                        description=form.cleaned_data['description'],
                        suggester=request.user,
                        status=STATUS.PENDING)
                charity.save()
            except IntegrityError:
                error_message = \
                        "That charity has already been suggested, thanks."
            else:
                return render(request, 'charities/suggest_done.html', env)
    else:
        form = SuggestCharityForm()

    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'charities/suggest.html', env)
dataset/ETHPy150Open mpirnat/hackday/hackday/charities/views.py/suggest/original