Beispiel #1
0
def example_catalog_tree():
    """Example CatalogTree"""

    print '\n--- example module cbs : CatalogTree ---\n'
    
    # create CatalogTree    
    ct = CatalogTree(language = 'en')
    ct.set_feeds()

    # service document 
    print 'Url service document:', ct.url
    print 'The service exposes {0} collections:'.format(len(ct.collections))
    for i, collection in enumerate(ct.collections, 1):
        feed = ct.feeds[collection] 
        print '-', collection, '->', len(feed.entries), 'entries'



    # methods  
    print '\n--- example module cbs : CatalogTree - methods ---'

    # get theme_id
    for entry in ct.get_entries('Themes'):
        if entry['ParentID'] is not None and entry['Language']=='en' \
        and ct.get_property('Themes', entry['ParentID'], 'ID', 'ParentID') is not None :
            theme_id = entry['ID']
            break

    theme_title = ct.get_property(collection = 'Themes', entry_id = theme_id, primary_key = 'ID', property_name = 'Title')
    print 'Theme id = {0}, title = {1}.'.format(theme_id, theme_title)

    # get parents theme
    print "\n* method: get_parents -> ct.get_parents(theme_id = {0})".format(theme_id)
    parents = ct.get_parents(theme_id = theme_id)
    for parent_id in parents[:-1]:
        print '- {0} ({1})'.format(ct.get_property('Themes', parent_id, 'ID', 'Title'), parent_id)

    # get children theme
    print "\n* method: get_children -> ct.get_children(theme_id = {0})".format(theme_id)
    children = ct.get_children(theme_id)
    for child in children['Tables_Themes']:
        print '- Table: {0} (id: {1})'.format(ct.get_property('Tables', child['TableID'], 'ID', 'Title'), child['TableID'])
    for child in children['Themes']:
        print '- Theme: {0} (id: {1})'.format(ct.get_property('Themes', child['ID'], 'ID', 'Title'), child['ID'])
Beispiel #2
0
from flask import Flask, request, session, redirect, url_for, render_template, flash
from py2cbs import CatalogTree, Table

app = Flask(__name__)

tree = CatalogTree(language = 'en')
tree.set_feeds()

@app.route('/')
def index():
	#return redirect('/theme')
	return render_template('index.html')

@app.route('/theme/None',  methods=['GET'])
@app.route('/theme',  methods=['GET'])
def theme_root():
	theme_id = None
	breadcrumbs = []
	children = tree.get_children(theme_id)
	context = {'theme_id':theme_id,'tree':tree, 'children':children, 'breadcrumbs':breadcrumbs}
	return render_template('theme.html', **context)

@app.route('/theme/<theme_id>',  methods=['GET'])
def theme_child(theme_id):
	theme_id = int(theme_id)
	breadcrumbs = tree.get_parents(theme_id) 
	children = tree.get_children(theme_id)
	context = {'theme_id':theme_id,'tree':tree, 'children':children, 'breadcrumbs':breadcrumbs}
	return render_template('theme.html', **context)

@app.route('/table/<tables_themes_id>',  methods=['GET'])