<s> from datetime import date <EOL> from dateutil . relativedelta import relativedelta <EOL> from django . contrib . auth . models import User <EOL> from django . db import models <EOL> from django . db . models . signals import post_save <EOL> from django . utils import timezone <EOL> from settings import AVAILABLE_TEMPLATES , DEFAULT_TEMPLATE <EOL> from mod . models import Mod , Option , Server , Tune <EOL> def get_template ( request ) : <EOL> if not request . user . is_authenticated ( ) : <EOL> return DEFAULT_TEMPLATE <EOL> template = request . user . profile . template <EOL> if template not in [ template_ [ <NUM_LIT:0> ] for template_ in AVAILABLE_TEMPLATES if template_ [ <NUM_LIT:2> ] or request . user . is_staff ] : <EOL> template = DEFAULT_TEMPLATE <EOL> request . user . profile . template = template <EOL> request . user . profile . save ( ) <EOL> return template <EOL> class UserProfile ( models . Model ) : <EOL> user = models . OneToOneField ( User , unique = True , related_name = '<STR_LIT>' ) <EOL> template = models . CharField ( max_length = <NUM_LIT:100> , default = DEFAULT_TEMPLATE ) <EOL> allowed_mods = models . ManyToManyField ( Mod , blank = True , related_name = '<STR_LIT>' ) <EOL> GENDER_NONE = <NUM_LIT:1> <EOL> GENDER_MALE = <NUM_LIT:2> <EOL> GENDER_FEMALE = <NUM_LIT:3> <EOL> GEDGET_CHOICES = ( <EOL> ( GENDER_NONE , '<STR_LIT>' ) , <EOL> ( GENDER_MALE , '<STR_LIT>' ) , <EOL> ( GENDER_FEMALE , '<STR_LIT>' ) , <EOL> ) <EOL> gender = models . IntegerField ( choices = GEDGET_CHOICES , default = GENDER_NONE ) <EOL> publish_gender = models . BooleanField ( default = False ) <EOL> birthday = models . DateField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> publish_birthday = models . BooleanField ( default = False ) <EOL> ingame_name = models . CharField ( max_length = <NUM_LIT:20> , blank = True , null = True , default = '<STR_LIT>' ) <EOL> publish_ingame_name = models . BooleanField ( default = False ) <EOL> fav_map = models . CharField ( max_length = <NUM_LIT:50> , blank = True , null = True , default = '<STR_LIT>' , verbose_name = '<STR_LIT>' ) <EOL> publish_fav_map = models . BooleanField ( default = False ) <EOL> fav_mod = models . CharField ( max_length = <NUM_LIT:20> , blank = True , null = True , default = '<STR_LIT>' , verbose_name = '<STR_LIT>' ) <EOL> publish_fav_mod = models . BooleanField ( default = False ) <EOL> contact = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True , default = '<STR_LIT>' ) <EOL> publish_contact = models . BooleanField ( default = False ) <EOL> website = models . URLField ( blank = True , null = True , default = '<STR_LIT>' ) <EOL> publish_website = models . BooleanField ( default = False ) <EOL> publish_name = models . BooleanField ( default = False ) <EOL> def active_servers ( self ) : <EOL> return self . user . servers . filter ( is_active = True ) <EOL> def online_servers ( self ) : <EOL> return self . user . servers . filter ( is_active = True , online = True ) <EOL> def active_count ( self ) : <EOL> return len ( self . user . servers . filter ( is_active = True ) ) <EOL> def online_count ( self ) : <EOL> return len ( self . user . servers . filter ( is_active = True , online = True ) ) <EOL> @ property <EOL> def get_age ( self ) : <EOL> age = relativedelta ( dt1 = date . today ( ) , dt2 = self . birthday ) . years <EOL> if age < <NUM_LIT:8> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif age < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> possessive = '<STR_LIT>' if self . user . username . endswith ( '<STR_LIT:s>' ) else '<STR_LIT:s>' <EOL> return u"<STR_LIT>" . format ( self . user . username , possessive ) <EOL> class Moderator ( models . Model ) : <EOL> server = models . ForeignKey ( Server , related_name = '<STR_LIT>' ) <EOL> user = models . ForeignKey ( User , related_name = '<STR_LIT>' ) <EOL> restart_allowed = models . BooleanField ( default = False ) <EOL> edit_automatic_restart_allowed = models . BooleanField ( default = False ) <EOL> edit_map_download_allowed = models . BooleanField ( default = False ) <EOL> edit_votes_allowed = models . BooleanField ( default = False ) <EOL> map_upload_allowed = models . BooleanField ( default = False ) <EOL> console_allowed = models . BooleanField ( default = False ) <EOL> edit_rcon_commands_allowed = models . BooleanField ( default = False ) <EOL> allowed_options = models . ManyToManyField ( Option , related_name = '<STR_LIT>' ) <EOL> allowed_tunings = models . ManyToManyField ( Tune , related_name = '<STR_LIT>' ) <EOL> class Activation ( models . Model ) : <EOL> user = models . OneToOneField ( User , unique = True , related_name = '<STR_LIT>' ) <EOL> key = models . CharField ( max_length = <NUM_LIT:32> , unique = True , null = True ) <EOL> def post_user_save ( instance , ** kwargs ) : <EOL> if kwargs [ '<STR_LIT>' ] : <EOL> profile = UserProfile ( user = instance ) <EOL> profile . save ( ) <EOL> post_save . connect ( post_user_save , sender = User , dispatch_uid = '<STR_LIT>' ) </s>
