<commit_before>from datetime import datetime
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from log_register.managers import LotManager, LogManager
from log_register.settings import ERROR, DEBUG, SUCCESS, WARNING, INFO


class Lot(models.Model):
    """
    This model represents a lot of logs.
    * The 'register_start' field represents when the log was created, but doesn't represent the first log.
    * The 'register_end' field just represent when you end to register log for this lot, This field is set when you
    call the 'close' method.
    You must not set this field manually, but (like everything in python) you can, of course. :)
    * The 'single' field represents that this Lot is a unique (must be) lot instance for a particular object in
    database.
    You must not set this field manually, but (like everything in python) you can, of course. :)
    * The 'content_type', 'object_id' and 'lot_object' fields represent (polymorphically) the object
    in database, where happen the logs.
    If single is False (be default it's just like that), the three field don't make sense (For me and my mind)

    See the examples (When I'll write them :) )
    """
    register_start = models.DateField(auto_now_add=True)
    register_end = models.DateField(blank=True, null=True)

    single = models.BooleanField(default=False)
    content_type = models.ForeignKey(ContentType, null=True, blank=True)
    object_id = models.PositiveIntegerField(null=True, blank=True)
    lot_object = generic.GenericForeignKey()

    objects = LotManager()

    def close(self):
        """
        This method set the current date time and, by convention, you wont log
         anything with it. but you can :)
        """
        self.register_end = datetime.now()
        self.save()
        return self

    def info_count(self):
        """
        Return the count of info logs
        """
        level = INFO
        return self.__get_count(level)

    def debug_count(self):
        """
        Return the count of debug logs
        """
        level = DEBUG
        return self.__get_count(level)

    def warning_count(self):
        """
        Return the count of warning logs
        """
        level = WARNING
        return self.__get_count(level)

    def error_count(self):
        """
        Return the count of error logs
        """
        level = ERROR
        return self.__get_count(level)

    def success_count(self):
        """
        Return the count of success logs
        """
        level = SUCCESS
        return self.__get_count(level)

    def success(self, reason, extra_data="", log_object=None):
        """
        Register a successful log.
        """
        level = SUCCESS
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def warning(self, reason, extra_data="", log_object=None):
        """
        Register a warning log.
        """
        level = WARNING
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def info(self, reason, extra_data="", log_object=None):
        """
        Register a info log.
        """
        level = INFO
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def error(self, reason, extra_data="", log_object=None):
        """
        Register a error log.
        """
        level = ERROR
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def debug(self, reason, extra_data="", log_object=None):
        """
        Register a debug log.
        """
        level = DEBUG
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def log(self, reason, extra_data="", level=INFO, log_object=None):
        """
        Register a log.
        Only the param 'reason' it's required.
        """
        log = Log(reason=reason, extra_data=extra_data, level=level)
        if not log_object is None:
            log.log_object = log_object
        log.save()
        return log

    def __get_count(self, level):
        count = self.logs.filter(lovel=level).count()
        return count


class Log(models.Model):
    """
    This method represent the a log of something that happen.
    Only the 'lot' and 'reason' field are required.

    * The 'reason' field represents the answer for "Why this log happen?" (See the examples)
    * The 'extra_date' field represent the the answer for "What is the context of this log?",<commit_msg>Fix bad kwarg argument<commit_after>from datetime import datetime
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from log_register.managers import LotManager, LogManager
from log_register.settings import ERROR, DEBUG, SUCCESS, WARNING, INFO


class Lot(models.Model):
    """
    This model represents a lot of logs.
    * The 'register_start' field represents when the log was created, but doesn't represent the first log.
    * The 'register_end' field just represent when you end to register log for this lot, This field is set when you
    call the 'close' method.
    You must not set this field manually, but (like everything in python) you can, of course. :)
    * The 'single' field represents that this Lot is a unique (must be) lot instance for a particular object in
    database.
    You must not set this field manually, but (like everything in python) you can, of course. :)
    * The 'content_type', 'object_id' and 'lot_object' fields represent (polymorphically) the object
    in database, where happen the logs.
    If single is False (be default it's just like that), the three field don't make sense (For me and my mind)

    See the examples (When I'll write them :) )
    """
    register_start = models.DateField(auto_now_add=True)
    register_end = models.DateField(blank=True, null=True)

    single = models.BooleanField(default=False)
    content_type = models.ForeignKey(ContentType, null=True, blank=True)
    object_id = models.PositiveIntegerField(null=True, blank=True)
    lot_object = generic.GenericForeignKey()

    objects = LotManager()

    def close(self):
        """
        This method set the current date time and, by convention, you wont log
         anything with it. but you can :)
        """
        self.register_end = datetime.now()
        self.save()
        return self

    def info_count(self):
        """
        Return the count of info logs
        """
        level = INFO
        return self.__get_count(level)

    def debug_count(self):
        """
        Return the count of debug logs
        """
        level = DEBUG
        return self.__get_count(level)

    def warning_count(self):
        """
        Return the count of warning logs
        """
        level = WARNING
        return self.__get_count(level)

    def error_count(self):
        """
        Return the count of error logs
        """
        level = ERROR
        return self.__get_count(level)

    def success_count(self):
        """
        Return the count of success logs
        """
        level = SUCCESS
        return self.__get_count(level)

    def success(self, reason, extra_data="", log_object=None):
        """
        Register a successful log.
        """
        level = SUCCESS
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def warning(self, reason, extra_data="", log_object=None):
        """
        Register a warning log.
        """
        level = WARNING
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def info(self, reason, extra_data="", log_object=None):
        """
        Register a info log.
        """
        level = INFO
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def error(self, reason, extra_data="", log_object=None):
        """
        Register a error log.
        """
        level = ERROR
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def debug(self, reason, extra_data="", log_object=None):
        """
        Register a debug log.
        """
        level = DEBUG
        log = self.log(reason=reason, extra_data=extra_data, level=level, log_object=log_object)
        return log

    def log(self, reason, extra_data="", level=INFO, log_object=None):
        """
        Register a log.
        Only the param 'reason' it's required.
        """
        log = Log(reason=reason, extra_data=extra_data, level=level)
        if not log_object is None:
            log.log_object = log_object
        log.save()
        return log

    def __get_count(self, level):
        count = self.logs.filter(level=level).count()
        return count


class Log(models.Model):
    """
    This method represent the a log of something that happen.
    Only the 'lot' and 'reason' field are required.

    * The 'reason' field represents the answer for "Why this log happen?" (See the examples)
    * The 'extra_date' field represent the the answer for "What is the context of this log?",
{'fraction_non_alphanumeric': 0.0910333228214023, 'fraction_numerical': 0.0, 'mean_word_length': 2.5659670164917543, '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': '3705501', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2575, 'n_words': 906}