# Path: action/base_manager.py
# class BaseManager:
#     COOKIE_PATH = '/'
#     def delete_cookie(self, name):
#     def get_cookie(self, name):
#     def get_form(self, name, strip_value=True):
#     def set_cookie(self, name, value, httponly=True, expires=None):
# 
# Path: entity/recipe.py
# class Recipe:
#     def __init__(self, categories=[], description='', id=None, info='',
#                  ingredients='', rating=None, serving_size='', title='',
#                  tags=[], urls=[], synonyms=[], images=[], author=None):
#     def __str__(self):
#     def count_all(db):
#     def delete(self, db):
#     def find_all(db):
#     def find_category(db, category):
#     def find_pk(db, id):
#     def find_random(db, num):
#     def from_row(db, row):
#     def is_new(self):
#     def title_exists(db, title):
#     def save(self, db):
#     def __delete_images(self, db, force=False):
#     def __delete_recipe_has_category(self, db):
#     def __delete_recipe_has_tag(self, db):
#     def __delete_synonyms(self, db):
#     def __delete_urls(self, db):
#     def __generic_find(db, query, params):
# 
# Path: helper/url.py
# class Url:
#     def from_category(category, absolute=None):
#     def from_css(css_file, absolute=None):
#     def from_img(img_file, absolute=None):
#     def from_js(js_file, absolute=None):
#     def from_path(path_parts, absolute=None, filter_chars=False):
#     def from_recipe(recipe, absolute=None):
#     def search(search_text, absolute=None):
#     def slugify(text):


import bottle
import io
import json
import zipfile
from action import base_manager
from entity import recipe as recipe_entity
from helper import url as url_helper
        # Convert recipe to json compatible object.
        images = [image.path.replace(image_path, '')
                  for image in recipe.images]
        urls = [{'name': url.name, 'url': url.url} for url in recipe.urls]
        synonyms = [synonym.name for synonym in recipe.synonyms]
        json_obj = {
            'description': recipe.description,
            'info': recipe.info,
            'ingredients': recipe.ingredients,
            'serving_size': recipe.serving_size,
            'title': recipe.title,
            'urls': urls,
            'synonyms': synonyms,
            'images': images
        }

        # Create json.
        json_str = json.dumps(json_obj)

        # Create zip.
        with io.BytesIO() as zip_bytes:
            with zipfile.ZipFile(zip_bytes, mode='w') as zip:
                zip.writestr(recipe_json, json_str)
                for image in recipe.images:
                    index = image.path.rfind('/')
                    file_name = image.path[index:]
                    zip.write(static_path+'/'+image.path, file_name)
            result = zip_bytes.getvalue()

        # Stream to browser.

# Path: action/base_manager.py
# class BaseManager:
#     COOKIE_PATH = '/'
#     def delete_cookie(self, name):
#     def get_cookie(self, name):
#     def get_form(self, name, strip_value=True):
#     def set_cookie(self, name, value, httponly=True, expires=None):
# 
# Path: entity/recipe.py
# class Recipe:
#     def __init__(self, categories=[], description='', id=None, info='',
#                  ingredients='', rating=None, serving_size='', title='',
#                  tags=[], urls=[], synonyms=[], images=[], author=None):
#     def __str__(self):
#     def count_all(db):
#     def delete(self, db):
#     def find_all(db):
#     def find_category(db, category):
#     def find_pk(db, id):
#     def find_random(db, num):
#     def from_row(db, row):
#     def is_new(self):
#     def title_exists(db, title):
#     def save(self, db):
#     def __delete_images(self, db, force=False):
#     def __delete_recipe_has_category(self, db):
#     def __delete_recipe_has_tag(self, db):
#     def __delete_synonyms(self, db):
#     def __delete_urls(self, db):
#     def __generic_find(db, query, params):
# 
# Path: helper/url.py
# class Url:
#     def from_category(category, absolute=None):
#     def from_css(css_file, absolute=None):
#     def from_img(img_file, absolute=None):
#     def from_js(js_file, absolute=None):
#     def from_path(path_parts, absolute=None, filter_chars=False):
#     def from_recipe(recipe, absolute=None):
#     def search(search_text, absolute=None):
#     def slugify(text):


# Path: action/export_manager.py
import bottle
import io
import json
import zipfile
from action import base_manager
from entity import recipe as recipe_entity
from helper import url as url_helper

        # Convert recipe to json compatible object.
        images = [image.path.replace(image_path, '')
                  for image in recipe.images]
        urls = [{'name': url.name, 'url': url.url} for url in recipe.urls]
        synonyms = [synonym.name for synonym in recipe.synonyms]
        json_obj = {
            'description': recipe.description,
            'info': recipe.info,
            'ingredients': recipe.ingredients,
            'serving_size': recipe.serving_size,
            'title': recipe.title,
            'urls': urls,
            'synonyms': synonyms,
            'images': images
        }

        # Create json.
        json_str = json.dumps(json_obj)

        # Create zip.
        with io.BytesIO() as zip_bytes:
            with zipfile.ZipFile(zip_bytes, mode='w') as zip:
                zip.writestr(recipe_json, json_str)
                for image in recipe.images:
                    index = image.path.rfind('/')
                    file_name = image.path[index:]
                    zip.write(static_path+'/'+image.path, file_name)
            result = zip_bytes.getvalue()

        # Stream to browser.

        name = url_helper.Url.slugify(recipe.title)