# Path: threebot/models.py
# class WorkflowLog(models.Model):
#     SUCCESS = 0
#     ERROR = 1
#     PENDING = 2
# 
#     EXIT_CODE_CHOICES = (
#         (SUCCESS, 'Success'),
#         (ERROR, 'Error'),
#         (PENDING, 'Pending'),
#     )
# 
#     workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"))
#     date_created = models.DateTimeField(auto_now_add=True, help_text='Date the workflow was performed')
#     date_started = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     date_finished = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     exit_code = models.PositiveIntegerField(choices=EXIT_CODE_CHOICES, default=PENDING)
#     performed_by = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="The User who performed the Worfkflow")
#     performed_on = models.ForeignKey(Worker, help_text="The Worker Worfkflow was performed on")
# 
#     inputs = JSONField()
#     outputs = JSONField(null=True, blank=True)
# 
#     class Meta():
#         ordering = ['-date_created', ]
#         verbose_name = _("Workflow Log")
#         verbose_name_plural = _("Workflow Logs")
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_log_detail', (), {
#             'slug': self.workflow.slug,
#             'id': self.id})
# 
#     def permalink(self):
#         return reverse('core_workflow_log_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return "%s - %s logged %s" % (self.date_created.strftime('%d.%m.%y %H:%M'), str(self.performed_by), self.workflow.title, )
# 
# Path: threebot/utils.py
# @login_required
# def get_my_orgs(request, an_user=None):
#     if request is not None and an_user is None:
#         an_user = request.user
# 
#     default_org, created = Organization.objects.get_or_create(slug='3bot', name="3bot")
# 
#     if not OrganizationUser.objects.filter(organization=default_org, user=an_user).exists():
#         # we create an OrganizationUser, so each user is member of our default_org
#         # if default_org was just created, we also mark this user as admin and create an OrganizationOwner
#         org_user = OrganizationUser(organization=default_org, user=an_user, is_admin=created)
#         org_user.save()
#         if created:
#             org_owner = OrganizationOwner(organization=default_org, organization_user=org_user)
#             org_owner.save()
# 
#     orgs = Organization.objects.filter(users=an_user)
# 
#     return orgs


from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
from threebot.models import WorkflowLog
from threebot.utils import get_my_orgs



@login_required
def detail(request, id):
    orgs = get_my_orgs(request)

# Path: threebot/models.py
# class WorkflowLog(models.Model):
#     SUCCESS = 0
#     ERROR = 1
#     PENDING = 2
# 
#     EXIT_CODE_CHOICES = (
#         (SUCCESS, 'Success'),
#         (ERROR, 'Error'),
#         (PENDING, 'Pending'),
#     )
# 
#     workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"))
#     date_created = models.DateTimeField(auto_now_add=True, help_text='Date the workflow was performed')
#     date_started = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     date_finished = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     exit_code = models.PositiveIntegerField(choices=EXIT_CODE_CHOICES, default=PENDING)
#     performed_by = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="The User who performed the Worfkflow")
#     performed_on = models.ForeignKey(Worker, help_text="The Worker Worfkflow was performed on")
# 
#     inputs = JSONField()
#     outputs = JSONField(null=True, blank=True)
# 
#     class Meta():
#         ordering = ['-date_created', ]
#         verbose_name = _("Workflow Log")
#         verbose_name_plural = _("Workflow Logs")
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_log_detail', (), {
#             'slug': self.workflow.slug,
#             'id': self.id})
# 
#     def permalink(self):
#         return reverse('core_workflow_log_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return "%s - %s logged %s" % (self.date_created.strftime('%d.%m.%y %H:%M'), str(self.performed_by), self.workflow.title, )
# 
# Path: threebot/utils.py
# @login_required
# def get_my_orgs(request, an_user=None):
#     if request is not None and an_user is None:
#         an_user = request.user
# 
#     default_org, created = Organization.objects.get_or_create(slug='3bot', name="3bot")
# 
#     if not OrganizationUser.objects.filter(organization=default_org, user=an_user).exists():
#         # we create an OrganizationUser, so each user is member of our default_org
#         # if default_org was just created, we also mark this user as admin and create an OrganizationOwner
#         org_user = OrganizationUser(organization=default_org, user=an_user, is_admin=created)
#         org_user.save()
#         if created:
#             org_owner = OrganizationOwner(organization=default_org, organization_user=org_user)
#             org_owner.save()
# 
#     orgs = Organization.objects.filter(users=an_user)
# 
#     return orgs


# Path: threebot/views/api/log.py
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
from threebot.models import WorkflowLog
from threebot.utils import get_my_orgs




@login_required
def detail(request, id):
    orgs = get_my_orgs(request)

    log = get_object_or_404(WorkflowLog, id=id)