<s> import re <EOL> from django import template <EOL> from social . backends . oauth import OAuthAuth <EOL> from social . apps . django_app . me . models import UserSocialAuth <EOL> register = template . Library ( ) <EOL> name_re = re . compile ( r'<STR_LIT>' ) <EOL> @ register . filter <EOL> def backend_name ( backend ) : <EOL> name = backend . __class__ . __name__ <EOL> name = name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = name_re . sub ( r'<STR_LIT>' , name ) <EOL> return name <EOL> @ register . filter <EOL> def backend_class ( backend ) : <EOL> return backend . name . replace ( '<STR_LIT:->' , '<STR_LIT:U+0020>' ) <EOL> @ register . filter <EOL> def icon_name ( name ) : <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:username>' : '<STR_LIT:user>' , <EOL> } . get ( name , name ) <EOL> @ register . filter <EOL> def social_backends ( backends ) : <EOL> backends = [ ( name , backend ) for name , backend in backends . items ( ) <EOL> if name not in [ '<STR_LIT:username>' , '<STR_LIT:email>' ] ] <EOL> backends . sort ( key = lambda b : b [ <NUM_LIT:0> ] ) <EOL> return [ backends [ n : n + <NUM_LIT:10> ] for n in range ( <NUM_LIT:0> , len ( backends ) , <NUM_LIT:10> ) ] <EOL> @ register . filter <EOL> def legacy_backends ( backends ) : <EOL> backends = [ ( name , backend ) for name , backend in backends . items ( ) <EOL> if name in [ '<STR_LIT:username>' , '<STR_LIT:email>' ] ] <EOL> backends . sort ( key = lambda b : b [ <NUM_LIT:0> ] ) <EOL> return backends <EOL> @ register . filter <EOL> def oauth_backends ( backends ) : <EOL> backends = [ ( name , backend ) for name , backend in backends . items ( ) <EOL> if issubclass ( backend , OAuthAuth ) ] <EOL> backends . sort ( key = lambda b : b [ <NUM_LIT:0> ] ) <EOL> return backends <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def associated ( context , backend ) : <EOL> user = context . get ( '<STR_LIT:user>' ) <EOL> context [ '<STR_LIT>' ] = None <EOL> if user and user . is_authenticated ( ) : <EOL> try : <EOL> context [ '<STR_LIT>' ] = UserSocialAuth . objects . filter ( <EOL> user = user , provider = backend . name <EOL> ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> pass <EOL> return '<STR_LIT>' </s>
