Beispiel #1
0
def oups(request):
    from project.rent.models import MemberRentalPlan
    ctx = {
        'CATALOG_CATEGORIES': Category.list_names(),
        'SITE_URL': 'http://%s' % Site.objects.get_current().domain,
        'STATIC_URL': settings.STATIC_URL,
    }

#    plan = MemberRentalPlan.get_current_plan(request.user)
    plan = MemberRentalPlan.objects.all()[0]

    from project.utils.mailer import mail
    mail('*****@*****.**', 'emails/rent_emails/plan_subscription_successfull.html', {
        'user': plan.user,
        'plan': plan,
        'new_releases': Item.list_new_releases(6),
        'coming_soon': Item.list_all()[:6],
    }, subject="TEST EMAIL!")

    return render_to_response('emails/rent_emails/plan_subscription_successfull.html', {
        'user': plan.user,
        'plan': plan,
        'new_releases': Item.list_new_releases(6),
        'coming_soon': Item.list_all()[:6],
    }, Context(ctx))
Beispiel #2
0
def check_in(request, **kwargs):
    if request.method == 'POST':
        form = InventoryCheckInForm(request.POST)
        if form.is_valid():
            purchase = form.cleaned_data['purchase']
            quantity = form.cleaned_data['quantity']
            is_new = form.cleaned_data['condition'] == 'True'
            buy_only = form.cleaned_data.get('buy_only', False)
            
            for _q in range(quantity):
                inventory = Inventory()
                inventory.dropship = form.cleaned_data['dc']
                inventory.item = form.cleaned_data['upc']
                inventory.purchase_item = form.cleaned_data['purchase_item']
                inventory.buy_only = buy_only
                inventory.fill_barcode() 
                inventory.is_new = purchase.is_new if purchase else is_new
                inventory.save()

            return redirect('staff:page', 'Inventory/Check-In'), None
        item = Item.find_by_upc(form['upc'].data)
    else:
        form = InventoryCheckInForm()
        item = None
    
    return {
        'title': 'Check-In',
        'form': form,
        'item': item,
    }, None
Beispiel #3
0
def buy_intro(request):
    qs = Item.list_all()
    date_x = datetime.now() - timedelta(30)
    filter = Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x) & Q(sold_amount__gt=0)
    qs = qs.filter(filter).order_by('-sold_amount', 'id')
    return {
        'new_releases': qs[:20],
        'slim_banner': get_slim_banner(request),
    }
Beispiel #4
0
def trade_intro(request):
    qs = Item.list_all()
    date_x = datetime.now() - timedelta(30)
    filter = Q(trade_flag=True) & Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x)
    qs = qs.filter(filter).order_by('-trade_price', 'id')
    return {
        'new_releases': qs[:20],
        'slim_banner': get_slim_banner(request),
    }
Beispiel #5
0
def rent_intro(request):
    class Form(forms.Form):
        email = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': '1'}))
        confirm_email = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': '2'}))
        password = forms.CharField(widget=forms.PasswordInput(attrs={'tabindex': '3'}))
        confirm_password = forms.CharField(widget=forms.PasswordInput(attrs={'tabindex': '4'}))
        username = forms.CharField(widget=forms.TextInput(attrs={'tabindex': '5'}))
        how_did_you_hear = forms.ChoiceField(choices=HOW_DID_YOU_HEAR_CHOICES, widget=forms.Select(attrs={'tabindex': '6'}))


    qs = Item.list_all()
    date_x = datetime.now() - timedelta(30)
    filter = Q(rent_flag=True) & Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x) & Q(rent_amount__gt=0)
    qs = qs.filter(filter).order_by('-rent_amount', 'id')
    context = {
        'new_releases': qs[:20],
#        'slim_banner': get_slim_banner(request),
        'form': Form(),
    }
    all_plans = get_all_rental_plans_info(request)[:2]
    page_id = int(request.GET.get('pageid',0))
    if page_id == 0:
        template = 'intro/rent.html'
        all_plans = get_all_rental_plans_info(request)
    elif page_id == 1:
        template = 'intro/landing-1.html'
        qs = Item.list_all()
        qs_base = qs.filter(rent_amount__gt=0).order_by('-rent_amount', 'id')
        qs = qs_base
        rent_list = RentList.objects.filter(rent_order__date_rent__gte=datetime.now() - timedelta(days=7)).values('item__id').query
        qs = qs.filter(id__in=rent_list)
        if qs.count() < 3:
            qs = qs_base
        context['qs'] = qs[:7]
    elif page_id == 2:
        template = 'intro/landing-2.html'
    else:
        template = 'intro/landing-3.html'
    context['all_plans'] = all_plans
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
Beispiel #6
0
def index(request):
    referer = request.META.get('HTTP_REFERER', '').lower()
    if referer!='':
        for dlp in DLP_CHOICES:
            for s in DLP_CHOICES[dlp]:
                if referer.find(s)!=-1:
                    return redirect(dlp)
    items = Item.list_new_releases(None).exclude(rent_flag=False).order_by('?')[:30]
    return {
        'new_releases': items,
        'slim_banner': get_slim_banner(request),
    }
