# Path: pyvac/views/base.py
# class View(ViewBase):
#     """
#     Base class of every views.
#     """
# 
#     def update_response(self, response):
#         # this is a view to render
#         if isinstance(response, dict):
#             global_ = {
#                 'pyvac': {
#                     'version': __version__,
#                     'login': self.login,
#                     'user': self.user,
#                 }
#             }
# 
#             if self.user:
#                 # if logged, retrieve total requests count for header
#                 req_list = {'requests': []}
#                 requests = []
#                 if self.user.is_admin:
#                     country = self.user.country
#                     requests = Request.all_for_admin_per_country(self.session,
#                                                                  country)
#                 elif self.user.is_super:
#                     requests = Request.by_manager(self.session, self.user)
# 
#                 req_list['requests'] = requests
# 
#                 # always add our requests
#                 for req in Request.by_user(self.session, self.user):
#                     if req not in req_list['requests']:
#                         req_list['requests'].append(req)
# 
#                 # only count next requests
#                 today = datetime.now()
#                 if self.user.is_admin:
#                     # for admin, display request from 1st of month
#                     today = today.replace(day=1)
#                 requests_count = len([req for req in req_list['requests']
#                                       if req.date_to >= today])
# 
#                 global_['pyvac']['requests_count'] = requests_count
# 
#                 # retrieve available users for sudo
#                 sudoers = Sudoer.alias(self.session, self.user)
#                 if sudoers:
#                     sudoers.append(self.user)
#                 global_['pyvac']['sudoers'] = sudoers
# 
#             response.update(global_)
# 
# Path: pyvac/helpers/holiday.py
# def get_holiday(user, year=None, use_datetime=False):
#     """ return holidays for user country
# 
#     format is unixtime for javascript
#     """
#     klass = conv_table[user.country]
# 
#     cal = klass()
#     current_year = year or datetime.now().year
#     next_year = current_year + 1
# 
#     # retrieve Dates from workalendar
#     holiday_current_raw = [dt for dt, _ in cal.holidays(current_year)]
#     holiday_next_raw = [dt for dt, _ in cal.holidays(next_year)]
# 
#     if user.country in override and current_year in override[user.country]:
#         holiday_current_raw = [datetime.strptime(dt, '%Y-%m-%d')
#                                for dt in
#                                override[user.country][current_year]]
# 
#     if user.country in override and next_year in override[user.country]:
#         holiday_next_raw = [datetime.strptime(dt, '%Y-%m-%d')
#                             for dt in
#                             override[user.country][next_year]]
# 
#     if not use_datetime:
#         # must cast to javascript timestamp
#         holiday_current = [utcify(dt) for dt in holiday_current_raw]
#         holiday_next = [utcify(dt) for dt in holiday_next_raw]
#     else:
#         # must cast to datetime as workalendar returns only Date objects
#         holiday_current = [datetime(dt.year, dt.month, dt.day)
#                            for dt in holiday_current_raw]
#         holiday_next = [datetime(dt.year, dt.month, dt.day)
#                         for dt in holiday_next_raw]
# 
#     return holiday_current + holiday_next


import logging
from .base import View
from pyvac.helpers.holiday import get_holiday
# -*- coding: utf-8 -*-

log = logging.getLogger(__name__)


class List(View):
    """
    List holiday for given year
    """
    def render(self):
        year = int(self.request.params.get('year'))

# Path: pyvac/views/base.py
# class View(ViewBase):
#     """
#     Base class of every views.
#     """
# 
#     def update_response(self, response):
#         # this is a view to render
#         if isinstance(response, dict):
#             global_ = {
#                 'pyvac': {
#                     'version': __version__,
#                     'login': self.login,
#                     'user': self.user,
#                 }
#             }
# 
#             if self.user:
#                 # if logged, retrieve total requests count for header
#                 req_list = {'requests': []}
#                 requests = []
#                 if self.user.is_admin:
#                     country = self.user.country
#                     requests = Request.all_for_admin_per_country(self.session,
#                                                                  country)
#                 elif self.user.is_super:
#                     requests = Request.by_manager(self.session, self.user)
# 
#                 req_list['requests'] = requests
# 
#                 # always add our requests
#                 for req in Request.by_user(self.session, self.user):
#                     if req not in req_list['requests']:
#                         req_list['requests'].append(req)
# 
#                 # only count next requests
#                 today = datetime.now()
#                 if self.user.is_admin:
#                     # for admin, display request from 1st of month
#                     today = today.replace(day=1)
#                 requests_count = len([req for req in req_list['requests']
#                                       if req.date_to >= today])
# 
#                 global_['pyvac']['requests_count'] = requests_count
# 
#                 # retrieve available users for sudo
#                 sudoers = Sudoer.alias(self.session, self.user)
#                 if sudoers:
#                     sudoers.append(self.user)
#                 global_['pyvac']['sudoers'] = sudoers
# 
#             response.update(global_)
# 
# Path: pyvac/helpers/holiday.py
# def get_holiday(user, year=None, use_datetime=False):
#     """ return holidays for user country
# 
#     format is unixtime for javascript
#     """
#     klass = conv_table[user.country]
# 
#     cal = klass()
#     current_year = year or datetime.now().year
#     next_year = current_year + 1
# 
#     # retrieve Dates from workalendar
#     holiday_current_raw = [dt for dt, _ in cal.holidays(current_year)]
#     holiday_next_raw = [dt for dt, _ in cal.holidays(next_year)]
# 
#     if user.country in override and current_year in override[user.country]:
#         holiday_current_raw = [datetime.strptime(dt, '%Y-%m-%d')
#                                for dt in
#                                override[user.country][current_year]]
# 
#     if user.country in override and next_year in override[user.country]:
#         holiday_next_raw = [datetime.strptime(dt, '%Y-%m-%d')
#                             for dt in
#                             override[user.country][next_year]]
# 
#     if not use_datetime:
#         # must cast to javascript timestamp
#         holiday_current = [utcify(dt) for dt in holiday_current_raw]
#         holiday_next = [utcify(dt) for dt in holiday_next_raw]
#     else:
#         # must cast to datetime as workalendar returns only Date objects
#         holiday_current = [datetime(dt.year, dt.month, dt.day)
#                            for dt in holiday_current_raw]
#         holiday_next = [datetime(dt.year, dt.month, dt.day)
#                         for dt in holiday_next_raw]
# 
#     return holiday_current + holiday_next


# Path: pyvac/views/holiday.py
import logging
from .base import View
from pyvac.helpers.holiday import get_holiday

# -*- coding: utf-8 -*-

log = logging.getLogger(__name__)


class List(View):
    """
    List holiday for given year
    """
    def render(self):
        year = int(self.request.params.get('year'))

        holidays = get_holiday(self.user, year)