def filtered_tags(context, list, keywords, region_slug=None):
    list = list or []
    keywords = keywords or []
    unused = set(list)
    filtered = []
    for word in keywords:
        for tag in unused:
            if word.lower() in tag.lower():
                filtered.append(tag)
                unused.remove(tag)
                break
    if not filtered:
        return ''

    if region_slug:
        context['global'] = False
        tags = [{
            'name': t,
            'slug': slugify(t),
            'region': {
                'slug': region_slug
            }
        } for t in filtered]
    else:
        context['global'] = True
        tags = [{'name': t, 'slug': slugify(t)} for t in filtered]

    context = copy(context)
    context.update({'tag_list': tags})
    return render_to_string('tags/tag_list_snippet.html', context)
Exemple #2
0
    def get_queryset(self):
        import tags.models as tags

        qs = super(MapGlobalView, self).get_queryset()
        self.tag = tags.Tag.objects.get(slug=tags.slugify(self.kwargs["tag"]))
        tagsets = tags.PageTagSet.objects.filter(tags=self.tag)
        pages = Page.objects.filter(pagetagset__in=tagsets)
        return MapData.objects.filter(page__in=pages).order_by("-length")
Exemple #3
0
    def get_queryset(self):
        import tags.models as tags

        qs = super(MapGlobalView, self).get_queryset()
        self.tag = tags.Tag.objects.get(slug=tags.slugify(self.kwargs['tag']))
        tagsets = tags.PageTagSet.objects.filter(tags=self.tag)
        pages = Page.objects.filter(pagetagset__in=tagsets)
        return qs.filter(page__in=pages)
Exemple #4
0
 def get_queryset(self):
     self.tag_name = slugify(self.kwargs['slug'])
     try:
         self.tag = Tag.objects.get(slug=self.tag_name)
         self.tag_name = self.tag.name
         return PageTagSet.objects.filter(tags=self.tag)
     except Tag.DoesNotExist:
         self.tag = None
         return PageTagSet.objects.none()
Exemple #5
0
 def get_queryset(self):
     self.tag_name = slugify(self.kwargs['slug'])
     try:
         self.tag = Tag.objects.get(slug=self.tag_name)
         self.tag_name = self.tag.name
         return PageTagSet.objects.filter(tags=self.tag)
     except Tag.DoesNotExist:
         self.tag = None
         return PageTagSet.objects.none()
    def get_queryset(self):
        import tags.models as tags

        qs = super(BaseMapRegionView, self).get_queryset()
        region = self.get_region()
        self.tag = tags.Tag.objects.get(slug=tags.slugify(self.kwargs['tag']),
                                        region=region)
        tagsets = tags.PageTagSet.objects.filter(tags=self.tag, region=region)
        pages = Page.objects.filter(pagetagset__in=tagsets, region=region)
        return MapData.objects.filter(page__in=pages).\
            select_related('page').defer('page__content').order_by('-length')
    def get_queryset(self):
        import tags.models as tags

        qs = super(BaseMapRegionView, self).get_queryset()
        region = self.get_region()
        self.tag = tags.Tag.objects.get(
            slug=tags.slugify(self.kwargs['tag']),
            region=region
        )
        tagsets = tags.PageTagSet.objects.filter(tags=self.tag, region=region)
        pages = Page.objects.filter(pagetagset__in=tagsets, region=region)
        return MapData.objects.filter(page__in=pages).\
            select_related('page').defer('page__content').order_by('-length')
def filtered_tags(context, list, keywords, region_slug=None):
    list = list or []
    keywords = keywords or []
    unused = set(list)
    filtered = []
    for word in keywords:
        for tag in unused:
            if word.lower() in tag.lower():
                filtered.append(tag)
                unused.remove(tag)
                break
    if not filtered:
        return ''

    if region_slug:
        context['global'] = False
        tags = [{'name': t, 'slug': slugify(t), 'region': {'slug': region_slug}} for t in filtered]
    else:
        context['global'] = True
        tags = [{'name': t, 'slug': slugify(t)} for t in filtered]

    context = copy(context)
    context.update({'tag_list': tags})
    return render_to_string('tags/tag_list_snippet.html', context)
Exemple #9
0
def filtered_tags(list, keywords):
    list = list or []
    keywords = keywords or []
    unused = set(list)
    filtered = []
    for word in keywords:
        for tag in unused:
            if word in tag:
                filtered.append(tag)
                unused.remove(tag)
                break
    if not filtered:
        return ''
    tags = [{'name': t, 'slug': slugify(t)} for t in filtered]
    return render_to_string('tags/tag_list_snippet.html', {'tag_list': tags})
Exemple #10
0
 def clean(self, value):
     if not value:
         if self.required:
             raise ValidationError(self.error_messages["required"])
         else:
             return []
     self.run_validators(value)
     keys = []
     for word in parse_tags(value):
         try:
             tag, created = Tag.objects.get_or_create(slug=slugify(word), defaults={"name": word})
             keys.append(tag.pk)
         except IntegrityError as e:
             raise ValidationError(e)
     return Tag.objects.filter(pk__in=keys)
Exemple #11
0
 def clean(self, value):
     if not value:
         if self.required:
             raise ValidationError(self.error_messages['required'])
         else:
             return []
     self.run_validators(value)
     keys = []
     for word in parse_tags(value):
         try:
             tag, created = Tag.objects.get_or_create(slug=slugify(word),
                                                  defaults={'name': word})
             keys.append(tag.pk)
         except IntegrityError as e:
             raise ValidationError(e)
     return Tag.objects.filter(pk__in=keys)
    def get_content(self, context):
        region = context["region"]
        try:
            self.tag = Tag.objects.get(slug=slugify(self.name), region=region)
        except Tag.DoesNotExist:
            context["tag_name"] = self.name
        else:
            view = TaggedList()
            view.kwargs = dict(slug=self.name, region=region.slug)
            view.request = context["request"]
            try:
                view.object_list = view.get_queryset()
            except Http404:
                view.object_list = []

            context = copy(context)
            context.update(view.get_context_data(object_list=view.object_list))

        return render_to_string("tags/tagged_list_snippet.html", context)
Exemple #13
0
 def __init__(self, *args, **kwargs):
     super(IncludeTagNode, self).__init__(*args, **kwargs)
     try:
         self.tag = Tag.objects.get(slug=slugify(self.name))
     except Tag.DoesNotExist:
         self.tag = None
 def get_or_create_tag(self, word):
     tag, created = Tag.objects.get_or_create(
         slug=slugify(word), region=self.region,
         defaults={'name': word}
     )
     return tag
Exemple #15
0
 def get_or_create_tag(self, word):
     tag, created = Tag.objects.get_or_create(slug=slugify(word),
                                              region=self.region,
                                              defaults={'name': word})
     return tag
Exemple #16
0
 def get_queryset(self):
     qs = super(MapGlobalView, self).get_queryset()
     self.tag = tags.Tag.objects.get(slug=tags.slugify(self.kwargs['tag']))
     tagsets = tags.PageTagSet.objects.filter(tags=self.tag)
     pages = Page.objects.filter(pagetagset__in=tagsets)
     return qs.filter(page__in=pages)
Exemple #17
0
 def __init__(self, *args, **kwargs):
     super(IncludeTagNode, self).__init__(*args, **kwargs)
     try:
         self.tag = Tag.objects.get(slug=slugify(self.name))
     except Tag.DoesNotExist:
         self.tag = None