Beispiel #7
0
def quick(request):
    if not request.is_ajax():
        return redirect('search:search')

    q = request.REQUEST.get('q')
    qs = Item.search_by_keyword(q)
        
    try:        
        res = []
        for i in qs[:7]:
            res.append({
                'url': i.get_absolute_url(),
                'title': i.get_cropped_name() + ' ' + unicode(i.category),
                'upc': i.upc,
                'release_date': defaultfilters.date(i.release_date) if i.release_date else None,
                'icon': i.get_nano_thumb(),
            })
    except Exception, e:
        debug(e)
Beispiel #8
0
def quick_game_finder(qs, q):
    qs = Item.search_by_keyword(q, qs)
    return qs
Beispiel #9
0
        elif order_by == 3: #Value: Low to High
            qs = qs.filter(trade_flag=True, trade_price__gt='0.0').order_by('trade_price')
        elif order_by == 4: #Value: High to Low
            qs = qs.filter(trade_flag=True, trade_price__gt='0.0').order_by('-trade_price')
        elif order_by == 5: #Rent Availability
            qs = qs.filter(rent_status__lt=6).order_by('-rent_status')
        elif order_by == 6: #Release Date
            qs = qs.exclude(release_date=None).order_by('-release_date')
        elif order_by == 7: ## of Players
            qs = qs.order_by('-number_of_players')
    
    q = request.GET.get('q')
    if q:
        title = q
        base_url['q'] = q
        qs = Item.search_by_keyword(q, qs=qs)
        
    if title and category:
        title += ' (' + category.name + ')'
        
    title = title or 'All Games'

    base_url = '&'.join(['%s=%s' % (k, urlquote(v)) for k, v in base_url.items()])    

    paginator = Paginator(qs, settings.SEARCH_RESULTS_PER_PAGE, 2)
    try:
        current_page = paginator.page(page)
    except Exception, e:
        debug(e)
        raise Http404()
Beispiel #10
0
def popular_by_category(request, slug):
    category = get_object_or_404(Category, slug=slug)
    return {
        'items': [get_item_json_synopsis(item) for item in Item.list_popular_by_category(category, 12)], 
    }
Beispiel #11
0
def popular_by_publisher(request, id):
    publisher = get_object_or_404(Publisher, pk=id)
    return {
        'items': [get_item_json_synopsis(item) for item in Item.list_popular_by_publisher(publisher, 12)], 
    }
