def process_exception(self, request, exception): if isinstance(exception, AbortException): r = HttpResponse(exception.message) r.status_code = exception.code r.code = set_code(exception.code) return r
def json_response(data, code=200, mimetype='application/json'): """ For ajax(json) response, wrapper json data to convert HttpResponse. """ resp = HttpResponse(data, mimetype) resp.code = code return resp
def result(request): context = {} context['logged'] = True context['first_name'] = request.user.first_name context['last_name'] = request.user.last_name if request.method == 'POST': form = GeneForm(request.POST) if form.is_valid(): genes = separe_genes(form.cleaned_data['gene']) found = False results = [] soma = 0.0 for gene in genes: data = RefGene.objects.filter(gene__iexact = gene) info = {} if data.exists(): found = True info = data[0].context() counter_base = 0 counter_exon = 0 for d in data: counter_base += d.length_base() counter_exon += 1 info['totalExons'] = counter_exon info['totalBases'] = counter_base custo = calcular_custo(data) info['valorCusto'] = 'R$ ' + str(custo) info['found'] = True soma += custo else: info['gene'] = gene info['found'] = False results.append(info) context['results'] = results context['found'] = found context['total'] = 'R$ ' + str(soma) return render(request, 'result.html',context) else: resp = HttpResponse(form.errors) resp.code = 409 return resp else: return redirect('/search')
def add_blacklist(request): """ This method is for API that sets tco_url or screen_name to BlackList. Here is usage: When you want to report the photo that has url "http://t.co/hogehoge" You need to set the URL starts with http://t.co. http://sakura.playshiritori.com/api/ add_blacklist?tco_url=http://t.co/hogehoge When you want to report the user that has name keiko713 http://sakura.playshiritori.com/api/ add_blacklist?screen_name=keiko713 if you receive following, your report was succeed: "[Success] Your request is confirmed. Thank you for your help!" """ message = None if request.method == 'GET': url = request.GET.get('tco_url', '') name = request.GET.get('screen_name', '') if not url and not name: message = '[Error: Invalid Request Parameters]' \ + ' Please put the param either url or screen_name' else: if url and not url.startswith('http://t.co/'): message = '[Error: Invalid Request Parameters]' \ + ' Please put http://t.co/ URL for the url parameter' else: if not is_blacklist_url(url) or not is_blacklist_name(name): black_list = BlackList(tco_url=url, screen_name=name) black_list.save() message = '[Success] Your request is confirmed.' \ + ' Thank you for your help!' resp = HttpResponse(message, 'text/plain') resp.code = 200 return resp
def json_response(data, code=200, mimetype="application/json"): resp = HttpResponse(data, mimetype) resp.code = code return resp
def json_response(content, code=200): resp = HttpResponse(json.dumps(content), mimetype='application/json') resp.code = code return resp