Beispiel #1
0
    def all_lines(self):
        """
        Return a cached set of basket lines.

        This is important for offers as they alter the line models and you
        don't want to reload them from the DB.
        """
        if self.id is None:
            return query.EmptyQuerySet(model=self.__class__)
        if self._lines is None:
            self._lines = self.lines.all()
        return self._lines
Beispiel #2
0
    def all_lines(self):
        """
        Return a cached set of basket lines.

        This is important for offers as they alter the line models and you
        don't want to reload them from the DB as that information would be
        lost.
        """
        if self.id is None:
            return query.EmptyQuerySet(model=self.__class__)
        if self._lines is None:
            self._lines = self.lines.select_related(
                'product', 'product__stockrecord').all().prefetch_related(
                    'attributes', 'product__images')
        return self._lines
Beispiel #3
0
def permission_filtered_model_qs(queryset, user, permissions=[]):
    """ returns Queryset filtered accordingly to given permissions """
    if user.is_superuser:
        return queryset
    category_fk = model_category_fk(queryset.model)
    if not category_fk:
        return queryset
    q = queryset
    qs = query.EmptyQuerySet()
    if permissions:
        categories = DenormalizedCategoryUserRole.objects.categories_by_user_and_permission(user, permissions)
    else:
        categories = DenormalizedCategoryUserRole.objects.categories_by_user(user)
    if categories:
        if queryset.model == Category:
            qs = q.filter( pk__in=categories )
        else:
            lookup = '%s__in' % category_fk.name
            qs = q.filter(**{lookup: categories})
    return qs