Beispiel #12
0
def rent_intro2(request):
#    if not settings.DEBUG and not request.META.get('HTTP_REFERER', None):
#        return redirect('rent_intro')

    qs = Item.list_all()
    qs = qs.filter(rent_amount__gt=0).order_by('-rent_amount', 'id')

    objects = Item.list_all()
    objects = objects.order_by('-release_date', '-top_rental')

    all_games_count = objects.count()

    applied_filters = 2

    if request.is_ajax():
        c = request.GET.get('c', '')
        if c:
            objects = objects.filter(category__slug=c)

        g = request.GET.get('g', '')
        if g:
            applied_filters += 1
            g = map(int, g.split(','))
            ff = map(lambda x: Q(genre_list__contains=Genre.objects.get(id=x).name), g)
            objects = objects.filter(reduce(operator.or_, ff))
        y = request.GET.get('y', '')
        if y:
            applied_filters += 1
            y = map(int, y.split(','))
            ff = map(lambda x: Q(release_date__year=x), y)
            objects = objects.filter(reduce(operator.or_, ff))
        r = request.GET.get('r', '')
        if r:
            applied_filters += 1
            r = map(int, r.split(','))
            ff = map(lambda x: Q(ratio__gte=x, ratio__lt=x+1), r)
            objects = objects.filter(reduce(operator.or_, ff))
        a = request.GET.get('a', '')
        if a:
            applied_filters += 1
            a = map(int, a.split(','))
            if 100 in a:
                ff = [Q(top_rental=True)]
            else:
                ff = []
            ff += map(lambda x: Q(rent_status=x), a)
            objects = objects.filter(reduce(operator.or_, ff))
            show_all = ItemRentStatus.NotReleased in a
        else:
            objects = objects.exclude(rent_status=ItemRentStatus.NotRentable)
            show_all = False
        e = request.GET.get('e', '')
        if e:
            applied_filters += 1
            e = map(int, e.split(','))
            ff = map(lambda x: Q(rating=x), e)
            objects = objects.filter(reduce(operator.or_, ff))
        cs = request.GET.get('cs', '')
        if cs:
            applied_filters += 1
            cs = int(cs)
            today = datetime.today()
            if cs == 0:
                objects = objects.filter(release_date__gt=today)
            elif cs == 1:
                objects = objects.filter(release_date__gt=today, release_date__lte=today + timedelta(30))
            elif cs == 2:
                objects = objects.filter(release_date__gt=today + timedelta(30), release_date__lte=today + timedelta(60))
            objects = objects.order_by('release_date', '-top_rental')
        elif not show_all:
            objects = objects.filter(release_date__lte=datetime.today())
    else:
        objects = objects.filter(rent_status__in=[ItemRentStatus.Available, ItemRentStatus.High, ItemRentStatus.Medium, ItemRentStatus.Low])

    if 'p' in request.GET:
        page = request.GET['p'].lower()
        if page != 'show all':
            try:
                page = int(page)
            except:
                return redirect(request.META['PATH_INFO'])
        elif applied_filters < 2:
            page = 1
    else:
        page = 1

    if page != 'show all':
        paginator = Paginator(objects, 16, 4)
        try:
            current_page = paginator.page(page)
        except Exception, _e:
            raise Http404()
        objects = current_page.object_list
Beispiel #13
0
def check_upc(request, upc):
    item = Item.find_by_upc(upc)
    if item:
        return JsonResponse({'success': True, 'title': item.name, 'platform': unicode(item.category)})
    else:
        return JsonResponse({'success': False})
