<s> from __future__ import unicode_literals <EOL> import logging <EOL> import os <EOL> from unicodedata import normalize <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User , Group <EOL> from django . contrib . sites . models import Site <EOL> from django . db import models <EOL> from django . db . models . signals import post_save <EOL> from django . utils import six <EOL> from django . utils . encoding import python_2_unicode_compatible , force_text <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> import django_mobile_app_distribution . settings as app_dist_settings <EOL> from django_mobile_app_distribution . exceptions import MobileAppDistributionConfigurationException <EOL> from django_mobile_app_distribution . storage import CustomFileSystemStorage <EOL> if six . PY2 : <EOL> from urlparse import urljoin <EOL> else : <EOL> from urllib . parse import urljoin <EOL> log = logging . getLogger ( __name__ ) <EOL> _MISSING_SITE_MESSAGE = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> def normalize_filename ( dirname , filename ) : <EOL> dirname = force_text ( dirname ) <EOL> filename = force_text ( normalize ( '<STR_LIT>' , filename ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> return force_text ( os . path . join ( dirname , filename ) ) <EOL> def normalize_ios_filename ( instance , filename ) : <EOL> return normalize_filename ( app_dist_settings . MOBILE_APP_DISTRIBUTION_IOS_UPLOAD_TO_DIRECTORY_NAME , filename ) <EOL> def normalize_android_filename ( instance , filename ) : <EOL> return normalize_filename ( app_dist_settings . MOBILE_APP_DISTRIBUTION_ANDROID_UPLOAD_TO_DIRECTORY_NAME , filename ) <EOL> def normalize_image_filename ( instance , filename ) : <EOL> return normalize_filename ( app_dist_settings . MOBILE_APP_DISTRIBUTION_APP_ICON_DIRECTORY_NAME , filename ) <EOL> @ python_2_unicode_compatible <EOL> class UserInfo ( models . Model ) : <EOL> user = models . OneToOneField ( User , verbose_name = _ ( '<STR_LIT:user>' ) ) <EOL> language = models . CharField ( max_length = <NUM_LIT:20> , choices = app_dist_settings . LANGUAGES , default = app_dist_settings . ENGLISH , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> def __str__ ( self ) : <EOL> return self . user . username <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> @ python_2_unicode_compatible <EOL> class App ( models . Model ) : <EOL> user = models . ForeignKey ( User , blank = True , null = True , default = None , related_name = '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> groups = models . ManyToManyField ( <EOL> Group , <EOL> blank = True , <EOL> related_name = '<STR_LIT>' , <EOL> default = None , <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> ) <EOL> name = models . CharField ( max_length = <NUM_LIT:200> , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> comment = models . CharField ( max_length = <NUM_LIT:200> , verbose_name = _ ( '<STR_LIT>' ) , blank = True , null = True ) <EOL> version = models . CharField ( max_length = <NUM_LIT:200> , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> updatedAt = models . DateTimeField ( auto_now = True , editable = False , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> createdAt = models . DateTimeField ( auto_now_add = True , editable = False , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class IosApp ( App ) : <EOL> operating_system = models . CharField ( <EOL> max_length = <NUM_LIT:50> , <EOL> choices = app_dist_settings . OS_CHOICES , <EOL> default = app_dist_settings . IOS , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> editable = False <EOL> ) <EOL> app_binary = models . FileField ( upload_to = normalize_ios_filename , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> bundle_identifier = models . CharField ( <EOL> max_length = <NUM_LIT:200> , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> default = '<STR_LIT>' , <EOL> help_text = _ ( '<STR_LIT>' ) <EOL> ) <EOL> display_image = models . ImageField ( <EOL> upload_to = normalize_image_filename , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> default = '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' , <EOL> blank = True <EOL> ) <EOL> full_size_image = models . ImageField ( <EOL> upload_to = normalize_image_filename , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> default = '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' , <EOL> blank = True <EOL> ) <EOL> def get_binary_url ( self ) : <EOL> if not self . app_binary : <EOL> return None <EOL> Site . objects . clear_cache ( ) <EOL> try : <EOL> Site . objects . get_current ( ) <EOL> except Exception : <EOL> raise MobileAppDistributionConfigurationException ( _MISSING_SITE_MESSAGE ) <EOL> return urljoin ( Site . objects . get_current ( ) . domain , self . app_binary . url ) <EOL> def get_plist_url ( self ) : <EOL> Site . objects . clear_cache ( ) <EOL> current_site = None <EOL> try : <EOL> current_site = Site . objects . get_current ( ) <EOL> except Exception : <EOL> raise MobileAppDistributionConfigurationException ( _MISSING_SITE_MESSAGE ) <EOL> return urljoin ( <EOL> current_site . domain , <EOL> reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . pk } ) <EOL> ) <EOL> def get_display_image_url ( self ) : <EOL> Site . objects . clear_cache ( ) <EOL> current_site = None <EOL> try : <EOL> current_site = Site . objects . get_current ( ) <EOL> except Exception : <EOL> raise MobileAppDistributionConfigurationException ( _MISSING_SITE_MESSAGE ) <EOL> return urljoin ( Site . objects . get_current ( ) . domain , self . display_image . url ) <EOL> def get_full_size_image_url ( self ) : <EOL> Site . objects . clear_cache ( ) <EOL> current_site = None <EOL> try : <EOL> current_site = Site . objects . get_current ( ) <EOL> except Exception : <EOL> raise MobileAppDistributionConfigurationException ( _MISSING_SITE_MESSAGE ) <EOL> return urljoin ( Site . objects . get_current ( ) . domain , self . full_size_image . url ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> fs = CustomFileSystemStorage ( ) <EOL> class AndroidApp ( App ) : <EOL> operating_system = models . CharField ( <EOL> max_length = <NUM_LIT:50> , <EOL> choices = app_dist_settings . OS_CHOICES , <EOL> default = app_dist_settings . ANDROID , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> editable = False <EOL> ) <EOL> app_binary = models . FileField ( upload_to = normalize_android_filename , verbose_name = _ ( '<STR_LIT>' ) , storage = fs ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> def create_user_info ( sender , instance , created , ** kwargs ) : <EOL> try : <EOL> instance . userinfo <EOL> except Exception : <EOL> try : <EOL> UserInfo . objects . create ( user = instance ) <EOL> except Exception : <EOL> pass <EOL> post_save . connect ( create_user_info , sender = User ) </s>
