def seed(request, key): """ Provide a form to seed, or populate, the libs for a specific spam email. The email message is specified by *key*. If the specified email cannot be found, this raises a 404 error. :param HttpRequest request: A web request. :param string key: The identifier for a specific email. :rtype: An HttpResponse object. """ try: email = Email.get(key) except BadKeyError: raise Http404 email.views += 1 email.put() if request.method == 'GET': libs = Lib.all().filter('email =', email).order('position') ctx = RequestContext(request, { 'title': email.title, 'key': key, 'libs': libs }) return render_to_response('seed_fields.html', context_instance=ctx) ls = [] for l in request.POST.items(): ls.append(( l[0], l[1], Lib.get(l[0]), )) ls.sort(cmp=lambda x, y: cmp(x[2].position, y[2].position)) newbody = '' bodyidx = 0 for l in ls: newbody += email.body[bodyidx:l[2].position] bodyidx = l[2].position newbody += l[1] bodyidx += len(l[2].original) newbody += email.body[bodyidx:] ctx = RequestContext( request, { 'key': key, 'title': email.title, 'body': newbody, 'is_processed': True, 'views': email.views }) return render_to_response('output_raw.html', context_instance=ctx)
def seed(request, key): """ Provide a form to seed, or populate, the libs for a specific spam email. The email message is specified by *key*. If the specified email cannot be found, this raises a 404 error. :param HttpRequest request: A web request. :param string key: The identifier for a specific email. :rtype: An HttpResponse object. """ try: email = Email.get(key) except BadKeyError: raise Http404 email.views += 1 email.put() if request.method == 'GET': libs = Lib.all().filter('email =', email).order('position') ctx = RequestContext(request, { 'title':email.title, 'key':key, 'libs':libs }) return render_to_response('seed_fields.html', context_instance=ctx) ls = [] for l in request.POST.items(): ls.append( (l[0], l[1], Lib.get(l[0]),) ) ls.sort(cmp=lambda x,y: cmp(x[2].position, y[2].position)) newbody = '' bodyidx = 0 for l in ls: newbody += email.body[bodyidx:l[2].position] bodyidx = l[2].position newbody += l[1] bodyidx += len(l[2].original) newbody += email.body[bodyidx:] ctx = RequestContext(request, { 'key':key, 'title':email.title, 'body':newbody, 'is_processed':True, 'views':email.views }) return render_to_response('output_raw.html', context_instance=ctx)