<commit_before>from datetime import datetime, timedelta

from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models

from fjord.base.models import ModelBase, JSONObjectField


RECORD_INFO = u'info'
RECORD_ERROR = u'error'


class RecordManager(models.Manager):
    @classmethod
    def log(cls, type_, app, src, action, msg, instance=None, metadata=None):
        msg = msg.encode('utf-8')
        metadata = metadata or {}

        rec = Record(
            app=app,
            type=type_,
            src=src,
            action=action,
            content_object=instance,
            msg=msg,
            metadata=metadata
        )
        rec.save()
        return rec

    def recent(self, app):
        return (self
                .filter(app=app)
                .filter(created__gte=datetime.now() - timedelta(days=7)))

    def records(self, instance):
        return (
            self
            .filter(object_id=instance.id,
                    content_type=ContentType.objects.get_for_model(instance))
        )


class Record(ModelBase):
    """Defines an audit record for something that happened in translations"""

    TYPE_CHOICES = [
        (RECORD_INFO, RECORD_INFO),
        (RECORD_ERROR, RECORD_ERROR),
    ]

    # What app does this apply to
    app = models.CharField(max_length=50)

    # What component was running (e.g. "gengo-machine", "dennis", ...)
    src = models.CharField(max_length=50)

    # The type of this message (e.g. "info", "error", ...)
    type = models.CharField(choices=TYPE_CHOICES, max_length=20)

    # What happened to create this entry (e.g. "guess-language",<commit_msg>Make journal.Record not derive from ModelBase<commit_after>from datetime import datetime, timedelta

from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models

from fjord.base.models import JSONObjectField


RECORD_INFO = u'info'
RECORD_ERROR = u'error'


class RecordManager(models.Manager):
    @classmethod
    def log(cls, type_, app, src, action, msg, instance=None, metadata=None):
        msg = msg.encode('utf-8')
        metadata = metadata or {}

        rec = Record(
            app=app,
            type=type_,
            src=src,
            action=action,
            content_object=instance,
            msg=msg,
            metadata=metadata
        )
        rec.save()
        return rec

    def recent(self, app):
        return (self
                .filter(app=app)
                .filter(created__gte=datetime.now() - timedelta(days=7)))

    def records(self, instance):
        return (
            self
            .filter(object_id=instance.id,
                    content_type=ContentType.objects.get_for_model(instance))
        )


class Record(models.Model):
    """Defines an audit record for something that happened in translations"""

    TYPE_CHOICES = [
        (RECORD_INFO, RECORD_INFO),
        (RECORD_ERROR, RECORD_ERROR),
    ]

    # What app does this apply to
    app = models.CharField(max_length=50)

    # What component was running (e.g. "gengo-machine", "dennis", ...)
    src = models.CharField(max_length=50)

    # The type of this message (e.g. "info", "error", ...)
    type = models.CharField(choices=TYPE_CHOICES, max_length=20)

    # What happened to create this entry (e.g. "guess-language",
{'fraction_non_alphanumeric': 0.10377906976744186, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 2.4103072348860257, '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': '7212844', 'n_tokens_mistral': 1033, 'n_tokens_neox': 978, 'n_words': 249}