# Path: narrative/models.py
# class Datum(models.Model):
#     # When was the datum created
#     timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
#     expiration_time = models.DateTimeField(null=True, blank=True, default=None)
#     # Origin of this datum; ie, what piece of software created it
#     origin = models.CharField(max_length=64)
#     datum_name = models.CharField(max_length=64)
# 
#     # Additional information about the datum; this is very datum specific
#     # This approach, storing json in a textfield and having an
#     # explicit accessor and mutator, is very ugly.  Really this is because
#     # we are storing non-structured/sparse data in a relational format.
#     datum_note_json = models.TextField(null=True, blank=True, default=None)
# 
#     # An ID to tie particular datums together
#     thread_id = models.CharField(max_length=36, null=True, blank=True)
# 
#     log_level = models.IntegerField(choices=DatumLogLevel.types, default=DatumLogLevel.INFO)
# 
#     objects = DatumManager()
# 
#     def __init__(self, *args, **kwargs):
#         if 'ttl' in kwargs:
#             kwargs['expiration_time'] = self.get_utc_now() + kwargs.pop('ttl')
# 
#         super(Datum, self).__init__(*args, **kwargs)
# 
#     def __str__(self):
#         note_snippet = self.datum_note_json[:50] if self.datum_note_json else ''
#         return 'origin:{0} datum_name:{1} note:{2}'.format(
#             self.origin, self.datum_name, note_snippet
#         )
# 
#     def get_note(self):
#         if self.datum_note_json:
#             return json.loads(self.datum_note_json)
#         else:
#             return []
# 
#     def set_note(self, note):
#         self.datum_note_json = json.dumps(note)
# 
#     def get_utc_now(self):
#         return utc_tz.localize(datetime.datetime.utcnow())
# 
#     @property
#     def timestamp_with_tz(self):
#         return utc_tz.localize(self.timestamp)
# 
#     def save(self, *args, **kwargs):
#         if None == self.thread_id:
#             self.thread_id = str(uuid.uuid4())
# 
#         super(Datum, self).save(*args, **kwargs)


from optparse import make_option
from django.core.management.base import BaseCommand
from narrative.models import Datum




class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option(
            '--verbose', action='store_true', dest='verbose', default=False,
            help='Determines if this command should in verbose mode'),)
    help = (
        'Clear any expired events')

    def handle(self, *args, **options):

# Path: narrative/models.py
# class Datum(models.Model):
#     # When was the datum created
#     timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
#     expiration_time = models.DateTimeField(null=True, blank=True, default=None)
#     # Origin of this datum; ie, what piece of software created it
#     origin = models.CharField(max_length=64)
#     datum_name = models.CharField(max_length=64)
# 
#     # Additional information about the datum; this is very datum specific
#     # This approach, storing json in a textfield and having an
#     # explicit accessor and mutator, is very ugly.  Really this is because
#     # we are storing non-structured/sparse data in a relational format.
#     datum_note_json = models.TextField(null=True, blank=True, default=None)
# 
#     # An ID to tie particular datums together
#     thread_id = models.CharField(max_length=36, null=True, blank=True)
# 
#     log_level = models.IntegerField(choices=DatumLogLevel.types, default=DatumLogLevel.INFO)
# 
#     objects = DatumManager()
# 
#     def __init__(self, *args, **kwargs):
#         if 'ttl' in kwargs:
#             kwargs['expiration_time'] = self.get_utc_now() + kwargs.pop('ttl')
# 
#         super(Datum, self).__init__(*args, **kwargs)
# 
#     def __str__(self):
#         note_snippet = self.datum_note_json[:50] if self.datum_note_json else ''
#         return 'origin:{0} datum_name:{1} note:{2}'.format(
#             self.origin, self.datum_name, note_snippet
#         )
# 
#     def get_note(self):
#         if self.datum_note_json:
#             return json.loads(self.datum_note_json)
#         else:
#             return []
# 
#     def set_note(self, note):
#         self.datum_note_json = json.dumps(note)
# 
#     def get_utc_now(self):
#         return utc_tz.localize(datetime.datetime.utcnow())
# 
#     @property
#     def timestamp_with_tz(self):
#         return utc_tz.localize(self.timestamp)
# 
#     def save(self, *args, **kwargs):
#         if None == self.thread_id:
#             self.thread_id = str(uuid.uuid4())
# 
#         super(Datum, self).save(*args, **kwargs)


# Path: narrative/management/commands/clear_expired_data.py
from optparse import make_option
from django.core.management.base import BaseCommand
from narrative.models import Datum





class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option(
            '--verbose', action='store_true', dest='verbose', default=False,
            help='Determines if this command should in verbose mode'),)
    help = (
        'Clear any expired events')

    def handle(self, *args, **options):

        cleared_events = Datum.objects.clear_expired()