Beispiel #14
0
def buy_intro2(request):
    objects = Item.list_all()
    objects = objects.filter(retail_price_new__gt=0).order_by('-release_date')

    all_games_count = objects.filter(release_date__lte=datetime.today()).count()

    applied_filters = 2

    if request.is_ajax():
        c = request.GET.get('c', '')
        if c:
            objects = objects.filter(category__slug=c)

        g = request.GET.get('g', '')
        if g:
            applied_filters += 1
            g = map(int, g.split(','))
            ff = map(lambda x: Q(genre_list__contains=Genre.objects.get(id=x).name), g)
            objects = objects.filter(reduce(operator.or_, ff))
        y = request.GET.get('y', '')
        if y:
            applied_filters += 1
            y = map(int, y.split(','))
            ff = map(lambda x: Q(release_date__year=x), y)
            objects = objects.filter(reduce(operator.or_, ff))
        r = request.GET.get('r', '')
        if r:
            applied_filters += 1
            r = map(int, r.split(','))
            ff = map(lambda x: Q(ratio__gte=x, ratio__lt=x+1), r)
            objects = objects.filter(reduce(operator.or_, ff))
        pr = request.GET.get('pr', '')
        if pr:
            applied_filters += 1
            rr = [('0.01', '20'), ('20', '50'), ('50', '10000')]
            pr = set(map(int, pr.split(',')))
            if 3 in pr:
                show_used = True
                pr.remove(3)
            else:
                show_used = False
            if pr:
                ff = map(lambda x: Q(retail_price_new__gte=rr[x][0], retail_price_new__lt=rr[x][1]) | Q(retail_price_used__gte=rr[x][0], retail_price_used__lt=rr[x][1]), pr)
                objects = objects.filter(reduce(operator.or_, ff))
            if show_used:
                objects = objects.filter(pre_owned=True)
        e = request.GET.get('e', '')
        if e:
            applied_filters += 1
            e = map(int, e.split(','))
            ff = map(lambda x: Q(rating=x), e)
            objects = objects.filter(reduce(operator.or_, ff))
        cs = request.GET.get('cs', '')
        if cs:
            applied_filters += 1
            cs = int(cs)
            today = datetime.today()
            if cs == 0:
                objects = objects.filter(release_date__gt=today)
            elif cs == 1:
                objects = objects.filter(release_date__gt=today, release_date__lte=today + timedelta(30))
            elif cs == 2:
                objects = objects.filter(release_date__gt=today + timedelta(30), release_date__lte=today + timedelta(60))
            objects = objects.order_by('release_date')
        else:
            objects = objects.filter(release_date__lte=datetime.today())
    else:
        objects = objects.filter(release_date__lte=datetime.today())

    if 'p' in request.GET:
        page = request.GET['p'].lower()
        if page != 'show all':
            try:
                page = int(page)
            except:
                return redirect(request.META['PATH_INFO'])
        elif applied_filters < 2:
            page = 1
    else:
        page = 1

    if page != 'show all':
        paginator = Paginator(objects, 16, 4)
        try:
            current_page = paginator.page(page)
        except Exception, _e:
            raise Http404()
        objects = current_page.object_list
Beispiel #15
0
def trade_intro2(request):
    qs = Item.list_all().filter(trade_flag=True, trade_amount__gt=0, trade_price__gt=0)
    hot_trades = qs.order_by('-trade_amount', 'id')[:20]

    objects = Item.list_all()
    objects = objects.order_by('-release_date', '-hot_trade')

    all_games_count = objects.count()

    applied_filters = 2

    if request.is_ajax():
        c = request.GET.get('c', '')
        if c:
            objects = objects.filter(category__slug=c)

        g = request.GET.get('g', '')
        if g:
            applied_filters += 1
            g = map(int, g.split(','))
            ff = map(lambda x: Q(genre_list__contains=Genre.objects.get(id=x).name), g)
            objects = objects.filter(reduce(operator.or_, ff))
        y = request.GET.get('y', '')
        if y:
            applied_filters += 1
            y = map(int, y.split(','))
            ff = map(lambda x: Q(release_date__year=x), y)
            objects = objects.filter(reduce(operator.or_, ff))
        r = request.GET.get('r', '')
        if r:
            applied_filters += 1
            r = map(int, r.split(','))
            ff = map(lambda x: Q(ratio__gte=x, ratio__lt=x+1), r)
            objects = objects.filter(reduce(operator.or_, ff))
        t = request.GET.get('t', '')
        if t:
            vv = [15, 25, 35]
            applied_filters += 1
            t = set(map(int, t.split(',')))
            if 200 in t:
                ff = [Q(hot_trade=True)]
                t.remove(200)
            else:
                ff = []
            ff += map(lambda x: Q(trade_price__gte=vv[x]), t)
            objects = objects.filter(reduce(operator.or_, ff))
        e = request.GET.get('e', '')
        if e:
            applied_filters += 1
            e = map(int, e.split(','))
            ff = map(lambda x: Q(rating=x), e)
            objects = objects.filter(reduce(operator.or_, ff))
        cs = request.GET.get('cs', '')
        if cs:
            applied_filters += 1
            cs = int(cs)
            today = datetime.today()
            if cs == 0:
                objects = objects.filter(release_date__gt=today)
            elif cs == 1:
                objects = objects.filter(release_date__gt=today, release_date__lte=today + timedelta(30))
            elif cs == 2:
                objects = objects.filter(release_date__gt=today + timedelta(30), release_date__lte=today + timedelta(60))
            objects = objects.order_by('release_date', '-hot_trade')
        else:
            objects = objects.filter(trade_price__gt=0, trade_flag=True, release_date__lte=datetime.now())
    else:
        objects = objects.filter(trade_price__gt=0, trade_flag=True, release_date__lte=datetime.now())

    if 'p' in request.GET:
        page = request.GET['p'].lower()
        if page != 'show all':
            try:
                page = int(page)
            except:
                return redirect(request.META['PATH_INFO'])
        elif applied_filters < 2:
            page = 1
    else:
        page = 1

    if page != 'show all':
        paginator = Paginator(objects, 16, 4)
        try:
            current_page = paginator.page(page)
        except Exception, _e:
            raise Http404()
        objects = current_page.object_list
