<commit_before>"""
Views for the taxonomy app
"""
from __future__ import unicode_literals

from django.shortcuts import (
    render,
    redirect,
    get_object_or_404,
)

from .forms import VocabularyForm
from learningresources.models import Repository
from taxonomy.models import Vocabulary


def create_vocabulary(request, repository_id):
    """
    Show form to create a new vocabulary
    """
    form = VocabularyForm()

    repository = get_object_or_404(Repository, id=repository_id)

    if request.method == "POST":
        form = VocabularyForm(request.POST)

        form.instance.repository = repository
        form.instance.required = False
        form.instance.weight = 1000
        if form.is_valid():
            form.save()
            return redirect(
                'taxonomy:edit_vocabulary',
                vocabulary_id=form.instance.id,
                repository_id=repository_id,
            )

        return render(
            request,
            "vocabulary.html",
            {
                'form': form,
                'repository_id': repository_id,
            }
        )

    return render(
        request,
        "vocabulary.html",
        {
            'form': form,
            'repository_id': repository_id,
        }
    )


def edit_vocabulary(request, repository_id, vocabulary_id):
    """
    Show form to edit an existing vocabulary
    """
    vocabulary = get_object_or_404(Vocabulary, id=vocabulary_id)
    form = VocabularyForm(instance=vocabulary)

    repository = get_object_or_404(Repository, id=repository_id)
    form.instance.repository = repository
    form.instance.required = False
    form.instance.weight = 1000

    if request.method == "POST":
        form = VocabularyForm(request.POST)

        form.instance.repository = repository
        form.instance.required = False
        form.instance.weight = 1000
        if form.is_valid():
            form.save()
            return redirect(
                'taxonomy:edit_vocabulary',
                vocabulary_id=form.instance.id,
                repository_id=repository_id,
            )

        return render(
            request,
            "vocabulary.html",
            {
                'form': form,
                'vocabulary_id': vocabulary_id,
                'repository_id': repository_id,<commit_msg>Pass instance so Django knows this is an update<commit_after>"""
Views for the taxonomy app
"""
from __future__ import unicode_literals

from django.shortcuts import (
    render,
    redirect,
    get_object_or_404,
)

from .forms import VocabularyForm
from learningresources.models import Repository
from taxonomy.models import Vocabulary


def create_vocabulary(request, repository_id):
    """
    Show form to create a new vocabulary
    """
    form = VocabularyForm()

    repository = get_object_or_404(Repository, id=repository_id)

    if request.method == "POST":
        form = VocabularyForm(request.POST)

        form.instance.repository = repository
        form.instance.required = False
        form.instance.weight = 1000
        if form.is_valid():
            form.save()
            return redirect(
                'taxonomy:edit_vocabulary',
                vocabulary_id=form.instance.id,
                repository_id=repository_id,
            )

        return render(
            request,
            "vocabulary.html",
            {
                'form': form,
                'repository_id': repository_id,
            }
        )

    return render(
        request,
        "vocabulary.html",
        {
            'form': form,
            'repository_id': repository_id,
        }
    )


def edit_vocabulary(request, repository_id, vocabulary_id):
    """
    Show form to edit an existing vocabulary
    """
    vocabulary = get_object_or_404(Vocabulary, id=vocabulary_id)
    form = VocabularyForm(instance=vocabulary)

    repository = get_object_or_404(Repository, id=repository_id)
    form.instance.repository = repository
    form.instance.required = False
    form.instance.weight = 1000

    if request.method == "POST":
        form = VocabularyForm(request.POST, instance=vocabulary)

        form.instance.repository = repository
        form.instance.required = False
        form.instance.weight = 1000
        if form.is_valid():
            form.save()
            return redirect(
                'taxonomy:edit_vocabulary',
                vocabulary_id=form.instance.id,
                repository_id=repository_id,
            )

        return render(
            request,
            "vocabulary.html",
            {
                'form': form,
                'vocabulary_id': vocabulary_id,
                'repository_id': repository_id,
{'fraction_non_alphanumeric': 0.08419280151547043, 'fraction_numerical': 0.01010313618185645, 'mean_word_length': 1.9774436090225564, 'pattern_counts': {'":': 4, '<': 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': '6391868', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1274, 'n_words': 272}