# Path: duckpond/apps/editor/app.py
# def before_request():


import requests
import json
import shutil
from tempfile import TemporaryFile
from flask import session, abort
from .app import app

def getAuth():
   user = app.config['AUTH_SERVICE'].getUser(session['username'])
   return requests.auth.HTTPBasicAuth(user['username'], user['password'])

def getContentList():
   url = app.config['SERVICE'] + 'content/'
   req = requests.get(url,auth=getAuth(),headers={'Connection' : 'close'})
   if req.status_code!=200:
      raise IOError('Cannot get content list from service, status {status}'.format(**{'status':req.status_code}))
   return json.loads(req.text)

def createContent(typeName,genre,name,headline):
   url = app.config['SERVICE'] + 'content/'
   user = app.config['AUTH_SERVICE'].getUser(session['username'])
   headers = {'Content-Type' : 'application/ld+json', 'Connection' : 'close'}
   data = {
      '@context' : 'http://schema.org/',
      '@type' : typeName,

# Path: duckpond/apps/editor/app.py
# def before_request():


# Path: duckpond/apps/editor/model.py
import requests
import json
import shutil
from tempfile import TemporaryFile
from flask import session, abort
from .app import app


def getAuth():
   user = app.config['AUTH_SERVICE'].getUser(session['username'])
   return requests.auth.HTTPBasicAuth(user['username'], user['password'])

def getContentList():
   url = app.config['SERVICE'] + 'content/'
   req = requests.get(url,auth=getAuth(),headers={'Connection' : 'close'})
   if req.status_code!=200:
      raise IOError('Cannot get content list from service, status {status}'.format(**{'status':req.status_code}))
   return json.loads(req.text)

def createContent(typeName,genre,name,headline):
   url = app.config['SERVICE'] + 'content/'
   user = app.config['AUTH_SERVICE'].getUser(session['username'])
   headers = {'Content-Type' : 'application/ld+json', 'Connection' : 'close'}
   data = {
      '@context' : 'http://schema.org/',
      '@type' : typeName,

      'genre' : genre,