# Path: attendance/views.py
# class DailyAttendanceView(View):
#     template_name = 'attendance/attendance-daily.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
#         try:
#             d = date(int(kwargs.get('year')), int(kwargs.get('month')),
#                      int(kwargs.get('day')))
#         except ValueError:
#             raise Http404
# 
#         daily_attendance = get_object_or_404(DailyAttendance, date=d)
#         attendance_dict = create_daily_attendance_dict(daily_attendance)
# 
#         # attendance_dict = { "1st year": { user: [present, s_time, e_time], } }
#         context = {'attendance_dict': attendance_dict, 'head': d}
#         return render(request, self.template_name, context)
# 
# class MonthlyAttendanceView(View):
#     template_name = 'attendance/attendance-sum.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
# 
#         year = int(kwargs.get('year'))
#         month = int(kwargs.get('month'))
# 
#         attendance_list = DailyAttendance.objects.filter(date__year=year, date__month=month)
#         if attendance_list.count() == 0:
#             raise Http404
#         attendance_dict = sum_daily_attendance_dict(attendance_list)
#         context = {'attendance_dict': attendance_dict, 'head': str(year) + " " + str(month)}
#         return render(request, self.template_name, context)
# 
# class YearlyAttendanceView(View):
#     template_name = 'attendance/attendance-sum.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
# 
#         year = int(kwargs.get('year'))
# 
#         attendance_list = DailyAttendance.objects.filter(date__year=year)
#         if attendance_list.count() == 0:
#             raise Http404
#         attendance_dict = sum_daily_attendance_dict(attendance_list)
#         context = {'attendance_dict': attendance_dict, 'head': str(year)}
#         return render(request, self.template_name, context)


from django.conf.urls import url
from attendance.views import DailyAttendanceView, MonthlyAttendanceView, YearlyAttendanceView
from django.contrib.auth.decorators import login_required
# created by Chirath R, chirath.02@gmail.com



urlpatterns = [
    url(
        r'^(?P<year>[0-9]+)/$',
        login_required(YearlyAttendanceView.as_view()),
        name='yearly_attendance'
    ),
    url(
        r'^(?P<year>[0-9]+)/(?P<month>[0-9]+)/$',
        login_required(MonthlyAttendanceView.as_view()),
        name='monthly_attendance'
    ),
    url(
        r'^(?P<year>[0-9]+)/(?P<month>[0-9]+)/(?P<day>[0-9]+)/$',

# Path: attendance/views.py
# class DailyAttendanceView(View):
#     template_name = 'attendance/attendance-daily.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
#         try:
#             d = date(int(kwargs.get('year')), int(kwargs.get('month')),
#                      int(kwargs.get('day')))
#         except ValueError:
#             raise Http404
# 
#         daily_attendance = get_object_or_404(DailyAttendance, date=d)
#         attendance_dict = create_daily_attendance_dict(daily_attendance)
# 
#         # attendance_dict = { "1st year": { user: [present, s_time, e_time], } }
#         context = {'attendance_dict': attendance_dict, 'head': d}
#         return render(request, self.template_name, context)
# 
# class MonthlyAttendanceView(View):
#     template_name = 'attendance/attendance-sum.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
# 
#         year = int(kwargs.get('year'))
#         month = int(kwargs.get('month'))
# 
#         attendance_list = DailyAttendance.objects.filter(date__year=year, date__month=month)
#         if attendance_list.count() == 0:
#             raise Http404
#         attendance_dict = sum_daily_attendance_dict(attendance_list)
#         context = {'attendance_dict': attendance_dict, 'head': str(year) + " " + str(month)}
#         return render(request, self.template_name, context)
# 
# class YearlyAttendanceView(View):
#     template_name = 'attendance/attendance-sum.html'
# 
#     def get(self, request, **kwargs):
#         if not request.user.is_authenticated:
#             return redirect('permission_denied')
# 
#         year = int(kwargs.get('year'))
# 
#         attendance_list = DailyAttendance.objects.filter(date__year=year)
#         if attendance_list.count() == 0:
#             raise Http404
#         attendance_dict = sum_daily_attendance_dict(attendance_list)
#         context = {'attendance_dict': attendance_dict, 'head': str(year)}
#         return render(request, self.template_name, context)


# Path: attendance/urls.py
from django.conf.urls import url
from attendance.views import DailyAttendanceView, MonthlyAttendanceView, YearlyAttendanceView
from django.contrib.auth.decorators import login_required

# created by Chirath R, chirath.02@gmail.com



urlpatterns = [
    url(
        r'^(?P<year>[0-9]+)/$',
        login_required(YearlyAttendanceView.as_view()),
        name='yearly_attendance'
    ),
    url(
        r'^(?P<year>[0-9]+)/(?P<month>[0-9]+)/$',
        login_required(MonthlyAttendanceView.as_view()),
        name='monthly_attendance'
    ),
    url(
        r'^(?P<year>[0-9]+)/(?P<month>[0-9]+)/(?P<day>[0-9]+)/$',

        login_required(DailyAttendanceView.as_view()),