<s> from django . contrib . auth . models import AbstractBaseUser , PermissionsMixin <EOL> from django . contrib . auth . models import UserManager <EOL> from django . contrib . flatpages . models import FlatPage <EOL> from django . core . urlresolvers import reverse <EOL> from django . db . models import signals <EOL> from django . templatetags . static import static <EOL> from django . utils import timezone <EOL> from django . db import models <EOL> from allauth . account . models import EmailAddress <EOL> from django_countries . fields import CountryField <EOL> from skills . models import Skill , TrainingBit <EOL> class CustomUserManager ( UserManager ) : <EOL> def create_superuser ( self , username , password , ** kwargs ) : <EOL> user = self . model ( username = username , is_staff = True , is_superuser = True , ** kwargs ) <EOL> user . set_password ( password ) <EOL> user . save ( ) <EOL> return user <EOL> class User ( AbstractBaseUser , PermissionsMixin ) : <EOL> USERNAME_FIELD = '<STR_LIT:username>' <EOL> datetime_joined = models . DateTimeField ( default = timezone . now ) <EOL> username = models . CharField ( max_length = <NUM_LIT> , unique = True , error_messages = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> email = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> image = models . ImageField ( upload_to = '<STR_LIT>' , null = True , blank = True ) <EOL> description = models . TextField ( blank = True ) <EOL> skills_in_progress = models . ManyToManyField ( Skill , blank = True , related_name = '<STR_LIT>' ) <EOL> skills_completed = models . ManyToManyField ( Skill , blank = True , related_name = '<STR_LIT>' ) <EOL> trainingbits_in_progress = models . ManyToManyField ( TrainingBit , blank = True , related_name = '<STR_LIT>' ) <EOL> trainingbits_completed = models . ManyToManyField ( TrainingBit , blank = True , related_name = '<STR_LIT>' ) <EOL> is_active = models . BooleanField ( default = True ) <EOL> has_been_welcomed = models . BooleanField ( default = False ) <EOL> def is_taking_skill ( self , skill ) : <EOL> return skill in self . skills_in_progress . all ( ) <EOL> def complete_skill ( self , completed_skill ) : <EOL> skills = self . complete_skills ( [ complete_skill ] ) <EOL> return skills [ <NUM_LIT:0> ] <EOL> def complete_skills ( self , completed_skills ) : <EOL> self . skills_in_progress . remove ( * completed_skills ) <EOL> self . skills_completed . add ( * completed_skills ) <EOL> return completed_skills <EOL> def has_completed_skill ( self , skill ) : <EOL> return skill in self . skills_completed . all ( ) <EOL> def is_taking_trainingbit ( self , trainingbit ) : <EOL> return trainingbit in self . trainingbits_in_progress . all ( ) <EOL> def complete_trainingbit ( self , completed_trainingbit ) : <EOL> tbs = self . complete_trainingbits ( [ completed_trainingbit ] ) <EOL> return tbs [ <NUM_LIT:0> ] <EOL> def complete_trainingbits ( self , completed_trainingbits ) : <EOL> self . trainingbits_in_progress . remove ( * completed_trainingbits ) <EOL> self . trainingbits_completed . add ( * completed_trainingbits ) <EOL> return completed_trainingbits <EOL> def has_completed_trainingbit ( self , trainingbit ) : <EOL> return trainingbit in self . trainingbits_completed . all ( ) <EOL> def get_full_name ( self ) : <EOL> return self . email <EOL> def get_short_name ( self ) : <EOL> return self . email <EOL> objects = CustomUserManager ( ) <EOL> def account_verified ( self ) : <EOL> if self . user . is_authenticated : <EOL> result = EmailAddress . objects . get_primary ( self . user ) <EOL> if len ( result ) : <EOL> return result [ <NUM_LIT:0> ] . verified <EOL> return False <EOL> @ property <EOL> def is_trainer ( self ) : <EOL> if self . is_admin : <EOL> return True <EOL> return self . groups . filter ( name = '<STR_LIT>' ) <EOL> @ property <EOL> def is_admin ( self ) : <EOL> return self . groups . filter ( name = '<STR_LIT>' ) or self . is_superuser <EOL> @ property <EOL> def is_staff ( self ) : <EOL> "<STR_LIT>" <EOL> return self . is_admin or self . is_trainer <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . id ] ) <EOL> def getImage ( self ) : <EOL> if self . image : <EOL> return self . image . url <EOL> else : <EOL> return static ( '<STR_LIT>' ) <EOL> class UserInfo ( models . Model ) : <EOL> SEXES = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> ORGANISATION_TYPES = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> sex = models . CharField ( max_length = <NUM_LIT:20> , choices = SEXES , blank = False ) <EOL> country = CountryField ( null = True ) <EOL> birthdate = models . DateField ( null = True ) <EOL> organization = models . CharField ( max_length = <NUM_LIT:15> , choices = ORGANISATION_TYPES , blank = False ) <EOL> user = models . OneToOneField ( User , null = True , blank = True ) <EOL> def get_or_create_userinfo ( user ) : <EOL> """<STR_LIT>""" <EOL> userinfo , c = UserInfo . objects . get_or_create ( user = user ) <EOL> return userinfo <EOL> User . userinfo = property ( get_or_create_userinfo ) <EOL> class GCLFlatPage ( FlatPage ) : <EOL> show_in_footer = models . BooleanField ( default = False ) <EOL> class Meta : <EOL> verbose_name = "<STR_LIT>" <EOL> verbose_name_plural = "<STR_LIT>" <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . url ] ) <EOL> from solo . models import SingletonModel <EOL> class SiteConfiguration ( SingletonModel ) : <EOL> analytics_code = models . TextField ( help_text = '<STR_LIT>' ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class Meta : <EOL> verbose_name = "<STR_LIT>" <EOL> verbose_name_plural = "<STR_LIT>" </s>
