<commit_before>from django.conf import settings
from django.db import models
from django.utils import timezone

class Category(models.Model):
  parent = models.ForeignKey("self", null=True, blank=True)
  name = models.CharField(max_length=255)
  description = models.CharField(max_length=255, blank=True)

  def __str__(self):
    return self.name

  class Meta:
    verbose_name_plural = 'categories'

class Entry(models.Model):
  user = models.ForeignKey(settings.AUTH_USER_MODEL)
  category = models.ForeignKey(Category)
  # TODO: Validate tz_begin and tz_end are valid time zones.
  t_begin = models.DateTimeField('t_begin')
  tz_begin = models.CharField(max_length=255, default=str(timezone.get_current_timezone()))
  t_end = models.DateTimeField('t_end', null=True, blank=True)
  tz_end = models.CharField(max_length=255, default=str(timezone.get_current_timezone()))
  description = models.CharField(max_length=255, blank=True)

  def __str__(self):
    return str(self.user) + ', ' + str(self.category) + ' @ ' \
      + str(self.t_begin) + ' - ' + str(self.t_end)

  class Meta:
    verbose_name_plural = 'entries'<commit_msg>Initial work on making use of models.Entry tz_begin and tz_end time zones by using them to modify the time stamps when saving an entry.<commit_after>from django.conf import settings
from django.db import models
from django.utils import timezone

class Category(models.Model):
  parent = models.ForeignKey("self", null=True, blank=True)
  name = models.CharField(max_length=255)
  description = models.CharField(max_length=255, blank=True)

  def __str__(self):
    return self.name

  class Meta:
    verbose_name_plural = 'categories'

class Entry(models.Model):
  user = models.ForeignKey(settings.AUTH_USER_MODEL)
  category = models.ForeignKey(Category)
  # TODO: Validate tz_begin and tz_end are valid time zones.
  t_begin = models.DateTimeField('t_begin')
  tz_begin = models.CharField(max_length=255, default=str(timezone.get_current_timezone()))
  t_end = models.DateTimeField('t_end', null=True, blank=True)
  tz_end = models.CharField(max_length=255, default=str(timezone.get_current_timezone()))
  description = models.CharField(max_length=255, blank=True)

  def save (self, *args, **kwargs):
    self.t_begin = timezone.make_naive(self.t_begin, timezone.get_current_timezone())
    timezone.activate(self.tz_begin)
    self.t_begin = timezone.make_aware(self.t_begin, timezone.get_current_timezone())
    timezone.deactivate()

    self.t_end = timezone.make_naive(self.t_end, timezone.get_current_timezone())
    timezone.activate(self.tz_end)
    self.t_end = timezone.make_aware(self.t_end, timezone.get_current_timezone())
    timezone.deactivate()

    super(Entry, self).save(*args, **kwargs)

  def __str__(self):
    return str(self.user) + ', ' + str(self.category) + ' @ ' \
      + str(self.t_begin) + ' - ' + str(self.t_end)

  class Meta:
    verbose_name_plural = 'entries'
{'fraction_non_alphanumeric': 0.11920980926430517, 'fraction_numerical': 0.010217983651226158, 'mean_word_length': 5.068181818181818, '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': '279295', 'n_tokens_mistral': 1012, 'n_tokens_neox': 967, 'n_words': 190}