Beispiel #16
0
def category(request, slug, filter):
    category = slug and get_object_or_404(Category, slug=slug)

    if 'genre' in request.GET:
        genre = request.GET.get('genre', '*')
        try:
            request.session['filter/genre'] = Genre.objects.get(pk=int(genre))
        except:
            request.session['filter/genre'] = None
        return redirect(request.META['PATH_INFO'])
    
    if 'p' in request.GET:
        try:
            page = int(request.GET['p'])
        except:
            return redirect(request.META['PATH_INFO'])
    else:
        page = 1
    genres = category.list_genres() if category else Genre.objects.all()[:]
    genre = request.session.get('filter/genre')
    if genre and (genre not in genres):
        genre = None

    # TODO: resolve me!    
    genres = genres[:15]

    auto_filter = False if filter else True
    filter = (filter, dict(CATALOG_FILTERS).get(filter)) if filter else CATALOG_FILTERS[0]
    
    featured_games = FeaturedGame.get(category, request)
#    if category:
#        featured_games = FeaturedGame.get(category)
#    else:
#        featured_games = CatalogBanner.get()
    
    if category: 
        objects = Item.list_by_category(category, genre)
    else:
        objects = Item.list_all(genre)

    q = request.GET.get('q')
    if q:
        objects = quick_game_finder(objects, q)
    else:
        def get_objects(*args, **kwargs):
            filter = kwargs.get('filter')
            if category or not request.user.is_authenticated():
                qs = objects.order_by(*args)
                if filter:
                    qs = qs.filter(filter)
                return qs
            else:
                own_consoles = request.user.get_profile().get_owned_systems()
                o1 = objects.filter(category__in=own_consoles).order_by(*args)
                if filter: o1 = o1.filter(filter)
                o2 = objects.exclude(category__in=own_consoles).order_by(*args)
                if filter: o2 = o2.filter(filter)
                return list(o1) + list(o2)
                
        
        f = filter and filter[0]
        if f == 'best-sellers':
            date_x = datetime.now() - timedelta(60)
            filter = Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x) & Q(sold_amount__gt=0)
            objects = get_objects('-sold_amount', '-release_date', 'id', filter=filter)
        elif f == 'top-rentals':
            date_x = datetime.now() - timedelta(60)
            filter = Q(rent_flag=True) & Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x) & Q(rent_amount__gt=0)
            objects = get_objects('-rent_amount', '-release_date', 'id', filter=filter)
        elif f == 'top-trades':
