<s> import re <EOL> from django import template <EOL> from django . utils . translation import ugettext <EOL> import phonenumbers <EOL> from . . models import PhoneDevice <EOL> register = template . Library ( ) <EOL> phone_mask = re . compile ( '<STR_LIT>' ) <EOL> @ register . filter <EOL> def mask_phone_number ( number ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( number , phonenumbers . PhoneNumber ) : <EOL> number = format_phone_number ( number ) <EOL> return phone_mask . sub ( '<STR_LIT:*>' , number ) <EOL> @ register . filter <EOL> def format_phone_number ( number ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( number , phonenumbers . PhoneNumber ) : <EOL> number = phonenumbers . parse ( number ) <EOL> return phonenumbers . format_number ( number , phonenumbers . PhoneNumberFormat . INTERNATIONAL ) <EOL> @ register . filter <EOL> def device_action ( device ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( device , PhoneDevice ) <EOL> number = mask_phone_number ( format_phone_number ( device . number ) ) <EOL> if device . method == '<STR_LIT>' : <EOL> return ugettext ( '<STR_LIT>' ) % number <EOL> elif device . method == '<STR_LIT>' : <EOL> return ugettext ( '<STR_LIT>' ) % number <EOL> raise NotImplementedError ( '<STR_LIT>' % device . method ) </s>
