def render(self, context): request = value_or_none('request', context) product = value_or_literal(self._product, context) basket_prefix = value_or_literal(self._basket_prefix_name, context) template_name = value_or_literal(self._template_name, context) if not template_name: template_name = 'cubane/ishop/elements/add_to_basket.html' # construct return url category = product.primary_category if category: return_url = reverse('shop.category', args=[category.slug, category.pk]) else: return_url = '' # render add to basket form form = AddToBasketForm(request=request, product=product, prefix=basket_prefix, with_varieties=self._with_varieties) t = get_template(template_name) d = { 'product': product, 'form': form, 'basket_prefix': basket_prefix, 'post_url': reverse('shop.basket.add') + '?r=%s' % return_url } with context.push(**d): return t.render(context)
def backend_edit_url(context, instance): """ Find the edit url for editing the given instance. """ backend = value_or_none('backend', context) if backend: return backend.get_url_for_model_instance(instance, view='edit') + ('?pk=%s' % instance.pk) else: return ''
def render(self, context): form = value_or_none(self.form, context) enctype = value_or_literal(self.enctype, context) if form == None: return '' t = self.get_template() d = {'form': form, 'enctype': enctype} with context.push(**d): return t.render(context)
def render(self, context): image = value_or_none(self.image, context) shape = value_or_literal(self.shape, context) clippath = value_or_literal(self.clippath, context) if shape: if shape not in settings.IMAGE_SHAPES and shape != 'original': return template_error("Shape '%s' not defined." % shape) else: shape = 'original' return render_svg_image(image, shape, clippath)
def render(self, context): image = value_or_none(self.image, context) shape = value_or_literal(self.shape, context) # additional attributes if self.attr: attr = value_or_literal(self.attr, context) else: attr = None return self.render_image(image, shape, self.noscript, attr, self.inline)
def render(self, context): # resolve target (none, category or product) if self._target == None: target = None else: target = value_or_literal(self._target, context) if target == 'None': target = None # resolve sep request = value_or_none('request', context) sep = value_or_literal(self._sep, context) # build list of pages based on given target items = [('Home', '/')] if target == None: pass elif isinstance(target, str) or isinstance(target, unicode): # static page items.append((target, make_absolute_url(request.path))) elif isinstance(target, get_category_model()): # category page items.extend([(c.title, c.get_absolute_url()) for c in target.get_path()]) elif isinstance(target, get_product_model()): # product category first... if target.primary_category: items.extend([(c.title, c.get_absolute_url()) for c in target.primary_category.get_path()]) # ...then the product itself items.append((target.title, target.get_absolute_url())) elif isinstance(target, ChildPage): # page/child page page = target.page items.append((page.title, page.get_absolute_url())) items.append((target.title, target.get_absolute_url())) elif isinstance(target, PageBase): # single cms page items.append((target.title, target.get_absolute_url())) else: raise ValueError('Invalid target argument: Must be instance of Category, Product or None.') t = get_template('cubane/ishop/elements/breadcrumbs.html') d = { 'items': items, 'sep': sep, } with context.push(**d): return t.render(context)
def render(self, context): image = value_or_none(self.image, context) shape = value_or_literal(self.shape, context) # additional attributes if self.attr: attr = value_or_literal(self.attr, context) else: attr = None if shape: if shape not in settings.IMAGE_SHAPES and shape != 'original': return template_error("Shape '%s' not defined." % shape) else: shape = 'original' return render_background_image_attr(image, shape, self.height, attr)
def current_url_with_args(context, **kwargs): """ Return the current URL with all existing query arguments with the given query arguments added to the current URL. """ request = value_or_none('request', context) if request: args = request.GET.copy() for k, v in kwargs.iteritems(): if v is None: if k in args: del args[k] else: args[k] = v if args: return make_absolute_url('%s?%s' % (request.path, args.urlencode())) else: return make_absolute_url(request.path) else: return ''