# Path: harnas/checker/heraclient.py
# class Template(object):
#     def __init__(self, id, auth=None, data=None):
#         self.id = id
#         self.auth = get_auth(auth)
#         if not data:
#             resp = requests.get(URL + 'template/%s' % self.id, auth=self.auth)
#             response_raise(resp)
#             data = resp.json()
#         self.name = data['name']
#         self.public = data['public']
# 
#     def change(self, public=None, name=None):
#         req = filter_out_if_none(dict(public=public, name=name))
#         resp = requests.post(URL + 'template/%s' % self.id, auth=self.auth, data=req)
#         response_raise(resp)
#         if public is not None:
#             self.public = public
#         if name is not None:
#             self.name = name
# 
#     @classmethod
#     def list(self, auth=None):
#         auth = get_auth(auth)
#         resp = requests.get(URL + 'template/', auth=auth)
#         response_raise(resp)
#         return [ Template(item['id'], auth=auth, data=item)
#                  for item in resp.json()['templates'] ]


from django.conf import settings
from django.core.cache import cache
from harnas.checker.heraclient import Template


def get_templates_list():
    templates = cache.get('templates_list')
    if templates is None:
        templates = Template.list(settings.HERA_AUTH)
        cache.set('templates_list', templates, 60 * 60 * 24)

# Path: harnas/checker/heraclient.py
# class Template(object):
#     def __init__(self, id, auth=None, data=None):
#         self.id = id
#         self.auth = get_auth(auth)
#         if not data:
#             resp = requests.get(URL + 'template/%s' % self.id, auth=self.auth)
#             response_raise(resp)
#             data = resp.json()
#         self.name = data['name']
#         self.public = data['public']
# 
#     def change(self, public=None, name=None):
#         req = filter_out_if_none(dict(public=public, name=name))
#         resp = requests.post(URL + 'template/%s' % self.id, auth=self.auth, data=req)
#         response_raise(resp)
#         if public is not None:
#             self.public = public
#         if name is not None:
#             self.name = name
# 
#     @classmethod
#     def list(self, auth=None):
#         auth = get_auth(auth)
#         resp = requests.get(URL + 'template/', auth=auth)
#         response_raise(resp)
#         return [ Template(item['id'], auth=auth, data=item)
#                  for item in resp.json()['templates'] ]


# Path: harnas/checker/utils.py
from django.conf import settings
from django.core.cache import cache
from harnas.checker.heraclient import Template



def get_templates_list():
    templates = cache.get('templates_list')
    if templates is None:
        templates = Template.list(settings.HERA_AUTH)
        cache.set('templates_list', templates, 60 * 60 * 24)

    return templates