# Path: attendance/models.py
# class SSIDName(models.Model):
#     name = models.CharField(max_length=30)
# 
#     def generate_random_name(self):
#         size = random.randint(10, 17)
#         chars = string.ascii_lowercase + string.digits
#         self.name = ''.join(random.choice(chars) for _ in range(size))
# 
#     def __str__(self):
#         return self.name
# 
# class DailyAttendance(models.Model):
#     """
#     attendance = { "2016": {"user_id": [1, s_time, e_time], "user_id": [0, s_time, e_time]}  }
#     """
#     date = models.DateField()
#     attendance = JSONField()
# 
#     def __str__(self):
#         return str(self.date)
# 
# Path: attendance/serializers.py
# class SSIDNameSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = SSIDName
#         fields = ['name']
#         read_only_fields = ['name']


from datetime import datetime, timedelta
from django.contrib.auth.models import User
from django.http import Http404
from django.shortcuts import redirect, get_object_or_404, render
from django.utils import timezone
from django.utils.datetime_safe import date
from django.views.generic.base import View
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from attendance.models import SSIDName, DailyAttendance
from attendance.serializers import SSIDNameSerializer
from registration.models import UserInfo
    return attendance_dict


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'))


# Path: attendance/models.py
# class SSIDName(models.Model):
#     name = models.CharField(max_length=30)
# 
#     def generate_random_name(self):
#         size = random.randint(10, 17)
#         chars = string.ascii_lowercase + string.digits
#         self.name = ''.join(random.choice(chars) for _ in range(size))
# 
#     def __str__(self):
#         return self.name
# 
# class DailyAttendance(models.Model):
#     """
#     attendance = { "2016": {"user_id": [1, s_time, e_time], "user_id": [0, s_time, e_time]}  }
#     """
#     date = models.DateField()
#     attendance = JSONField()
# 
#     def __str__(self):
#         return str(self.date)
# 
# Path: attendance/serializers.py
# class SSIDNameSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = SSIDName
#         fields = ['name']
#         read_only_fields = ['name']


# Path: attendance/views.py
from datetime import datetime, timedelta
from django.contrib.auth.models import User
from django.http import Http404
from django.shortcuts import redirect, get_object_or_404, render
from django.utils import timezone
from django.utils.datetime_safe import date
from django.views.generic.base import View
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from attendance.models import SSIDName, DailyAttendance
from attendance.serializers import SSIDNameSerializer
from registration.models import UserInfo

    return attendance_dict


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)