#            date_x = datetime.now() - timedelta(60)
#            filter = Q(trade_flag=True) & Q(release_date__lte=datetime.now()) & Q(release_date__gte=date_x) & Q(trade_amount__gt=0)
            filter = Q(trade_flag=True) & Q(release_date__lte=datetime.now()) & Q(trade_amount__gt=0)
            objects = get_objects('-trade_amount', '-release_date', 'id', filter=filter)
        elif f == 'new-releases':
            date_x = datetime.now() - timedelta(60)
            objects = objects.filter(release_date__gt=date_x, release_date__lte=datetime.now()).order_by('-release_date')
            if not category and request.user.is_authenticated():
                objects = objects.filter(release_date__gt=date_x, release_date__lte=datetime.now())
                own_consoles = request.user.get_profile().get_owned_systems()
                o1 = objects.filter(category__in=own_consoles)
                o2 = objects.exclude(category__in=own_consoles)
                objects = list(o1) + list(o2)
        else:
            seed = request.session.get('catalog-random-seed', random.random())
            if page == 1:
                seed = random.random()
            request.session['catalog-random-seed'] = seed
            request.session.save()
                
            random.seed(seed)

            if f == 'coming-soon':
#                date_x = datetime.now() + timedelta(30)
#                objects = objects.filter(Q(release_date__gt=datetime.now()) & Q(release_date__lte=date_x))
                objects = objects.filter(release_date__gt=datetime.now())

            if category or not request.user.is_authenticated():
                objects = list(objects)
            else:
                own_consoles = request.user.get_profile().get_owned_systems().order_by('-release_date', 'id')
                o1 = list(objects.filter(category__in=own_consoles))
                o2 = list(objects.exclude(category__in=own_consoles))
#                random.shuffle(o1)
#                random.shuffle(o2)
                objects = o1 + o2 

    paginator = Paginator(objects, settings.CATALOG_ITEMS_AMOUNT, 5)
    try:
        current_page = paginator.page(page)
    except Exception, e:
        debug(e)
        raise Http404()
Beispiel #17
0
def get_default_filter_context(request, ctx={}):
    all = Item.list_all().filter(release_date__lte=datetime.today())
    all_games_count = all.filter(release_date__lte=datetime.today()).count()

    genres = Genre.objects.all().order_by('name')
    genres = map(lambda x: {'id': x.id, 'name': x.name, 'item_count': all.filter(genre_list__contains=x.name).count()}, genres)

    y = datetime.today().year
    years = map(lambda x: {'year': x, 'count': all.filter(release_date__year=x).count()}, range(y, y-3, -1))

    ratings = map(lambda x: {'rating': x, 'count': all.filter(Q(ratio__gte=x, ratio__lt=x+1)).count()}, [5, 4, 3])

    prices = [{
        'price': 0,
        'text': 'Under $20',
        'count': all.filter(retail_price_new__gt=0, retail_price_new__lt=20).count(),
    }, {
        'price': 1,
        'text': '$20 - $49.99',
        'count': all.filter(retail_price_new__gte=20, retail_price_new__lt=50).count(),
    }, {
        'price': 2,
        'text': 'Over $50',
        'count': all.filter(retail_price_new__gte=50).count(),
    }, {
        'price': 3,
        'text': 'Pre-Owned',
        'count': all.filter(pre_owned=True).count(),
    }]

    RENT_STATUS_CHOICES_MAP = dict(RENT_STATUS_CHOICES)
    availability = []
    for a in (ItemRentStatus.Available, ItemRentStatus.High, ItemRentStatus.Medium, ItemRentStatus.Low, ItemRentStatus.Unknown, ItemRentStatus.NotReleased):
        availability.append({
            'id': a,
            'text': RENT_STATUS_CHOICES_MAP[a],
            'count': Item.list_all().filter(rent_status=a).count(),
        })
    availability.append({
        'id': 100,
        'text': 'Top Rental',
        'count': Item.list_all().filter(top_rental=True).count(),
    })

    trade = [{
        'price': 0,
        'text': 'Over $15',
        'count': all.filter(trade_price__gte=15).count(),
    }, {
        'price': 1,
        'text': 'Over $25',
        'count': all.filter(trade_price__gte=25).count(),
    }, {
        'price': 2,
        'text': 'Over $35',
        'count': all.filter(trade_price__gte=35).count(),
    },]

    esrb = Rating.objects.all().annotate(item_count=Count('item')).filter(item_count__gt=0).exclude(id=131126)

    all = Item.list_all().filter(retail_price_new__gt=0)
    today = datetime.today()
    coming = [{
        'id': 0,
        'name': 'View All',
        'count': all.filter(release_date__gt=today).count(),
    }, {
        'id': 1,
        'name': 'This Month',
        'count': all.filter(release_date__gt=today, release_date__lte=today + timedelta(30)).count(),
    }, {
        'id': 2,
        'name': 'Next Month',
        'count': all.filter(release_date__gt=today + timedelta(30), release_date__lte=today + timedelta(60)).count(),
    }]

    res = {
        'genres': genres,
        'years': years,
        'prices': prices,
        'ratings': ratings,
        'availability': availability,
        'trade': trade,
        'esrb': esrb,
        'coming': coming,
        'all_games_count': all_games_count,
        'b': Item.objects.filter(pk__in=[800008, 800013, 800002])
    }
    res.update(get_wimgw_context(request))
    res.update(ctx)
    return res
