<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from . utils . modules import try_import , get_classes <EOL> from . conf import settings <EOL> class ExtensibleModelBase ( models . base . ModelBase ) : <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> try : <EOL> app_label = attrs [ '<STR_LIT:Meta>' ] . app_label <EOL> except KeyError : <EOL> module_name = attrs [ "<STR_LIT>" ] <EOL> app_label = module_name . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> extensions = _find_extensions ( app_label , name ) <EOL> bases = tuple ( extensions ) + bases <EOL> return super ( ExtensibleModelBase , cls ) . __new__ ( <EOL> cls , name , bases , attrs ) <EOL> def _find_extensions ( app_label , model_name ) : <EOL> ext = [ ] <EOL> suffix = "<STR_LIT>" % ( <EOL> app_label , model_name . lower ( ) ) <EOL> modules = filter ( None , [ <EOL> try_import ( "<STR_LIT>" % ( app_name , suffix ) ) <EOL> for app_name in settings . INSTALLED_APPS ] ) <EOL> modules = [ mod for mod in [ <EOL> try_import ( "<STR_LIT>" % ( app_name , suffix ) ) <EOL> for app_name in settings . INSTALLED_APPS ] if mod ] <EOL> for module in modules : <EOL> for cls in get_classes ( module , models . Model ) : <EOL> ext . append ( cls ) <EOL> return ext <EOL> @ python_2_unicode_compatible <EOL> class Backend ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:20> , unique = True ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self ) <EOL> @ python_2_unicode_compatible <EOL> class App ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> module = models . CharField ( max_length = <NUM_LIT:100> , unique = True ) <EOL> active = models . BooleanField ( default = False ) <EOL> def __str__ ( self ) : <EOL> return self . module <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self ) <EOL> @ python_2_unicode_compatible <EOL> class ContactBase ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> created_on = models . DateTimeField ( auto_now_add = True ) <EOL> modified_on = models . DateTimeField ( auto_now = True ) <EOL> language = models . CharField ( max_length = <NUM_LIT:6> , blank = True , <EOL> help_text = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class Meta : <EOL> abstract = True <EOL> def __str__ ( self ) : <EOL> return self . name or "<STR_LIT>" <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self ) <EOL> @ property <EOL> def is_anonymous ( self ) : <EOL> """<STR_LIT>""" <EOL> return not self . name <EOL> @ property <EOL> def default_connection ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . connection_set . count ( ) > <NUM_LIT:0> : <EOL> return self . connection_set . all ( ) [ <NUM_LIT:0> ] <EOL> return None <EOL> class Contact ( ContactBase ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ExtensibleModelBase <EOL> @ python_2_unicode_compatible <EOL> class ConnectionBase ( models . Model ) : <EOL> backend = models . ForeignKey ( Backend ) <EOL> identity = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> contact = models . ForeignKey ( Contact , null = True , blank = True ) <EOL> created_on = models . DateTimeField ( auto_now_add = True ) <EOL> modified_on = models . DateTimeField ( auto_now = True ) <EOL> class Meta : <EOL> abstract = True <EOL> unique_together = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . identity , self . backend ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self ) <EOL> class Connection ( ConnectionBase ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ExtensibleModelBase </s>
