<commit_before>import os
import logging
import mistune

from django.db import transaction
from django.contrib import messages

from .models import Model, LatestModel, Change, Category, Location
from .utils import MODEL_DIR

from .markdown import markdown

logger = logging.getLogger(__name__)

def upload(model_file, options={}):
    try:
        with transaction.atomic():
            m = Model.objects.filter(model_id=options['model_id']).latest('id', 'revision')

            if options.get('revision', False):
                location = m.location
                if location is not None:
                    location.pk = None
                    location.id = None
                    location.save()

                m.pk = None
                m.id = None
                m.revision += 1
                m.author = options['author']
                m.location = location
                m.save()

                m.categories.add(*lm.categories.all())
                m.save()
            else:
                # get the model_id for this model.
                try:
                    next_model_id = m.model_id + 1
                except LatestModel.DoesNotExist:
                    next_model_id = 1 # no models in db<commit_msg>Might not be necessary but want latest revision qualified by id not other way around.<commit_after>import os
import logging
import mistune

from django.db import transaction
from django.contrib import messages

from .models import Model, LatestModel, Change, Category, Location
from .utils import MODEL_DIR

from .markdown import markdown

logger = logging.getLogger(__name__)

def upload(model_file, options={}):
    try:
        with transaction.atomic():
            m = Model.objects.filter(model_id=options['model_id']).latest('revision', 'id')

            if options.get('revision', False):
                location = m.location
                if location is not None:
                    location.pk = None
                    location.id = None
                    location.save()

                m.pk = None
                m.id = None
                m.revision += 1
                m.author = options['author']
                m.location = location
                m.save()

                m.categories.add(*lm.categories.all())
                m.save()
            else:
                # get the model_id for this model.
                try:
                    next_model_id = m.model_id + 1
                except LatestModel.DoesNotExist:
                    next_model_id = 1 # no models in db
{'fraction_non_alphanumeric': 0.08176838810641628, 'fraction_numerical': 0.002347417840375587, 'mean_word_length': 1.5417495029821073, 'pattern_counts': {'":': 0, '<': 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': '654619', 'n_tokens_mistral': 674, 'n_tokens_neox': 621, 'n_words': 189}