<s> import logging <EOL> import calendar <EOL> from flask . ext . appbuilder import ModelView <EOL> from flask . ext . appbuilder . models . sqla . interface import SQLAInterface <EOL> from flask . ext . appbuilder . charts . views import GroupByChartView <EOL> from flask . ext . appbuilder . models . group import aggregate_count <EOL> from flask . ext . babelpkg import lazy_gettext as _ <EOL> from flask_appbuilder . models . mixins import UserExtensionMixin <EOL> from app import db , appbuilder <EOL> from . models import ContactGroup , Gender , Contact <EOL> log = logging . getLogger ( __name__ ) <EOL> def fill_gender ( ) : <EOL> try : <EOL> db . session . add ( Gender ( name = '<STR_LIT>' ) ) <EOL> db . session . add ( Gender ( name = '<STR_LIT>' ) ) <EOL> db . session . commit ( ) <EOL> except : <EOL> db . session . rollback ( ) <EOL> class ContactModelView ( ModelView ) : <EOL> datamodel = SQLAInterface ( Contact ) <EOL> label_columns = { '<STR_LIT>' : '<STR_LIT>' } <EOL> list_columns = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> base_order = ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> show_fieldsets = [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : [ '<STR_LIT:address>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : False } ) , <EOL> ] <EOL> add_fieldsets = [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : [ '<STR_LIT:address>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : False } ) , <EOL> ] <EOL> edit_fieldsets = [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : [ '<STR_LIT:address>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : False } ) , <EOL> ] <EOL> class GroupModelView ( ModelView ) : <EOL> datamodel = SQLAInterface ( ContactGroup ) <EOL> related_views = [ ContactModelView ] <EOL> class ContactChartView ( GroupByChartView ) : <EOL> datamodel = SQLAInterface ( Contact ) <EOL> chart_title = '<STR_LIT>' <EOL> label_columns = ContactModelView . label_columns <EOL> chart_type = '<STR_LIT>' <EOL> definitions = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ( aggregate_count , '<STR_LIT>' ) ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ( aggregate_count , '<STR_LIT>' ) ] <EOL> } <EOL> ] <EOL> def pretty_month_year ( value ) : <EOL> return calendar . month_name [ value . month ] + '<STR_LIT:U+0020>' + str ( value . year ) <EOL> def pretty_year ( value ) : <EOL> return str ( value . year ) <EOL> class ContactTimeChartView ( GroupByChartView ) : <EOL> datamodel = SQLAInterface ( Contact ) <EOL> chart_title = '<STR_LIT>' <EOL> chart_type = '<STR_LIT>' <EOL> label_columns = ContactModelView . label_columns <EOL> definitions = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : pretty_month_year , <EOL> '<STR_LIT>' : [ ( aggregate_count , '<STR_LIT>' ) ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : pretty_year , <EOL> '<STR_LIT>' : [ ( aggregate_count , '<STR_LIT>' ) ] <EOL> } <EOL> ] <EOL> db . create_all ( ) <EOL> fill_gender ( ) <EOL> appbuilder . add_view ( GroupModelView , "<STR_LIT>" , icon = "<STR_LIT>" , category = "<STR_LIT>" , category_icon = '<STR_LIT>' ) <EOL> appbuilder . add_view ( ContactModelView , "<STR_LIT>" , icon = "<STR_LIT>" , category = "<STR_LIT>" ) <EOL> appbuilder . add_separator ( "<STR_LIT>" ) <EOL> appbuilder . add_view ( ContactChartView , "<STR_LIT>" , icon = "<STR_LIT>" , category = "<STR_LIT>" ) <EOL> appbuilder . add_view ( ContactTimeChartView , "<STR_LIT>" , icon = "<STR_LIT>" , category = "<STR_LIT>" ) <EOL> log . info ( "<STR_LIT>" . format ( appbuilder . version ) ) <EOL> log . info ( "<STR_LIT>" . format ( UserExtensionMixin . __subclasses__ ( ) [ <NUM_LIT:0> ] ) ) </s>
