Esempio n. 1
0
def get_counts(request):
    counts = memcache.get('api_get_count')
    if not counts:
        coming_soon = Gift.accept_filters(filters=['coming_soon']).count()
        on_sale = Gift.accept_filters(filters=['on_sale']).count()
        no_sale = Gift.accept_filters(filters=['no_sale']).count()
        total = coming_soon + on_sale + no_sale
        if total:
            counts = {
                'coming_soon': coming_soon,
                'on_sale': on_sale,
                'no_sale': no_sale,
                'total': total}
        if counts:
            memcache.set('api_get_count', counts, 7200)
    return render_json_response(counts)
Esempio n. 2
0
def get_coming_soon_list(request):
    list_gifts = memcache.get('api_get_coming_soon_list')
    if not list_gifts:
        gifts = Gift.accept_filters(filters=['coming_soon'])
        if gifts:
            list_gifts = [gift.uid for gift in gifts]
            memcache.add('api_get_coming_soon_list', list_gifts, 7200)
    return render_json_response(list_gifts)
Esempio n. 3
0
def internal_delete_gifts_json_1c(request, task_id):
    id_1c = memcache.get(task_id)
    memcache.delete(task_id)
    if id_1c:
        gifts_obj = Gift.accept_filters().filter('id_1c =', id_1c)
        if gifts_obj.count():
            gift = gifts_obj[0]
            gift.delete()
    return render_to_response('empty.html')
Esempio n. 4
0
def internal_delete_gifts_json(request, task_id):
    name = memcache.get(task_id)
    memcache.delete(task_id)
    if name:
        gifts_obj = Gift.accept_filters().filter('name =', name)
        if gifts_obj.count():
            gift = gifts_obj[0]
            gift.delete()
    return render_to_response('empty.html')
Esempio n. 5
0
def sitemap(request):
    gift_urls = memcache.get(SITEMAP_MEMCACHE_NAME)
    if not gift_urls:
        gifts = Gift.accept_filters()
        gift_urls = [
        {'uid': g.uid,
        'lastmod': '%s' \
        % (g.modif_time.date())}\
        for g in gifts]
        memcache.add(SITEMAP_MEMCACHE_NAME, gift_urls, SITEMAP_MEMCACHE_LIVE)
    return render_to_response('sitemaps/sitemap.xml', {'gift_urls': gift_urls})
Esempio n. 6
0
def get_changed_gifts_from_date(request):
    date = request.values.get('from_date', None)
    if date is None:
        return redirect('/api/')
    try:
        date_t = datetime.strptime(date, '%Y-%m-%d')
    except ValueError:
        return redirect('/api/')
    memcache_name = 'api_get_changed_gifts_from_date_%s' % date
    list_gifts = memcache.get(memcache_name)
    if not list_gifts:
        gifts = Gift.accept_filters().filter('modif_time >', date_t)
        if gifts:
            list_gifts = [gift.uid for gift in gifts]
            memcache.add(memcache_name, list_gifts, 7200)
    return render_json_response(list_gifts)
Esempio n. 7
0
def get_new_gifts_between_dates(request):
    date1 = request.values.get("from_date", None)
    date2 = request.values.get('to_date', None)
    if date1 is None or date2 is None:
        return redirect('/api/')
    try:
        date_t1 = datetime.strptime(date1, '%Y-%m-%d')
        date_t2 = datetime.strptime(date2, '%Y-%m-%d')
    except ValueError:
        return redirect('/api/')
    memcache_name = 'api_get_new_gifts_between_dates_%s_%s' % (date1, date2)
    list_gifts = memcache.get(memcache_name)
    if not list_gifts:
        gifts = Gift.accept_filters().filter('add_time >=', date_t1)\
            .filter('add_time <=', date_t2)
        if gifts:
            list_gifts = [gift.uid for gift in gifts]
            memcache.add(memcache_name, list, 7200)
    return render_json_response(list_gifts)