def index_tag(req): images = UserImage.objects.public_only(req.user) #print 'index_tag 1:', images.query form = TagSearchForm(req.GET) tag = None if form.is_valid(): query = form.cleaned_data.get('query') exact = form.cleaned_data.get('exact') if query: if exact: try: tag = Tag.objects.filter(text__iexact=query).get() images = images.filter(tags=tag) except Tag.DoesNotExist: images = UserImage.objects.none() else: images = images.filter(tags__text__icontains=query) images = images.distinct() #print 'index_tag 2:', images.query context = { 'tag_search_form': form, 'tag': tag, } return index(req, images, 'user_image/index_tag.html', context)
def index_tag(req): images = UserImage.objects.public_only(req.user) #print 'index_tag 1:', images.query form = TagSearchForm(req.GET) tag = None if form.is_valid(): query = form.cleaned_data.get('query') exact = form.cleaned_data.get('exact') if query: if exact: try: tags = Tag.objects.filter(text__iexact=query) if tags.count() > 1: # More than one match: do case-sensitive query ctags = Tag.objects.filter(text=query) # note, 'text' is the primary key, so >1 shouldn't be possible if len(ctags) == 1: tag = ctags[0] else: # Uh, multiple case-insensitive matches but no case-sens # matches. Arbitrarily choose first case-insens tag = tags[0] else: tag = tags[0] images = images.filter(tags=tag) except Tag.DoesNotExist: images = UserImage.objects.none() else: images = images.filter(tags__text__icontains=query) images = images.distinct() #print 'index_tag 2:', images.query context = { 'tag_search_form': form, 'tag': tag, } return index(req, images, 'user_image/index_tag.html', context)