Beispiel #18
0
def wimgw(request):
    if request.is_ajax():
        if 'wimgw' in request.GET:
            return render_to_response('partials/wimgw.html', get_wimgw_context(request), RequestContext(request))
        elif 'carousel' in request.GET:
            carousel = request.GET['carousel']
            if carousel not in ['rent', 'trade', 'buy']:
                return HttpResponseBadRequest()
            if 'c' in request.GET:
                category = get_object_or_404(Category, slug=request.GET['c'])
            else:
                category = None
            carousel = {
                'trade': ('hottest_tradeins_carousel', {
                    'hot_trades': Item.list_all(category=category).filter(trade_flag=True, trade_price__gt=0).order_by('-trade_amount', 'id')[:20],}),
                'rent': ('most_rentals_carousel', {
                    'most_rentals': Item.list_all(category=category).filter(rent_flag=True).order_by('-rent_amount', 'id')[:20],}),
                'buy': ('best_sellers_carousel', {
                    'best_sellers': Item.list_hottest_selling(category=category)}),
            }[carousel]
            return render_to_response('partials/wimgw/%s.html' % carousel[0],
                                      carousel[1], RequestContext(request))

    q = None
    current_category = None
    objects = Item.list_all()
    applied_filters = 2
    if request.is_ajax():
        if 'q' in request.GET:
            q = request.GET['q']
            objects = Item.search_by_keyword(q).filter(trade_flag=True, trade_price__gt=0)

        c = request.GET.get('c', '')
        if c:
            objects = objects.filter(category__slug=c)
            current_category = Category.objects.get(slug=c)

        g = request.GET.get('g', '')
        if g:
            applied_filters += 1
            g = map(int, g.split(','))
            ff = map(lambda x: Q(genre_list__contains=Genre.objects.get(id=x).name), g)
            objects = objects.filter(reduce(operator.or_, ff))
        y = request.GET.get('y', '')
        if y:
            applied_filters += 1
            y = map(int, y.split(','))
            ff = map(lambda x: Q(release_date__year=x), y)
            objects = objects.filter(reduce(operator.or_, ff))
        r = request.GET.get('r', '')
        if r:
            applied_filters += 1
            r = map(int, r.split(','))
            ff = map(lambda x: Q(ratio__gte=x, ratio__lt=x+1), r)
            objects = objects.filter(reduce(operator.or_, ff))
        pr = request.GET.get('pr', '')
        if pr:
            applied_filters += 1
            rr = [('0.01', '20'), ('20', '50'), ('50', '10000')]
            pr = set(map(int, pr.split(',')))
            if 3 in pr:
                show_used = True
                pr.remove(3)
            else:
                show_used = False
            if pr:
                ff = map(lambda x: Q(retail_price_new__gte=rr[x][0], retail_price_new__lt=rr[x][1]) | Q(retail_price_used__gte=rr[x][0], retail_price_used__lt=rr[x][1]), pr)
                objects = objects.filter(reduce(operator.or_, ff))
            if show_used:
                objects = objects.filter(pre_owned=True)
        a = request.GET.get('a', '')
        if a:
            applied_filters += 1
            a = map(int, a.split(','))
            if 100 in a:
                ff = [Q(top_rental=True)]
            else:
                ff = []
            ff += map(lambda x: Q(rent_status=x), a)
            objects = objects.filter(reduce(operator.or_, ff))
        else:
            objects = objects.exclude(rent_status=ItemRentStatus.NotRentable)
        t = request.GET.get('t', '')
        if t:
            applied_filters += 1
            rr = [15, 25, 35]
            t = set(map(int, t.split(',')))
            if 100 in t:
                wimgw = True
                t.remove(100)
            else:
                wimgw = False
            if t:
                ff = map(lambda x: Q(trade_price__gte=rr[x], trade_flag=True, release_date__lte=datetime.now()), t)
                objects = objects.filter(reduce(operator.or_, ff))
        e = request.GET.get('e', '')
        if e:
            applied_filters += 1
            e = map(int, e.split(','))
            ff = map(lambda x: Q(rating=x), e)
            objects = objects.filter(reduce(operator.or_, ff))
        cs = request.GET.get('cs', '')
        if cs:
            applied_filters += 1
            cs = int(cs)
            today = datetime.today()
            if cs == 0:
                objects = objects.filter(release_date__gt=today)
            elif cs == 1:
                objects = objects.filter(release_date__gt=today, release_date__lte=today + timedelta(30))
            elif cs == 2:
                objects = objects.filter(release_date__gt=today + timedelta(30), release_date__lte=today + timedelta(60))
            objects = objects.order_by('release_date')


    if 'p' in request.GET:
        page = request.GET['p'].lower()
        if page != 'show all':
            try:
                page = int(page)
            except:
                return redirect(request.META['PATH_INFO'])
        elif applied_filters < 2:
            page = 1
    else:
        page = 1

    items_found = objects.count()

    if page != 'show all':
        paginator = Paginator(objects, 16, 4)
        try:
            current_page = paginator.page(page)
        except Exception, _e:
            raise Http404()
        objects = current_page.object_list
