def _load_latest_price(self):
        from pretweeting.apps.batches.models import Batch, Count
        from pretweeting.apps.batches.price import get_price
        latest_batch = Batch.objects.latest()

        try:
            count = latest_batch.count_set.get(word=self)
            price = get_price(count, latest_batch)
        except Count.DoesNotExist:
            count = Count(word=self, batch=latest_batch, number=0)
            price = get_price(count, latest_batch)

        self._latest_price = price
        self._latest_count = count.number
Beispiel #2
0
def list_words(request, page_num=1):
    batch = Batch.objects.latest()
    counts = batch.count_set.order_by("-number").filter(number__gte=consts.MIN_NUMBER_TO_SHOW).select_related("word")

    paginator = Paginator(counts, WORDS_PER_PAGE)
    page_num = int(page_num)
    try:
        page = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_num = paginator.num_pages
        page = paginator.page(page_num)

    prev_pages, next_pages, show_first, show_last = pagination_help(page_num, paginator, LIST_PAGE_RANGE)

    word_prices = [(count.word, get_price(count, batch)) for count in page.object_list]

    return render_to_response(
        "game/words/list.html",
        {
            "show_first": show_first,
            "show_last": show_last,
            "prev_pages": prev_pages,
            "next_pages": next_pages,
            "page": page,
            "page_subpath": "page",
            "word_prices": word_prices,
        },
        context_instance=RequestContext(request),
    )
Beispiel #3
0
def get_interesting_words_and_prices():
    latest_batch = Batch.objects.latest()
    key = 'batch_interesting_words_%d' % latest_batch.id
    words_and_prices = cache.get(key)
    if words_and_prices is None:   
        counts = (latest_batch.count_set.order_by('-number')
                .select_related('word'))[280:700]
        words_and_prices = [(count.word, get_price(count, latest_batch))
                for count in counts]
        cache.set(key, words_and_prices, 60 * 60 * 24)
    return words_and_prices