コード例 #1
0
ファイル: views.py プロジェクト: dsantelmo/ohdei
def adder(request, adder_text):
    logger = logging.getLogger('ohdei.adder.views.adder')
    #if GET or only whitespace
    form = _check_get(request, adder_text)
    if form is not None:
        logger.debug("/add/ URL was called on GET or it's only whitespace")
        return  render_to_response('adder.html', {'form':form}, context_instance=RequestContext(request))
    # request is POST and more than just whitespace
    form = AdderForm(request.POST)
    if form.is_valid():
        adder_b58id = _save_adder(form.cleaned_data['a'])
        logger.debug("redirecting to /added/%s" % adder_b58id)
        return HttpResponseRedirect("/added/%s" % adder_b58id)
    else:
        logger.debug("/add/ URL was called with an invalid form")
        return render_to_response('adder.html', {'form':form}, context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: dsantelmo/ohdei
def _check_get(request, adder_text):
    logger = logging.getLogger('ohdei.adder.views._check_get')
    if request.method == 'GET':
        req = request.GET.copy()
        req['a'] = adder_text
        form = AdderForm(req)
        logger.debug("GET with: %s" % adder_text)
        return form
    else:
        form = AdderForm(request.POST)
    if form.is_valid():
        if not remove_whitespace(form.cleaned_data['a']):
            logger.debug("only whitespace: %s" % form.cleaned_data['a'])
            return AdderForm()
    else:
        logger.debug("invalid form")
        return AdderForm()
    return None