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

# Copyright (c) 2014 Vincent Celis
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import logging

import utils
import settings

from base import BaseHandler
from models import Page

class PageApi(BaseHandler):
  def get(self, name):
    name = utils.checkPage(name)
    version = self.checkVersionRequest()

    page = Page.getName(name, version)

    if page:
      self.renderJson(page.to_dict(exclude=['created']))
    else:
      self.abort(404)

class HistoryApi(BaseHandler):
  def get(self, name):
    name = utils.checkPage(name)

    pages = Page.getNameAll(name)
    result = []

    for page in pages:
      result.append(page.to_dict(exclude=['created']))
    
    if result:
      self.renderJson(result)
    else:
      self.abort(404)
@@ -1244,36 +1244,459 @@
 ler):%0A  
-def get(self, name):
+%22%22%22API handler for specific wiki page versions%0A%0A  API handler to handle the requests for the specific wiki page versions.%0A  Inherits common functionality from BaseHandler%0A  %22%22%22%0A  def get(self, name):%0A    %22%22%22Handles the get requests for the page API%0A%0A    If a version is specified in the url it retreives the corresponding version%0A    of the requested page.%0A%0A    If the requested version or page doesn't exist, a 404 will be served.    %0A    %22%22%22
 %0A    nam
@@ -1861,32 +1861,40 @@
 clude=%5B'created'
+, 'name'
 %5D))%0A    else:%0A  
@@ -1945,16 +1945,204 @@
 ndler):%0A
+  %22%22%22API handler for the history of wiki pages%0A%0A  API handler to handle the requests for the history of the wiki pages.%0A%0A  If the requested page doesn't exist, a 404 will be served.%0A  %22%22%22%0A
   def ge
@@ -2315,16 +2315,24 @@
 created'
+, 'name'
 %5D))%0A    

update docstrings