# Path: scribeui_pyramid/modules/maps/models.py
# class Map(Base, BaseMixin):
# 
#     __tablename__ = 'maps'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False)
#     type = sa.Column(sa.Unicode(30), nullable=False)
#     description = sa.Column(sa.Unicode())
#     projection = sa.Column(sa.Unicode())
#     extent = sa.Column(sa.Unicode(50))
#     git_url = sa.Column(sa.Unicode())
# 
#     workspace_id = sa.Column(sa.Integer, sa.ForeignKey('workspaces.id'),
#                              nullable=False)
# 
#     def __repr__(self):
#         return u"<Map('{0}')>".format(self.name)
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# Path: scribeui_pyramid/modules/workspaces/models.py
# class Workspace(Base, BaseMixin):
# 
#     __tablename__ = 'workspaces'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False, unique=True)
#     password = sa.Column(sa.Unicode(256))
# 
# 
#     def __repr__(self):
#         return u"<Workspace('{0}')>".format(self.name)
# 
# 
#     @staticmethod
#     def password_manager():
#         return DelegatingPasswordManager(preferred=BCRYPTPasswordManager())
# 
# 
#     @staticmethod
#     def encode_password(raw):
#         return Workspace.password_manager().encode(raw)
# 
# 
#     @staticmethod
#     def check_password(hashed, raw):
#         return Workspace.password_manager().check(
#             hashed,
#             raw,
#             setter=Workspace.encode_password
#         )
# 
# 
#     @classmethod
#     def authenticate(cls, name, password):
#         workspace = DBSession.query(cls)\
#             .filter_by(name=name)\
#             .first()
# 
#         if workspace:
#             if workspace.password and password and Workspace.check_password(workspace.password, password):
#                 return workspace
#             elif not workspace.password and not password:
#                 return workspace
#         return None
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# 
#     def get_maps(self, type=None):
#         q = Map.query.filter(Map.workspace_id == self.id)
# 
#         if type:
#             q = q.filter(Map.type == type)
# 
#         return q.all()
# 
# 
#     def get_map_by_name(self, name):
#         q = DBSession.query(Map)\
#             .filter(Map.name == name.lower(), Map.workspace_id == self.id)
# 
#         return q.first()


import logging
import codecs
import pprint, os, fnmatch
from scribeui_pyramid.modules.maps.models import Map
from scribeui_pyramid.modules.workspaces.models import Workspace
from BeautifulSoup import BeautifulStoneSoup
from pyramid.view import view_config
from pyramid.response import FileResponse
from sqlalchemy.orm.exc import NoResultFound
        route_name='mapcache.tiles',
        permission='view',
        renderer='json',
        request_method='GET'
    )
    def tiles(self):
        response = {
            'status': 0,
            'errors': [],
        }
        # Validation
        try:
            mapID = self.request.GET.get('map')
        except KeyError as e:
            response['errors'].append('A map ID is required.')
        if mapID is None:
            response['errors'].append('A map ID is required.')
        try:
            jobPath = self.request.GET.get('job')
        except KeyError as e:
            response['errors'].append('A job path is required.')
        if jobPath is None:
            response['errors'].append('A job path is required.')
        try:
            tilerequest = self.request.GET.get('request')
        except KeyError as e:
            response['errors'].append('A tile request is required.')
        if tilerequest is None:
            response['errors'].append('A tile request is required.')
        try:

# Path: scribeui_pyramid/modules/maps/models.py
# class Map(Base, BaseMixin):
# 
#     __tablename__ = 'maps'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False)
#     type = sa.Column(sa.Unicode(30), nullable=False)
#     description = sa.Column(sa.Unicode())
#     projection = sa.Column(sa.Unicode())
#     extent = sa.Column(sa.Unicode(50))
#     git_url = sa.Column(sa.Unicode())
# 
#     workspace_id = sa.Column(sa.Integer, sa.ForeignKey('workspaces.id'),
#                              nullable=False)
# 
#     def __repr__(self):
#         return u"<Map('{0}')>".format(self.name)
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# Path: scribeui_pyramid/modules/workspaces/models.py
# class Workspace(Base, BaseMixin):
# 
#     __tablename__ = 'workspaces'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False, unique=True)
#     password = sa.Column(sa.Unicode(256))
# 
# 
#     def __repr__(self):
#         return u"<Workspace('{0}')>".format(self.name)
# 
# 
#     @staticmethod
#     def password_manager():
#         return DelegatingPasswordManager(preferred=BCRYPTPasswordManager())
# 
# 
#     @staticmethod
#     def encode_password(raw):
#         return Workspace.password_manager().encode(raw)
# 
# 
#     @staticmethod
#     def check_password(hashed, raw):
#         return Workspace.password_manager().check(
#             hashed,
#             raw,
#             setter=Workspace.encode_password
#         )
# 
# 
#     @classmethod
#     def authenticate(cls, name, password):
#         workspace = DBSession.query(cls)\
#             .filter_by(name=name)\
#             .first()
# 
#         if workspace:
#             if workspace.password and password and Workspace.check_password(workspace.password, password):
#                 return workspace
#             elif not workspace.password and not password:
#                 return workspace
#         return None
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# 
#     def get_maps(self, type=None):
#         q = Map.query.filter(Map.workspace_id == self.id)
# 
#         if type:
#             q = q.filter(Map.type == type)
# 
#         return q.all()
# 
# 
#     def get_map_by_name(self, name):
#         q = DBSession.query(Map)\
#             .filter(Map.name == name.lower(), Map.workspace_id == self.id)
# 
#         return q.first()


# Path: scribeui_pyramid/modules/plugins/mapcache/views/mapcacheViewer.py
import logging
import codecs
import pprint, os, fnmatch
from scribeui_pyramid.modules.maps.models import Map
from scribeui_pyramid.modules.workspaces.models import Workspace
from BeautifulSoup import BeautifulStoneSoup
from pyramid.view import view_config
from pyramid.response import FileResponse
from sqlalchemy.orm.exc import NoResultFound

        route_name='mapcache.tiles',
        permission='view',
        renderer='json',
        request_method='GET'
    )
    def tiles(self):
        response = {
            'status': 0,
            'errors': [],
        }
        # Validation
        try:
            mapID = self.request.GET.get('map')
        except KeyError as e:
            response['errors'].append('A map ID is required.')
        if mapID is None:
            response['errors'].append('A map ID is required.')
        try:
            jobPath = self.request.GET.get('job')
        except KeyError as e:
            response['errors'].append('A job path is required.')
        if jobPath is None:
            response['errors'].append('A job path is required.')
        try:
            tilerequest = self.request.GET.get('request')
        except KeyError as e:
            response['errors'].append('A tile request is required.')
        if tilerequest is None:
            response['errors'].append('A tile request is required.')
        try:

            map = Map.by_id(mapID)