# Path: phylocommons/get_treestore.py
# def get_treestore():
#     return Treestore(**settings.TREESTORE_KWARGS)
# 
# def tree_id_from_uri(uri):
#     return Treestore.id_from_uri(uri, base_uri=settings.TREE_URI)
# 
# def uri_from_tree_id(tree_id):
#     return Treestore.uri_from_id(tree_id, base_uri=settings.TREE_URI)


from django.shortcuts import render_to_response, redirect
from django.http import HttpResponse
from django.core.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import RequestContext
from phylocommons.get_treestore import get_treestore, tree_id_from_uri, uri_from_tree_id
from forms import SearchForm
from cStringIO import StringIO
from phylocommons import settings
from django.forms.forms import NON_FIELD_ERRORS
from django.forms.util import ErrorList
from django.http import Http404
import Bio.Phylo as bp
import urllib
            tree_info.update(all_tree_info[0])
            tree_info['citation'] = []
            for x in all_tree_info:
                if x['citation']: tree_info['citation'].append(x['citation'])
        except IndexError:
            raise Http404
            return not_found(request, tree_uri)
        obj_info = treestore.get_object_info(tree_uri)
        prefixes = treestore.prefixes
        def add_prefix(x):
            for prefix, uri in prefixes:
                if x.startswith(uri):
                    if prefix == 'obo':
                        try: return 'cdao:%s (obo:%s)' % (obo_to_cdao[x[len(uri):]], x[len(uri):])
                        except: pass
                    return '%s:%s' % (prefix, x[len(uri):])
            return x
        obj_info = [sum([(x, add_prefix(x)) for x in row], ()) for row in obj_info]
        
        params.update(tree_info)
        params['obj_info'] = obj_info
            
        return render_to_response(
            'view.html',
            params,
            context_instance=RequestContext(request)
        )


def download(request, tree_id=None):

# Path: phylocommons/get_treestore.py
# def get_treestore():
#     return Treestore(**settings.TREESTORE_KWARGS)
# 
# def tree_id_from_uri(uri):
#     return Treestore.id_from_uri(uri, base_uri=settings.TREE_URI)
# 
# def uri_from_tree_id(tree_id):
#     return Treestore.uri_from_id(tree_id, base_uri=settings.TREE_URI)


# Path: treeview/views.py
from django.shortcuts import render_to_response, redirect
from django.http import HttpResponse
from django.core.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import RequestContext
from phylocommons.get_treestore import get_treestore, tree_id_from_uri, uri_from_tree_id
from forms import SearchForm
from cStringIO import StringIO
from phylocommons import settings
from django.forms.forms import NON_FIELD_ERRORS
from django.forms.util import ErrorList
from django.http import Http404
import Bio.Phylo as bp
import urllib

            tree_info.update(all_tree_info[0])
            tree_info['citation'] = []
            for x in all_tree_info:
                if x['citation']: tree_info['citation'].append(x['citation'])
        except IndexError:
            raise Http404
            return not_found(request, tree_uri)
        obj_info = treestore.get_object_info(tree_uri)
        prefixes = treestore.prefixes
        def add_prefix(x):
            for prefix, uri in prefixes:
                if x.startswith(uri):
                    if prefix == 'obo':
                        try: return 'cdao:%s (obo:%s)' % (obo_to_cdao[x[len(uri):]], x[len(uri):])
                        except: pass
                    return '%s:%s' % (prefix, x[len(uri):])
            return x
        obj_info = [sum([(x, add_prefix(x)) for x in row], ()) for row in obj_info]
        
        params.update(tree_info)
        params['obj_info'] = obj_info
            
        return render_to_response(
            'view.html',
            params,
            context_instance=RequestContext(request)
        )


def download(request, tree_id=None):

    with get_treestore() as treestore: