How to use the coderedcms.models.snippet_models.ClassifierTerm.objects.filter function in coderedcms

To help you get started, we’ve selected a few coderedcms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coderedcorp / coderedcms / coderedcms / models / page_models.py View on Github external
all_children = self.get_index_children()
            # Filter by classifier terms if applicable
            if len(request.GET) > 0 and self.index_classifiers.exists():
                # Look up comma separated ClassifierTerm slugs i.e. `/?c=term1-slug,term2-slug`
                terms = []
                get_c = request.GET.get('c', None)
                if get_c:
                    terms = get_c.split(',')
                # Else look up individual querystrings i.e. `/?classifier-slug=term1-slug`
                else:
                    for classifier in self.index_classifiers.all().only('slug'):
                        get_term = request.GET.get(classifier.slug, None)
                        if get_term:
                            terms.append(get_term)
                if len(terms) > 0:
                    selected_terms = ClassifierTerm.objects.filter(slug__in=terms)
                    context['selected_terms'] = selected_terms
                    if len(selected_terms) > 0:
                        try:
                            for term in selected_terms:
                                all_children = all_children.filter(classifier_terms=term)
                        except AttributeError:
                            logger.warning(
                                "Tried to filter by ClassifierTerm, but <%s.%s ('%s')>.get_index_children() did not return a queryset or is not a queryset of CoderedPage models.",  # noqa
                                self._meta.app_label,
                                self.__class__.__name__,
                                self.title
                            )
            paginator = Paginator(all_children, self.index_num_per_page)
            pagenum = request.GET.get('p', 1)
            try:
                paged_children = paginator.page(pagenum)
github coderedcorp / coderedcms / coderedcms / models / snippet_models.py View on Github external
def save(self, *args, **kwargs):
        if not self.slug:
            # Make a slug and suffix a number if it already exists to ensure uniqueness
            newslug = slugify(self.name, allow_unicode=True)
            tmpslug = newslug
            suffix = 1
            while True:
                if not ClassifierTerm.objects.filter(slug=tmpslug).exists():
                    self.slug = tmpslug
                    break
                tmpslug = newslug + "-" + str(suffix)
                suffix += 1
        return super().save(*args, **kwargs)