Exemple #1
0
def tokeninput_json(request):
    from resrc.utils import slugify
    from taggit.models import Tag
    from django.db.models import Count

    query = request.GET.get('q')
    result = None
    if query is None:
        #result = cache.get("tokeninput-_everything_")
        if result is None :
            tags_json = Tag.objects.all().select_related('links') \
                .annotate(freq=Count('link')) \
                .values('id', 'name', 'freq')
            result = simplejson.dumps(list(tags_json))
            cache.set("tokeninput-_everything_", result)
    else:
        #result = cache.get("tokeninput-%s" % slugify(query))
        if result is None :
            from taggit.models import Tag
            tags_json = Tag.objects.filter(name__icontains=query) \
                .select_related('links').annotate(freq=Count('link')) \
                .values('id', 'name', 'freq')
            result = simplejson.dumps(list(tags_json))
            cache.set("tokeninput-%s" % slugify(query), result)

    return HttpResponse(result, mimetype="application/javascript")
Exemple #2
0
def tokeninput_json(request):
    from resrc.utils import slugify
    from taggit.models import Tag
    from django.db.models import Count

    query = request.GET.get('q')
    result = None
    if query is None:
        #result = cache.get("tokeninput-_everything_")
        if result is None :
            tags_json = Tag.objects.all().select_related('links') \
                .annotate(freq=Count('link')) \
                .values('id', 'name', 'freq')
            result = simplejson.dumps(list(tags_json))
            cache.set("tokeninput-_everything_", result)
    else:
        #result = cache.get("tokeninput-%s" % slugify(query))
        if result is None :
            from taggit.models import Tag
            tags_json = Tag.objects.filter(name__icontains=query) \
                .select_related('links').annotate(freq=Count('link')) \
                .values('id', 'name', 'freq')
            result = simplejson.dumps(list(tags_json))
            cache.set("tokeninput-%s" % slugify(query), result)

    return HttpResponse(result, mimetype="application/javascript")
Exemple #3
0
    def do_unique_slug(self):
        """
        Ensures that the slug is always unique for this post
        """
        if not self.id:
            # make sure we have a slug first
            if not len(self.slug.strip()):
                self.slug = slugify(self.user.username)

            self.slug = self.get_unique_slug(self.slug)
            return True

        return False
Exemple #4
0
    def do_unique_slug(self):
        """
        Ensures that the slug is always unique for this post
        """
        if not self.id:
            # make sure we have a slug first
            if not len(self.slug.strip()):
                self.slug = slugify(self.user.username)

            self.slug = self.get_unique_slug(self.slug)
            return True

        return False