<s> from nose . tools import eq_ , ok_ <EOL> from nose . plugins . skip import SkipTest <EOL> from flask . ext . admin . _compat import PY2 , as_unicode <EOL> if not PY2 : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> from wtforms import fields <EOL> from flask . ext . admin import form <EOL> from flask . ext . admin . contrib . mongoengine import ModelView <EOL> from . import setup <EOL> from datetime import datetime <EOL> class CustomModelView ( ModelView ) : <EOL> def __init__ ( self , model , <EOL> name = None , category = None , endpoint = None , url = None , <EOL> ** kwargs ) : <EOL> for k , v in kwargs . iteritems ( ) : <EOL> setattr ( self , k , v ) <EOL> super ( CustomModelView , self ) . __init__ ( model , <EOL> name , category , <EOL> endpoint , url ) <EOL> def create_models ( db ) : <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> test2 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> test3 = db . StringField ( ) <EOL> test4 = db . StringField ( ) <EOL> datetime_field = db . DateTimeField ( ) <EOL> def __str__ ( self ) : <EOL> return self . test1 <EOL> class Model2 ( db . Document ) : <EOL> string_field = db . StringField ( ) <EOL> int_field = db . IntField ( ) <EOL> float_field = db . FloatField ( ) <EOL> bool_field = db . BooleanField ( ) <EOL> model1 = db . ReferenceField ( Model1 ) <EOL> Model1 . objects . delete ( ) <EOL> Model2 . objects . delete ( ) <EOL> return Model1 , Model2 <EOL> def fill_db ( Model1 , Model2 ) : <EOL> Model1 ( '<STR_LIT>' , '<STR_LIT>' ) . save ( ) <EOL> Model1 ( '<STR_LIT>' , '<STR_LIT>' ) . save ( ) <EOL> Model1 ( '<STR_LIT>' , '<STR_LIT>' ) . save ( ) <EOL> Model1 ( '<STR_LIT>' , '<STR_LIT>' ) . save ( ) <EOL> Model1 ( None , '<STR_LIT>' ) . save ( ) <EOL> Model2 ( '<STR_LIT>' , None , None ) . save ( ) <EOL> Model2 ( '<STR_LIT>' , None , None ) . save ( ) <EOL> Model2 ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> ) . save ( ) <EOL> Model2 ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> ) . save ( ) <EOL> Model1 ( '<STR_LIT>' , datetime_field = datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:0> ) ) . save ( ) <EOL> Model1 ( '<STR_LIT>' , datetime_field = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> ) ) . save ( ) <EOL> def test_model ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> view = CustomModelView ( Model1 ) <EOL> admin . add_view ( view ) <EOL> eq_ ( view . model , Model1 ) <EOL> eq_ ( view . name , '<STR_LIT>' ) <EOL> eq_ ( view . endpoint , '<STR_LIT>' ) <EOL> eq_ ( view . _primary_key , '<STR_LIT:id>' ) <EOL> ok_ ( '<STR_LIT>' in view . _sortable_columns ) <EOL> ok_ ( '<STR_LIT>' in view . _sortable_columns ) <EOL> ok_ ( '<STR_LIT>' in view . _sortable_columns ) <EOL> ok_ ( '<STR_LIT>' in view . _sortable_columns ) <EOL> ok_ ( view . _create_form_class is not None ) <EOL> ok_ ( view . _edit_form_class is not None ) <EOL> eq_ ( view . _search_supported , False ) <EOL> eq_ ( view . _filters , None ) <EOL> eq_ ( view . _create_form_class . test1 . field_class , fields . StringField ) <EOL> eq_ ( view . _create_form_class . test2 . field_class , fields . StringField ) <EOL> eq_ ( view . _create_form_class . test3 . field_class , fields . TextAreaField ) <EOL> eq_ ( view . _create_form_class . test4 . field_class , fields . TextAreaField ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( test1 = '<STR_LIT>' , test2 = '<STR_LIT>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> model = Model1 . objects . first ( ) <EOL> eq_ ( model . test1 , '<STR_LIT>' ) <EOL> eq_ ( model . test2 , '<STR_LIT>' ) <EOL> eq_ ( model . test3 , '<STR_LIT>' ) <EOL> eq_ ( model . test4 , '<STR_LIT>' ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> ok_ ( '<STR_LIT>' in rv . data ) <EOL> url = '<STR_LIT>' % model . id <EOL> rv = client . get ( url ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( url , <EOL> data = dict ( test1 = '<STR_LIT>' , test2 = '<STR_LIT>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> model = Model1 . objects . first ( ) <EOL> eq_ ( model . test1 , '<STR_LIT>' ) <EOL> eq_ ( model . test2 , '<STR_LIT>' ) <EOL> eq_ ( model . test3 , '<STR_LIT>' ) <EOL> eq_ ( model . test4 , '<STR_LIT>' ) <EOL> url = '<STR_LIT>' % model . id <EOL> rv = client . post ( url ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> eq_ ( Model1 . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_column_editable_list ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> view = CustomModelView ( Model1 , <EOL> column_editable_list = [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> admin . add_view ( view ) <EOL> fill_db ( Model1 , Model2 ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> obj1 = Model1 . objects . get ( test1 = '<STR_LIT>' ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' + str ( obj1 . id ) : '<STR_LIT>' , <EOL> } ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' == data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> obj2 = Model1 . objects . get ( test1 = '<STR_LIT>' ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' + str ( obj2 . id ) : '<STR_LIT>' , <EOL> } ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> view = CustomModelView ( Model2 , <EOL> column_editable_list = [ <EOL> '<STR_LIT>' ] ) <EOL> admin . add_view ( view ) <EOL> obj3 = Model2 . objects . get ( string_field = '<STR_LIT>' ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' + str ( obj3 . id ) : str ( obj1 . id ) , <EOL> } ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' == data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> def test_column_filters ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> fill_db ( Model1 , Model2 ) <EOL> view = CustomModelView ( Model1 , column_filters = [ '<STR_LIT>' ] ) <EOL> admin . add_view ( view ) <EOL> eq_ ( len ( view . _filters ) , <NUM_LIT:7> ) <EOL> eq_ ( [ ( f [ '<STR_LIT:index>' ] , f [ '<STR_LIT>' ] ) for f in view . _filter_groups [ u'<STR_LIT>' ] ] , <EOL> [ <EOL> ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ] ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> view = CustomModelView ( Model2 , column_filters = [ '<STR_LIT>' ] ) <EOL> admin . add_view ( view ) <EOL> eq_ ( [ ( f [ '<STR_LIT:index>' ] , f [ '<STR_LIT>' ] ) for f in view . _filter_groups [ u'<STR_LIT>' ] ] , <EOL> [ <EOL> ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ] ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> view = CustomModelView ( Model2 , column_filters = [ '<STR_LIT>' ] , <EOL> endpoint = "<STR_LIT>" ) <EOL> admin . add_view ( view ) <EOL> eq_ ( [ ( f [ '<STR_LIT:index>' ] , f [ '<STR_LIT>' ] ) for f in view . _filter_groups [ u'<STR_LIT>' ] ] , <EOL> [ <EOL> ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ] ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> view = CustomModelView ( Model1 , <EOL> column_filters = [ '<STR_LIT>' ] , <EOL> endpoint = "<STR_LIT>" ) <EOL> admin . add_view ( view ) <EOL> eq_ ( [ ( f [ '<STR_LIT:index>' ] , f [ '<STR_LIT>' ] ) for f in view . _filter_groups [ u'<STR_LIT>' ] ] , <EOL> [ <EOL> ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ] ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> def test_default_sort ( ) : <EOL> app , db , admin = setup ( ) <EOL> M1 , _ = create_models ( db ) <EOL> M1 ( test1 = '<STR_LIT:c>' ) . save ( ) <EOL> M1 ( test1 = '<STR_LIT:b>' ) . save ( ) <EOL> M1 ( test1 = '<STR_LIT:a>' ) . save ( ) <EOL> eq_ ( M1 . objects . count ( ) , <NUM_LIT:3> ) <EOL> view = CustomModelView ( M1 , column_default_sort = '<STR_LIT>' ) <EOL> admin . add_view ( view ) <EOL> _ , data = view . get_list ( <NUM_LIT:0> , None , None , None , None ) <EOL> eq_ ( data [ <NUM_LIT:0> ] . test1 , '<STR_LIT:a>' ) <EOL> eq_ ( data [ <NUM_LIT:1> ] . test1 , '<STR_LIT:b>' ) <EOL> eq_ ( data [ <NUM_LIT:2> ] . test1 , '<STR_LIT:c>' ) <EOL> def test_extra_fields ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> view = CustomModelView ( <EOL> Model1 , <EOL> form_extra_fields = { <EOL> '<STR_LIT>' : fields . StringField ( '<STR_LIT>' ) <EOL> } <EOL> ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> pos1 = data . find ( '<STR_LIT>' ) <EOL> pos2 = data . find ( '<STR_LIT>' ) <EOL> ok_ ( pos2 < pos1 ) <EOL> def test_extra_field_order ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> view = CustomModelView ( <EOL> Model1 , <EOL> form_columns = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> form_extra_fields = { <EOL> '<STR_LIT>' : fields . StringField ( '<STR_LIT>' ) <EOL> } <EOL> ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> pos1 = data . find ( '<STR_LIT>' ) <EOL> pos2 = data . find ( '<STR_LIT>' ) <EOL> ok_ ( pos2 > pos1 ) <EOL> def test_custom_form_base ( ) : <EOL> app , db , admin = setup ( ) <EOL> class TestForm ( form . BaseForm ) : <EOL> pass <EOL> Model1 , _ = create_models ( db ) <EOL> view = CustomModelView ( <EOL> Model1 , <EOL> form_base_class = TestForm <EOL> ) <EOL> admin . add_view ( view ) <EOL> ok_ ( hasattr ( view . _create_form_class , '<STR_LIT>' ) ) <EOL> create_form = view . create_form ( ) <EOL> ok_ ( isinstance ( create_form , TestForm ) ) <EOL> def test_subdocument_config ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Comment ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> value = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> subdoc = db . EmbeddedDocumentField ( Comment ) <EOL> view1 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) <EOL> } <EOL> } <EOL> ) <EOL> ok_ ( hasattr ( view1 . _create_form_class , '<STR_LIT>' ) ) <EOL> form = view1 . create_form ( ) <EOL> ok_ ( '<STR_LIT:name>' in dir ( form . subdoc . form ) ) <EOL> ok_ ( '<STR_LIT:value>' not in dir ( form . subdoc . form ) ) <EOL> view2 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( '<STR_LIT:value>' , ) <EOL> } <EOL> } <EOL> ) <EOL> form = view2 . create_form ( ) <EOL> ok_ ( '<STR_LIT:name>' in dir ( form . subdoc . form ) ) <EOL> ok_ ( '<STR_LIT:value>' not in dir ( form . subdoc . form ) ) <EOL> def test_subdocument_class_config ( ) : <EOL> app , db , admin = setup ( ) <EOL> from flask . ext . admin . contrib . mongoengine import EmbeddedForm <EOL> class Comment ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> value = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> subdoc = db . EmbeddedDocumentField ( Comment ) <EOL> class EmbeddedConfig ( EmbeddedForm ) : <EOL> form_columns = ( '<STR_LIT:name>' , ) <EOL> view1 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : EmbeddedConfig ( ) <EOL> } <EOL> ) <EOL> form = view1 . create_form ( ) <EOL> ok_ ( '<STR_LIT:name>' in dir ( form . subdoc . form ) ) <EOL> ok_ ( '<STR_LIT:value>' not in dir ( form . subdoc . form ) ) <EOL> def test_nested_subdocument_config ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Comment ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> value = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> class Nested ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> comment = db . EmbeddedDocumentField ( Comment ) <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> nested = db . EmbeddedDocumentField ( Nested ) <EOL> view1 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> ) <EOL> form = view1 . create_form ( ) <EOL> ok_ ( '<STR_LIT:name>' in dir ( form . nested . form . comment . form ) ) <EOL> ok_ ( '<STR_LIT:value>' not in dir ( form . nested . form . comment . form ) ) <EOL> def test_nested_list_subdocument ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Comment ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> value = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> subdoc = db . ListField ( db . EmbeddedDocumentField ( Comment ) ) <EOL> view1 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> None : { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> ) <EOL> form = view1 . create_form ( ) <EOL> inline_form = form . subdoc . unbound_field . args [ <NUM_LIT:2> ] <EOL> ok_ ( '<STR_LIT:name>' in dir ( inline_form ) ) <EOL> ok_ ( '<STR_LIT:value>' not in dir ( inline_form ) ) <EOL> def test_ajax_fk ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> view = CustomModelView ( <EOL> Model2 , <EOL> url = '<STR_LIT>' , <EOL> form_ajax_refs = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> } <EOL> } <EOL> ) <EOL> admin . add_view ( view ) <EOL> ok_ ( u'<STR_LIT>' in view . _form_ajax_refs ) <EOL> model = Model1 ( test1 = u'<STR_LIT>' ) <EOL> model . save ( ) <EOL> model2 = Model1 ( test1 = u'<STR_LIT:foo>' , test2 = u'<STR_LIT:bar>' ) . save ( ) <EOL> loader = view . _form_ajax_refs [ u'<STR_LIT>' ] <EOL> mdl = loader . get_one ( model . id ) <EOL> eq_ ( mdl . test1 , model . test1 ) <EOL> items = loader . get_list ( u'<STR_LIT>' ) <EOL> eq_ ( len ( items ) , <NUM_LIT:1> ) <EOL> eq_ ( items [ <NUM_LIT:0> ] . id , model . id ) <EOL> items = loader . get_list ( u'<STR_LIT:bar>' ) <EOL> eq_ ( len ( items ) , <NUM_LIT:1> ) <EOL> eq_ ( items [ <NUM_LIT:0> ] . test1 , u'<STR_LIT:foo>' ) <EOL> form = view . create_form ( ) <EOL> eq_ ( form . model1 . __class__ . __name__ , u'<STR_LIT>' ) <EOL> with app . test_request_context ( '<STR_LIT>' ) : <EOL> ok_ ( u'<STR_LIT>' not in form . model1 ( ) ) <EOL> form . model1 . data = model <EOL> needle = u'<STR_LIT>' % as_unicode ( model . id ) <EOL> ok_ ( needle in form . model1 ( ) ) <EOL> ok_ ( u'<STR_LIT>' % as_unicode ( model . id ) in form . model1 ( ) ) <EOL> client = app . test_client ( ) <EOL> req = client . get ( u'<STR_LIT>' ) <EOL> eq_ ( req . data , u'<STR_LIT>' % model2 . id ) <EOL> client . post ( '<STR_LIT>' , data = { u'<STR_LIT>' : as_unicode ( model . id ) } ) <EOL> mdl = Model2 . objects . first ( ) <EOL> ok_ ( mdl is not None ) <EOL> ok_ ( mdl . model1 is not None ) <EOL> eq_ ( mdl . model1 . id , model . id ) <EOL> eq_ ( mdl . model1 . test1 , u'<STR_LIT>' ) <EOL> def test_nested_ajax_refs ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Comment ( db . Document ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> value = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> class Nested ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , required = True ) <EOL> comment = db . ReferenceField ( Comment ) <EOL> class Model1 ( db . Document ) : <EOL> test1 = db . StringField ( max_length = <NUM_LIT:20> ) <EOL> nested = db . EmbeddedDocumentField ( Nested ) <EOL> view1 = CustomModelView ( <EOL> Model1 , <EOL> form_subdocuments = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT:name>' ] <EOL> } <EOL> } <EOL> } <EOL> } <EOL> ) <EOL> form = view1 . create_form ( ) <EOL> eq_ ( type ( form . nested . form . comment ) . __name__ , '<STR_LIT>' ) <EOL> ok_ ( '<STR_LIT>' in view1 . _form_ajax_refs ) <EOL> def test_form_flat_choices ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Model ( db . Document ) : <EOL> name = db . StringField ( max_length = <NUM_LIT:20> , choices = ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) ) <EOL> view = CustomModelView ( Model ) <EOL> admin . add_view ( view ) <EOL> form = view . create_form ( ) <EOL> eq_ ( form . name . choices , [ ( '<STR_LIT:a>' , '<STR_LIT:a>' ) , ( '<STR_LIT:b>' , '<STR_LIT:b>' ) , ( '<STR_LIT:c>' , '<STR_LIT:c>' ) ] ) <EOL> def test_form_args_embeddeddoc ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Info ( db . EmbeddedDocument ) : <EOL> name = db . StringField ( ) <EOL> age = db . StringField ( ) <EOL> class Model ( db . Document ) : <EOL> info = db . EmbeddedDocumentField ( '<STR_LIT>' ) <EOL> timestamp = db . DateTimeField ( ) <EOL> view = CustomModelView ( <EOL> Model , <EOL> form_args = { <EOL> '<STR_LIT:info>' : { '<STR_LIT:label>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:label>' : '<STR_LIT>' } <EOL> } <EOL> ) <EOL> admin . add_view ( view ) <EOL> form = view . create_form ( ) <EOL> eq_ ( form . timestamp . label . text , '<STR_LIT>' ) <EOL> eq_ ( form . info . label . text , '<STR_LIT>' ) </s>
