def check_for_new_quotes(request): try : totalQuotes = request.GET['totalQuotes'] totalQuotes = int(totalQuotes) except: return HttpResponseBadRequest() quotes_count = QuoteRepository.all()[totalQuotes : totalQuotes + 10].count() return HttpResponse(quotes_count, mimetype='application/text')
def quotes(request): quotes = QuoteRepository.all()[:20] for quote in quotes: if len(quote.owner_name) > 30: quote.owner_name = ' '.join(quote.owner_name.split(' ')[:2]) + ' ...' quote.content = quote.content[:60 - len(quote.owner_name)] images_count = MemoryRepository.all().count() data = { 'all_quotes': quotes, 'images_count' : images_count, 'expected_number': 20, } return render_to_response("mainapp/main_pages/quotes.html", data, context_instance=RequestContext(request))
def get_new_quotes(request): try : totalQuotes = request.GET['totalQuotes'] totalQuotes = int(totalQuotes) except: return HttpResponseBadRequest() quotes = QuoteRepository.all()[totalQuotes : totalQuotes + 10] dict_to_be_dumped = {} i = 0 for quote in quotes: if len(quote.owner_name) > 30: quote.owner_name = ' '.join(quote.owner_name.split(' ')[:2]) + ' ...' dict_to_be_dumped['%s_content' % i] = quote.content[:60 - len(quote.owner_name)] dict_to_be_dumped['%s_owner_name' % i] = quote.owner_name dict_to_be_dumped['%s_id' % i] = quote.id #dict_to_be_dumped['%s_owner_image' % i] = quote.owner_image.url #dict_to_be_dumped['%s_related_image' % i] = quote.quote_related_image.url i+=1 return HttpResponse(simplejson.dumps(dict_to_be_dumped), mimetype='application/json')