示例#1
0
def clear_basket(request):
    """
    Empty the basket for the current user  
    """
    try:
        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace'] 	
        
        Basket.empty_basket(user, workspace)
        
    except Exception,  ex:
        logger.exception(ex)
        raise ex
示例#2
0
文件: views.py 项目: ncorona/notredam
def clear_basket(request):
    """
    Empty the basket for the current user  
    """
    try:
        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace']

        Basket.empty_basket(user, workspace)

    except Exception, ex:
        logger.exception(ex)
        raise ex
示例#3
0
def basket_size(request):
    """
    Return size of the current user basket
    """
    user = User.objects.get(pk=request.session['_auth_user_id'])
    workspace = request.session['workspace']

    basket = Basket.get_basket(user, workspace)
    
    count = basket.get_size()

    return HttpResponse(count)
示例#4
0
文件: views.py 项目: ncorona/notredam
def basket_size(request):
    """
    Return size of the current user basket
    """
    user = User.objects.get(pk=request.session['_auth_user_id'])
    workspace = request.session['workspace']

    basket = Basket.get_basket(user, workspace)

    count = basket.get_size()

    return HttpResponse(count)
示例#5
0
def reload_item(request):
    """
    Add items to the current user basket
    """

    try:
        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace']
        items_post = request.POST.getlist('items')
        logger.debug('items_post %s'%items_post)

        basket = Basket.get_basket(user, workspace)
        items = Item.objects.filter(pk__in=items_post)     
        logger.debug('items %s'%items)
        logger.debug('basket.items %s'%Basket.objects.all())  
        basket.add_items(items)
	
    except Exception,  ex:
        logger.exception(ex)
        raise ex
示例#6
0
文件: views.py 项目: ncorona/notredam
def reload_item(request):
    """
    Add items to the current user basket
    """

    try:
        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace']
        items_post = request.POST.getlist('items')
        logger.debug('items_post %s' % items_post)

        basket = Basket.get_basket(user, workspace)
        items = Item.objects.filter(pk__in=items_post)
        logger.debug('items %s' % items)
        logger.debug('basket.items %s' % Basket.objects.all())
        basket.add_items(items)

    except Exception, ex:
        logger.exception(ex)
        raise ex
示例#7
0
文件: views.py 项目: relic7/nd1404
def _search_items(request, workspace, media_type, start = 0, limit = 30):
    user = User.objects.get(pk=request.session['_auth_user_id'])
    logger.debug('************** searching items for user %s' % user.pk)

    only_basket = request.POST.has_key('only_basket')    
    logger.debug('************** searching only_basket %s' % only_basket)
    
    
    items = workspace.items.all()
    logger.debug('****************** found %d items' % len(items))

    user_basket = Basket.get_basket(user, workspace)
    basket_items = user_basket.items.all().values_list('pk', flat=True)
    logger.debug('******************8 found %d basket items' % len(basket_items))

    if only_basket:
        items = items.filter(pk__in=basket_items)

    items, total_count = _search(request.POST,  items, media_type, start, limit, workspace)

    return (items, total_count)
示例#8
0
def remove_from_basket(request):
    """
    Remove items from the current user basket
    """

    try:
        items_post = request.POST.getlist('items')

        items = Item.objects.filter(pk__in=items_post)       
 	
        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace']

        basket = Basket.get_basket(user, workspace)
        basket.remove_items(items)

        count = basket.get_size()

    except Exception,  ex:
        count = 0
        logger.exception(ex)
        raise ex
示例#9
0
文件: views.py 项目: ncorona/notredam
def remove_from_basket(request):
    """
    Remove items from the current user basket
    """

    try:
        items_post = request.POST.getlist('items')

        items = Item.objects.filter(pk__in=items_post)

        user = User.objects.get(pk=request.session['_auth_user_id'])
        workspace = request.session['workspace']

        basket = Basket.get_basket(user, workspace)
        basket.remove_items(items)

        count = basket.get_size()

    except Exception, ex:
        count = 0
        logger.exception(ex)
        raise ex
