# 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 import forms
from phylocommons.get_treestore import get_treestore, tree_id_from_uri, uri_from_tree_id
from phylocommons import settings
import Bio.Phylo as bp


class QueryForm(forms.Form):
    with get_treestore() as treestore:
        taxa = forms.CharField(required=True,
                               widget=forms.Textarea)
        taxa.widget.attrs['class'] = 'stretch'
        taxa.widget.attrs['placeholder'] = 'Enter a comma-separated list of taxa (e.g. Homo sapiens,Pan troglodytes,Pan paniscus,Gorilla gorilla,Pongo pygmaeus) to build a tree containing those taxa'
        
        format_choices = sorted(bp._io.supported_formats.keys()) + ['ascii']
        format_choices = [('view', '(open in tree viewer)')] + [(x,x) for x in format_choices]
        format = forms.ChoiceField(choices=format_choices,
                                   initial=format_choices[0],
                                   )
        format.widget.attrs['class'] = 'stretch'
                                   
        prune = forms.BooleanField(required=False, initial=True)
        

# 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: treequery/forms.py
from django import forms
from phylocommons.get_treestore import get_treestore, tree_id_from_uri, uri_from_tree_id
from phylocommons import settings
import Bio.Phylo as bp



class QueryForm(forms.Form):
    with get_treestore() as treestore:
        taxa = forms.CharField(required=True,
                               widget=forms.Textarea)
        taxa.widget.attrs['class'] = 'stretch'
        taxa.widget.attrs['placeholder'] = 'Enter a comma-separated list of taxa (e.g. Homo sapiens,Pan troglodytes,Pan paniscus,Gorilla gorilla,Pongo pygmaeus) to build a tree containing those taxa'
        
        format_choices = sorted(bp._io.supported_formats.keys()) + ['ascii']
        format_choices = [('view', '(open in tree viewer)')] + [(x,x) for x in format_choices]
        format = forms.ChoiceField(choices=format_choices,
                                   initial=format_choices[0],
                                   )
        format.widget.attrs['class'] = 'stretch'
                                   
        prune = forms.BooleanField(required=False, initial=True)
        

        tree_list = [tree_id_from_uri(x) for x in treestore.list_trees()]