def __init__(self, stock_selection=None, facet_selection=None, index=None, request=None): """ Values are extracted from the request. This will raise an IndexError if there is no object at the given index. """ if index is None: if request: self.index = int(request.GET.get("index", 0)) else: self.index = 0 else: self.index = index self.stock_selection = stock_selection self.facet_selection = facet_selection if facet_selection: self.stock_facet_qs = facet_selection.stock_facet_qs( self.stock_selection.stock) else: self.stock_facet_qs = StockFacetQuerySet( stock=self.stock_selection.stock) try: self.object_at_index = self.stock_facet_qs[self.index] except IndexError: self.object_at_index = None
def stock_facet_qs(self, stock): return StockFacetQuerySet(stock=stock, facet_slug=self.slug, facet_value=self.value)