# Path: status/models.py
# class Incident(BaseModel):
#     """ Creates an incident.  Incidents are displayed at the top of the page until closed. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     name = models.CharField(max_length=255)
#     hidden = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.user, self.name)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.pk, ])
# 
#     def get_first_update(self):
#         try:
#             first = self.incidentupdate_set.first()
#         except IncidentUpdate.DoesNotExist:
#             first = None
#         return first
# 
#     def get_latest_update(self):
#         try:
#             latest = self.incidentupdate_set.latest()
#         except IncidentUpdate.DoesNotExist:
#             latest = None
#         return latest
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident'
#         verbose_name_plural = 'Incidents'
#         ordering = ['-created', ]
# 
# class IncidentUpdate(BaseModel):
#     """ Updates about an incident. """
#     incident = models.ForeignKey(Incident)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     status = models.ForeignKey(Status)
#     description = models.TextField()
# 
#     def __unicode__(self):
#         return "%s - %s: %s" % (self.user, self.status, self.description)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.incident.pk, ])
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident Update'
#         verbose_name_plural = 'Incident Updates'
#         ordering = ['created', ]
# 
#     def save(self, *args, **kwargs):
#         """ Update the parent incident update time too. """
#         self.incident.updated = timezone.now()
#         self.incident.save()
#         super(IncidentUpdate, self).save(*args, **kwargs)
# 
# Path: status/forms.py
# class IncidentCreateForm(forms.ModelForm):
#     class Meta:
#         model = Incident
#         fields = ['name']
# 
# class IncidentUpdateCreateForm(forms.ModelForm):
#     class Meta:
#         model = IncidentUpdate
#         fields = ['status', 'description']


from datetime import date, timedelta
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from django.template import RequestContext, Template
from django.template.loader import get_template
from django.utils.decorators import method_decorator
from django.views.generic import (
    MonthArchiveView, YearArchiveView, CreateView, DeleteView, DetailView, ListView, TemplateView
)
from stronghold.decorators import public
from status.models import Incident, IncidentUpdate
from status.forms import IncidentCreateForm, IncidentUpdateCreateForm
import slack
import slack.chat
import logging
    model = IncidentUpdate
    form_class = IncidentUpdateCreateForm
    template_name = 'status/incident_form.html'

    def get_success_url(self):
        return reverse('status:incident_detail', args=[self.kwargs['pk']])

    def form_valid(self, form):
        iu = form.save(commit=False)
        i = Incident.objects.get(pk=self.kwargs['pk'])
        i.hidden = False
        i.save()
        iu.incident = i
        iu.incident.hidden = False
        iu.incident.save()
        iu.user = self.request.user
        iu.save()
        return HttpResponseRedirect(self.get_success_url())


class IncidentDetailView(DetailView):
    model = Incident

    @method_decorator(public)
    def dispatch(self, *args, **kwargs):
        return super(IncidentDetailView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(IncidentDetailView, self).get_context_data(**kwargs)
        context.update({

# Path: status/models.py
# class Incident(BaseModel):
#     """ Creates an incident.  Incidents are displayed at the top of the page until closed. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     name = models.CharField(max_length=255)
#     hidden = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.user, self.name)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.pk, ])
# 
#     def get_first_update(self):
#         try:
#             first = self.incidentupdate_set.first()
#         except IncidentUpdate.DoesNotExist:
#             first = None
#         return first
# 
#     def get_latest_update(self):
#         try:
#             latest = self.incidentupdate_set.latest()
#         except IncidentUpdate.DoesNotExist:
#             latest = None
#         return latest
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident'
#         verbose_name_plural = 'Incidents'
#         ordering = ['-created', ]
# 
# class IncidentUpdate(BaseModel):
#     """ Updates about an incident. """
#     incident = models.ForeignKey(Incident)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     status = models.ForeignKey(Status)
#     description = models.TextField()
# 
#     def __unicode__(self):
#         return "%s - %s: %s" % (self.user, self.status, self.description)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.incident.pk, ])
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident Update'
#         verbose_name_plural = 'Incident Updates'
#         ordering = ['created', ]
# 
#     def save(self, *args, **kwargs):
#         """ Update the parent incident update time too. """
#         self.incident.updated = timezone.now()
#         self.incident.save()
#         super(IncidentUpdate, self).save(*args, **kwargs)
# 
# Path: status/forms.py
# class IncidentCreateForm(forms.ModelForm):
#     class Meta:
#         model = Incident
#         fields = ['name']
# 
# class IncidentUpdateCreateForm(forms.ModelForm):
#     class Meta:
#         model = IncidentUpdate
#         fields = ['status', 'description']


# Path: status/views.py
from datetime import date, timedelta
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from django.template import RequestContext, Template
from django.template.loader import get_template
from django.utils.decorators import method_decorator
from django.views.generic import (
    MonthArchiveView, YearArchiveView, CreateView, DeleteView, DetailView, ListView, TemplateView
)
from stronghold.decorators import public
from status.models import Incident, IncidentUpdate
from status.forms import IncidentCreateForm, IncidentUpdateCreateForm
import slack
import slack.chat
import logging

    model = IncidentUpdate
    form_class = IncidentUpdateCreateForm
    template_name = 'status/incident_form.html'

    def get_success_url(self):
        return reverse('status:incident_detail', args=[self.kwargs['pk']])

    def form_valid(self, form):
        iu = form.save(commit=False)
        i = Incident.objects.get(pk=self.kwargs['pk'])
        i.hidden = False
        i.save()
        iu.incident = i
        iu.incident.hidden = False
        iu.incident.save()
        iu.user = self.request.user
        iu.save()
        return HttpResponseRedirect(self.get_success_url())


class IncidentDetailView(DetailView):
    model = Incident

    @method_decorator(public)
    def dispatch(self, *args, **kwargs):
        return super(IncidentDetailView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(IncidentDetailView, self).get_context_data(**kwargs)
        context.update({

            'form': IncidentUpdateCreateForm(),