示例#10
0
文件: views.py 项目: relic7/nd1404
def load_items(request, view_type=None, unlimited=False):
    logger.debug('******************** load_items')
    logger.debug('request POST inside* load_items %s' % request.POST )
    from datetime import datetime
    try:
        user = request.user
        
        workspace = request.session['workspace']        

        media_type = request.POST.getlist('media_type')
        
#        save media type on session

        if request.session.__contains__('media_type'):
            request.session['media_type'][workspace.pk] = list(media_type)
        else:
            request.session['media_type']= {workspace.pk: list(media_type)}
            
        request.session.modified = True
        
        start = int(request.POST.get('start', 0))
        limit = int(request.POST.get('limit', 30))
		
        if limit == 0:
            start = None
            limit = None
            
        
        items, total_count = _search_items(request, workspace, media_type, start, limit)                    
        item_dict = []
        now = time.time()

        items_pks = [item.pk for item in items]
        
        tasks_pending_obj = []
        tasks_pending = []
                

        default_language = get_metadata_default_language(user, workspace)

        user_basket = Basket.get_basket(user, workspace)
        basket_items = user_basket.items.all().values_list('pk', flat=True)
        
        items_info = []
        thumb_caption_setting = DAMComponentSetting.objects.get(name='thumbnail_caption')
        thumb_caption = thumb_caption_setting.get_user_setting(user, workspace)
        fullscreen_caption_setting = DAMComponentSetting.objects.get(name='fullscreen_caption')
        fullscreen_caption = fullscreen_caption_setting.get_user_setting(user, workspace)
        default_language = get_metadata_default_language(user, workspace)    
        check_deleted = request.POST.has_key('show_deleted')
        for item in items:
            tmp = item.get_info(workspace, thumb_caption, default_language, check_deleted = check_deleted, fullscreen_caption = fullscreen_caption)
            if item.pk in basket_items:
                tmp['item_in_basket'] = 1
            else:
                tmp['item_in_basket'] = 0
                
            items_info.append(tmp)
        
#        for item in items:
#            thumb_url,thumb_ready = _get_thumb_url(item, workspace)
#            logger.debug('thumb_url,thumb_ready %s, %s'%(thumb_url,thumb_ready))
#            
#            geotagged = 0
#            inprogress =  int( (not thumb_ready) or (item.pk in tasks_pending)) 
#            
#            
#            if GeoInfo.objects.filter(item=item).count() > 0:
#                geotagged = 1
#            
#            item_in_basket = 0
#
#            if item.pk in basket_items:
#                item_in_basket = 1
#             
#            states = item.stateitemassociation_set.all()
#            try:
#                my_caption = _get_thumb_caption(item, thumb_caption, default_language)
#            except:
#                # problems retrieving thumb, skip this items
#                continue
##                my_caption = ''
#            if inprogress:
#                preview_available = tasks_pending_obj.filter(component__variant__name = 'preview', component__item = item, params__contains = 'adapt_resource').count()
#            else:
#                preview_available = 0
#            item_info = {
#                "name":my_caption,
#                "pk": smart_str(item.pk),
#                "geotagged": geotagged, 
#                "inprogress": inprogress, 
#                'thumb': thumb_ready, 
#                'type': smart_str(item.type.name),
#                'inbasket': item_in_basket,
#                'preview_available': preview_available,
#                "url":smart_str(thumb_url), "url_preview":smart_str("/redirect_to_component/%s/preview/?t=%s" % (item.pk,  now))
#            }
#            
#            if states.count():
#                state_association = states[0]
#                
#                item_info['state'] = state_association.state.pk
#                
#            item_dict.append(item_info)
        
        logger.info('items_info: %s' % items_info) 
        res_dict = {"items": items_info, "totalCount": str(total_count)}       
        resp = simplejson.dumps(res_dict)

        return HttpResponse(resp)
    except Exception,  ex:
        logger.exception(ex)
        raise ex