<commit_before>""" View functions for tag related things

This includes both viewing the tag list, and manipulating tags on other things.
"""
from django.contrib.auth.decorators import login_required
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import defaultfilters
from django.template.response import TemplateResponse
from django.views.decorators.http import require_POST
import six

from tags.models import Tag
from tags.forms import AddTagForm, RemoveTagForm, RenameTagForm
import tags
from bookmarks.models import Bookmark
from .templatetags.tag import tagBlock

@login_required
def home(request):
    """ Uses index.html to display a list of all the user's tags """
    ctx = {}
    
    ctx["area"] = "tags"
    ctx["tags"] = Tag.by_user(request.user)
    ctx["atf"] = AddTagForm({"type":"tag"})
    ctx["rtf"] = RemoveTagForm({"type":"tag"})
    
    return TemplateResponse(request, "tags/index.html", ctx)


@login_required
def filter(request, tag):
    """ Given a slug, uses filter.html to display all the things tagged with that specific tag """
    tag = get_object_or_404(Tag, owner=request.user, slug=defaultfilters.slugify(tag))
    
    ctx = {}
    
    ctx["area"] = "tags"
    ctx["bookmarks"] = Bookmark.get_by_tag(tag)
    ctx["tag"] = tag
    ctx["atf"] = AddTagForm({"type":"tag"})
    ctx["rtf"] = RemoveTagForm({"type":"tag"})
    ctx["batf"] = AddTagForm({"type":"bookmark"})
    ctx["brtf"] = RemoveTagForm({"type":"kookmark"})
    
    return TemplateResponse(request, "tags/filter.html", ctx)

@login_required
def suggest(request, value):
    """ Returns a JSON object containing tag suggestions for the sepecified value
    
    The JSON object contains two values:
    - yours: The string that was submitted to this page
    - tags: An array of strings for the suggestions<commit_msg>Remove tag form on tag page spelt type correctly<commit_after>""" View functions for tag related things

This includes both viewing the tag list, and manipulating tags on other things.
"""
from django.contrib.auth.decorators import login_required
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import defaultfilters
from django.template.response import TemplateResponse
from django.views.decorators.http import require_POST
import six

from tags.models import Tag
from tags.forms import AddTagForm, RemoveTagForm, RenameTagForm
import tags
from bookmarks.models import Bookmark
from .templatetags.tag import tagBlock

@login_required
def home(request):
    """ Uses index.html to display a list of all the user's tags """
    ctx = {}
    
    ctx["area"] = "tags"
    ctx["tags"] = Tag.by_user(request.user)
    ctx["atf"] = AddTagForm({"type":"tag"})
    ctx["rtf"] = RemoveTagForm({"type":"tag"})
    
    return TemplateResponse(request, "tags/index.html", ctx)


@login_required
def filter(request, tag):
    """ Given a slug, uses filter.html to display all the things tagged with that specific tag """
    tag = get_object_or_404(Tag, owner=request.user, slug=defaultfilters.slugify(tag))
    
    ctx = {}
    
    ctx["area"] = "tags"
    ctx["bookmarks"] = Bookmark.get_by_tag(tag)
    ctx["tag"] = tag
    ctx["atf"] = AddTagForm({"type":"tag"})
    ctx["rtf"] = RemoveTagForm({"type":"tag"})
    ctx["batf"] = AddTagForm({"type":"bookmark"})
    ctx["brtf"] = RemoveTagForm({"type":"bookmark"})
    
    return TemplateResponse(request, "tags/filter.html", ctx)

@login_required
def suggest(request, value):
    """ Returns a JSON object containing tag suggestions for the sepecified value
    
    The JSON object contains two values:
    - yours: The string that was submitted to this page
    - tags: An array of strings for the suggestions
{'fraction_non_alphanumeric': 0.11381697000769034, 'fraction_numerical': 0.0030761343245321714, 'mean_word_length': 4.411927877947296, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3164070', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1120, 'n_words': 361}