Пример #1
0
	def view( self, request, shop_name ):
		Location( request.session, 'shop' ).set( get_shop_location( shop_name, '', request.GET ) )
		req = request.REQUEST
		form_request = None
		page = int( req[ 'page' ] ) if 'page' in req else 1	

		q_dict = {}
		q_dict.update( shop = self._shop_id )
		
		if 'category' in req:
			category = int( req[ 'category' ] )
			q_dict.update( category = category )
		else:
			category = None
		
		page_products = ItemPage( Product ).get( q_dict = q_dict, page = page )
		
		cart = Cart( request.session )
		cart.add_in_cart_attr( page_products[ 'object_list' ] )

		return super( ShopView, self ).view( request, shop_name,
												{	'page_products': page_products,
													'page': int( page ),
													'num_products_on_page': NUM_ITEMS_ON_PAGE,
													'categories': get_sorted_by_name( get_field_list_from_meta( 'product_category', ShopProductCategory, 'shop', self._shop_id  ) ),
													'category': category
												} )
Пример #2
0
	def view( self, request, shop_name, dictionary = {} ):		
		cart = Cart( request.session )		

		req = request.REQUEST
		Location( request.session, 'shop' ).set( get_shop_location( shop_name, 'search', request.GET ) )

		search = Search( request.session )
		search_is_set = search.is_set()
		
		d = {	'categories': get_sorted_by_name( get_field_list_from_meta( 'product_category', ShopProductCategory, 'shop', self._shop_id  ) ),					
				'producers': get_sorted_by_name( get_field_list_from_meta( 'producer', ShopProducer, 'shop', self._shop_id ) ),
				'countries': get_sorted_by_name( get_field_list_from_meta( 'country', ShopCountry, 'shop', self._shop_id ) ),
				'search_is_set': search_is_set
		}

		q_dict = { 'shop': self._shop_id }

		if request.method == 'POST':
			form = SearchProductForm( request.POST )
			fields = dict( [ ( key, request.POST[ key ] ) for key in form.fields.iterkeys() ] )
			if form.is_valid():
				d.update( is_valid = True )
				q_dict.update( form.cleaned_data )
				search.set( **q_dict )				
				shop = get_shop_by_name( request.session, shop_name )
				page_products = ItemPage( Product ).get( q_dict = SearchView._removed_empty_items( form, q_dict ), page = 1 )
				d.update( page = 1 )
			else:
				d.update( is_valid = False )
				page_products = None
		else:
			form = SearchProductForm()

			is_page = 'page' in req
			page = int( req[ 'page' ] ) if is_page else 1		
			d.update( page = page )

			if search.is_set():
				fields = search.get()
				if is_page:
					fields.update( shop = self._shop_id )
					page_products = ItemPage( Product ).get( q_dict = SearchView._removed_empty_items( form, search.get() ), page = page )
				else:
					page_products = None
			else:
				fields = dict( [ ( key, form.fields[ key ].initial ) for key in form.fields.iterkeys() ] )
				page_products = None		
				
		if page_products:
			cart.add_in_cart_attr( page_products[ 'object_list' ] )

		d.update( page_products = page_products )
		
		d.update( form = form )
		d.update( fields = fields )

		d.update( dictionary )
		
		return super( SearchView, self ).view( request, shop_name, d )
Пример #3
0
	def view( self, request, shop_name ):
		Location( request.session, 'shop' ).set( get_shop_location( shop_name, 'cart', request.GET ) )
		req = request.REQUEST
		cart = Cart( request.session )
		if request.method == 'POST':
			cart.remove_item( req[ 'product_id' ] )

		page = int( req[ 'page' ] ) if 'page' in req else 1
		delivery_cost = get_shop_by_name( request.session, shop_name ).delivery_cost

		page_products = ItemPage.get_by_items_list( items_list = cart.get(), page = page )

		return super( CartView, self ).view( request, shop_name,
												{	'page_products': page_products,
													'is_cart_empty': len( page_products[ 'object_list' ] ) == 0,
													'page': int( page ),
													'num_products_on_page': NUM_ITEMS_ON_PAGE,
													'sum': cart.get_sum_price() + delivery_cost
												} )