Example #1
0
    if len(res) == 2:
        cnx, template = res
        paged_data = None
    else:
        cnx, template, paged_data = res
    if isinstance(cnx, HttpResponse):
        return cnx
    context = {
        'page_class': 'staff-page-' + '-'.join(path),
    }
    path = map(lambda x: x.replace('__', '/'), path)
    context.update(cnx or {})
    template = template or 'staff/' + '/'.join(path) + '.html'
    if paged_data:
        def wrapper(request, *args, **kwargs): return context
        context = paged(*paged_data)(wrapper)(request)
        return render_to_response(template, context, RequestContext(request))
    else:
        return render_to_response(template, context, RequestContext(request))

@staff_only
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})

@staff_only
@simple_view('staff/purchase_order.html')
def purchase_order(request, purchase_id):
Example #2
0
def physical(request, dc_code=None, **kwargs):
    if 'dc' in request.GET:
        return redirect('staff:physical_inventory', request.GET['dc'])
    
    
    class FilterForm(forms.Form):
        platform = forms.ModelChoiceField(Category.list(), empty_label='(All)', required=False)
        publisher = forms.ModelChoiceField(Publisher.objects.all().order_by('name'), empty_label='(All)', required=False)
        q = forms.CharField(required=False, label='')
    
    
    profile = request.user.get_profile()
    if profile.group == Group.DC_Operator:
        if dc_code:
            raise Http404()
        dc = profile.dc
        dsc = None
    else:
        dc = Dropship.objects.filter(code=dc_code)
        dc = dc[0] if dc.count() else None
        dsc = Dropship.objects.all()

    search_form = FilterForm(request.GET)
    search_form.is_valid() # bound the form
    sd = search_form.cleaned_data

    qs = Inventory.objects.all()
    qs = qs.filter(dropship=dc)
    if not dc:
        qs = qs.order_by('-id')
    
    qs1 = qs
    if sd.get('platform'):
        qs1 = qs1.filter(item__category=sd['platform'].id)
    if sd.get('publisher'):
        qs1 = qs1.filter(item__publisher=sd['publisher'].id)
    if sd.get('q'):
        q = sd['q']
        filters = []
        for f in ('upc', 'id', 'short_name', 'genre_list', 'tag_list'):
            filters.append(Q(**{'item__%s__icontains' % f: q}))
        qs1 = qs1.filter(reduce(operator.or_, filters))

    class ItemWrapper(object):
        def __init__(self, id, total_count):
            self.id = id
            self.total_count = total_count
            
        def item(self):
            if hasattr(self, '__item'):
                return self.__item
            self.__item = Item.objects.get(pk=self.id)
            return self.__item
        
        def instock_count(self):
            return qs.filter(item__id=self.id, status=InventoryStatus.InStock).count()
    
    items = []
    for i in qs1.values('item').annotate(total_count=Count('item')):
        items.append(ItemWrapper(i['item'], i['total_count']))

    ctx = {
        'title': 'Physical Games',
        'dc_code': dc.code if dc else 'GMS',
        'dcs': dsc, 
        'paged_qs': items,
        'search_form': search_form,
    }
    if not dc_code:
        return ctx, None, ('items', )
    else:
        def wrapper(request, *args, **kwargs): return ctx
        ctx = paged('items')(wrapper)(request)
        return render_to_response('staff/inventory/physical.html', ctx, RequestContext(request))