# Path: account/mixins.py
# class LoginRequiredMixin(object):
# 
#     redirect_field_name = "next"
#     login_url = None
# 
#     def dispatch(self, request, *args, **kwargs):
#         self.request = request
#         self.args = args
#         self.kwargs = kwargs
#         if request.user.is_authenticated():
#             return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
#         return self.redirect_to_login()
# 
#     def get_login_url(self):
#         return self.login_url or settings.ACCOUNT_LOGIN_URL
# 
#     def get_next_url(self):
#         return self.request.get_full_path()
# 
#     def redirect_to_login(self):
#         return handle_redirect_to_login(
#             self.request,
#             redirect_field_name=self.redirect_field_name,
#             login_url=self.get_login_url(),
#             next_url=self.get_next_url(),
#         )
# 
# class SuperUserRequiredMixin(object):
#     redirect_field_name = "next"
#     login_url = None
# 
#     def dispatch(self, request, *args, **kwargs):
#         self.request = request
#         self.args = args
#         self.kwargs = kwargs
#         if request.user.is_superuser:
#             return super(SuperUserRequiredMixin, self).dispatch(request, *args, **kwargs)
#         raise PermissionDenied
# 
# Path: task/forms.py
# class CrontabForm(forms.ModelForm):
#     class Meta:
#         model = CrontabJob
#         fields = ['id', 'desc', 'project', 'command', 'sql_ref',
#                   'redis_ref', 'extra_ref']


import os
from django.shortcuts import redirect
from django.views.generic import FormView, ListView, TemplateView
from django.contrib import auth, messages
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.db.models import Q
from account.mixins import LoginRequiredMixin, SuperUserRequiredMixin
from account.utils import default_redirect
from models import CrontabJob, STATUS_CHOICES
from task.forms import CrontabForm
#!/usr/bin/env python
# coding=utf-8
"""

__created__ = '6/9/15'
__author__ = 'deling.ma'
"""



class CrontabListView(LoginRequiredMixin, ListView):
    model = CrontabJob
    template_name = "crontab_list.html"
    paginate_by = 10

    def get_queryset(self):
        if self.request.user.is_superuser:
            return CrontabJob.objects.order_by("-status")
        return CrontabJob.objects.filter(Q(project__user=self.request.user) |
                                         Q(user=self.request.user)).distinct().order_by("-status")



# Path: account/mixins.py
# class LoginRequiredMixin(object):
# 
#     redirect_field_name = "next"
#     login_url = None
# 
#     def dispatch(self, request, *args, **kwargs):
#         self.request = request
#         self.args = args
#         self.kwargs = kwargs
#         if request.user.is_authenticated():
#             return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
#         return self.redirect_to_login()
# 
#     def get_login_url(self):
#         return self.login_url or settings.ACCOUNT_LOGIN_URL
# 
#     def get_next_url(self):
#         return self.request.get_full_path()
# 
#     def redirect_to_login(self):
#         return handle_redirect_to_login(
#             self.request,
#             redirect_field_name=self.redirect_field_name,
#             login_url=self.get_login_url(),
#             next_url=self.get_next_url(),
#         )
# 
# class SuperUserRequiredMixin(object):
#     redirect_field_name = "next"
#     login_url = None
# 
#     def dispatch(self, request, *args, **kwargs):
#         self.request = request
#         self.args = args
#         self.kwargs = kwargs
#         if request.user.is_superuser:
#             return super(SuperUserRequiredMixin, self).dispatch(request, *args, **kwargs)
#         raise PermissionDenied
# 
# Path: task/forms.py
# class CrontabForm(forms.ModelForm):
#     class Meta:
#         model = CrontabJob
#         fields = ['id', 'desc', 'project', 'command', 'sql_ref',
#                   'redis_ref', 'extra_ref']


# Path: task/views.py
import os
from django.shortcuts import redirect
from django.views.generic import FormView, ListView, TemplateView
from django.contrib import auth, messages
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.db.models import Q
from account.mixins import LoginRequiredMixin, SuperUserRequiredMixin
from account.utils import default_redirect
from models import CrontabJob, STATUS_CHOICES
from task.forms import CrontabForm

#!/usr/bin/env python
# coding=utf-8
"""

__created__ = '6/9/15'
__author__ = 'deling.ma'
"""



class CrontabListView(LoginRequiredMixin, ListView):
    model = CrontabJob
    template_name = "crontab_list.html"
    paginate_by = 10

    def get_queryset(self):
        if self.request.user.is_superuser:
            return CrontabJob.objects.order_by("-status")
        return CrontabJob.objects.filter(Q(project__user=self.request.user) |
                                         Q(user=self.request.user)).distinct().order_by("-status")



class CrontabView(LoginRequiredMixin, FormView):