# Path: djangoevents/unifiedtranscoder.py
# class UnifiedTranscoder(AbstractTranscoder):
# class ResolveDomainFailed(Exception):
#     def __init__(self, json_encoder_cls=None):
#     def serialize(self, domain_event):
#     def deserialize(self, stored_event):
#     def _get_domain_event_class(module_name, class_name):
#     def _json_encode(self, data):
#     def _json_decode(self, json_str):
# def get_aggregate_type(domain_event):
# def get_event_type(domain_event):
# 
# Path: djangoevents/exceptions.py
# class AlreadyExists(DjangoeventsError):
#     pass


from .unifiedtranscoder import UnifiedStoredEvent
from django.conf import settings
from django.db.utils import IntegrityError
from django.utils import timezone
from djangoevents.exceptions import AlreadyExists
from eventsourcing.domain.services.eventstore import AbstractStoredEventRepository
from eventsourcing.domain.services.eventstore import EntityVersionDoesNotExist
from eventsourcing.domain.services.transcoding import EntityVersion
from eventsourcing.utils.time import timestamp_from_uuid
        from .models import Event  # import model at runtime for making top level import possible
import datetime
        events = self.EventModel.objects.filter(stored_entity_id=stored_entity_id)
        if query_ascending:
            events = events.order_by('id')
        else:
            events = events.order_by('-id')

        if after is not None:
            after_ts = datetime.datetime.fromtimestamp(timestamp_from_uuid(after))
            if query_ascending:
                events = events.filter(create_date__gt=after_ts)
            else:
                events = events.filter(create_date__gte=after_ts)

        if until is not None:
            until_ts = datetime.datetime.fromtimestamp(timestamp_from_uuid(until))
            if query_ascending:
                events = events.filter(create_date__lte=until_ts)
            else:
                events = events.filter(create_date__lt=until_ts)

        if limit is not None:
            events = events[:limit]

        events = list(events)
        if results_ascending != query_ascending:
            events.reverse()
        return [from_model_instance(e) for e in events]


def from_model_instance(event):

# Path: djangoevents/unifiedtranscoder.py
# class UnifiedTranscoder(AbstractTranscoder):
# class ResolveDomainFailed(Exception):
#     def __init__(self, json_encoder_cls=None):
#     def serialize(self, domain_event):
#     def deserialize(self, stored_event):
#     def _get_domain_event_class(module_name, class_name):
#     def _json_encode(self, data):
#     def _json_decode(self, json_str):
# def get_aggregate_type(domain_event):
# def get_event_type(domain_event):
# 
# Path: djangoevents/exceptions.py
# class AlreadyExists(DjangoeventsError):
#     pass


# Path: djangoevents/repository.py
from .unifiedtranscoder import UnifiedStoredEvent
from django.conf import settings
from django.db.utils import IntegrityError
from django.utils import timezone
from djangoevents.exceptions import AlreadyExists
from eventsourcing.domain.services.eventstore import AbstractStoredEventRepository
from eventsourcing.domain.services.eventstore import EntityVersionDoesNotExist
from eventsourcing.domain.services.transcoding import EntityVersion
from eventsourcing.utils.time import timestamp_from_uuid
        from .models import Event  # import model at runtime for making top level import possible
import datetime

        events = self.EventModel.objects.filter(stored_entity_id=stored_entity_id)
        if query_ascending:
            events = events.order_by('id')
        else:
            events = events.order_by('-id')

        if after is not None:
            after_ts = datetime.datetime.fromtimestamp(timestamp_from_uuid(after))
            if query_ascending:
                events = events.filter(create_date__gt=after_ts)
            else:
                events = events.filter(create_date__gte=after_ts)

        if until is not None:
            until_ts = datetime.datetime.fromtimestamp(timestamp_from_uuid(until))
            if query_ascending:
                events = events.filter(create_date__lte=until_ts)
            else:
                events = events.filter(create_date__lt=until_ts)

        if limit is not None:
            events = events[:limit]

        events = list(events)
        if results_ascending != query_ascending:
            events.reverse()
        return [from_model_instance(e) for e in events]


def from_model_instance(event):

    return UnifiedStoredEvent(