<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from djblets . db . fields import JSONField <EOL> from reviewboard . hostingsvcs . managers import HostingServiceAccountManager <EOL> from reviewboard . hostingsvcs . service import get_hosting_service <EOL> from reviewboard . site . models import LocalSite <EOL> @ python_2_unicode_compatible <EOL> class HostingServiceAccount ( models . Model ) : <EOL> service_name = models . CharField ( max_length = <NUM_LIT> ) <EOL> hosting_url = models . CharField ( max_length = <NUM_LIT:255> , blank = True , null = True ) <EOL> username = models . CharField ( max_length = <NUM_LIT> ) <EOL> data = JSONField ( ) <EOL> visible = models . BooleanField ( default = True ) <EOL> local_site = models . ForeignKey ( LocalSite , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> blank = True , <EOL> null = True ) <EOL> objects = HostingServiceAccountManager ( ) <EOL> def __str__ ( self ) : <EOL> return self . username <EOL> @ property <EOL> def service ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> cls = get_hosting_service ( self . service_name ) <EOL> if cls : <EOL> self . _service = cls ( self ) <EOL> else : <EOL> self . _service = None <EOL> return self . _service <EOL> @ property <EOL> def is_authorized ( self ) : <EOL> service = self . service <EOL> if service : <EOL> return service . is_authorized ( ) <EOL> else : <EOL> return False <EOL> def is_accessible_by ( self , user ) : <EOL> """<STR_LIT>""" <EOL> return not self . local_site or self . local_site . is_accessible_by ( user ) <EOL> def is_mutable_by ( self , user ) : <EOL> """<STR_LIT>""" <EOL> return user . has_perm ( '<STR_LIT>' , <EOL> self . local_site ) </s>