Beispiel #19
0
 def clean_upc(self):
     upc = self.cleaned_data['upc']
     item = Item.find_by_upc(upc)
     if not item:
         raise forms.ValidationError('Wrong UPC')
     return item
Beispiel #20
0
                'show_paginator': True,
                'has_previous_page': current_page.has_previous(),
                'previous_page_number': current_page.previous_page_number(),
                'has_next_page': current_page.has_next(),
                'next_page_number' : current_page.next_page_number(),
                'page_number': page,
                'page_range': calc_paginator_ranges(paginator, page),
                'num_pages': paginator.num_pages,
            })
            if applied_filters > 2:
                ctx['show_all_link'] = True
        else:
            ctx['no_paginator'] = True
        return JsonResponse(ctx)
    else:
        all = Item.list_all().filter(retail_price_new__gt=0, release_date__lte=datetime.today())

        genres = Genre.objects.all().order_by('name')
        genres = map(lambda x: {'id': x.id, 'name': x.name, 'item_count': all.filter(genre_list__contains=x.name).count()}, genres)

        y = datetime.today().year
        years = map(lambda x: {'year': x, 'count': all.filter(release_date__year=x).count()}, range(y, y-3, -1))

        ratings = map(lambda x: {'rating': x, 'count': all.filter(Q(ratio__gte=x, ratio__lt=x+1)).count()}, [5, 4, 3])

        prices = [{
            'price': 0,
            'text': 'Under $20',
            'count': all.filter(retail_price_new__gt=0, retail_price_new__lt=20).count(),
        }, {
            'price': 1,