import datetime
from django.db import models
from django.db.models.signals import post_save
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from groupmanager.models import Group


class MotorfleetProfile(models.Model):
    user = models.OneToOneField(User, related_name='motorfleet_profile')
    TITLES = (
    (u'MR', u'Mr.'),
    (u'MRS', u'Mrs.'),
    (u'MS', u'Ms.'),
    (u'DR', u'Dr.'),
    (u'PRO', u'Prof.')
    )
    title = models.CharField(max_length=3, choices=TITLES, verbose_name='Title', blank=True)
    dob = models.DateField(verbose_name='Date of birth', blank=True, null=True)
    OCCUPATIONS = (
		(1, u'Professional Exc.Sport/Tv/Film'),
		(2, u'Company Director'),
		(3, u'Skilled'),
		(4, u'Manual'),
		(5, u'Clerical'),
		(6, u'Customer Services'),
		(7, u'H M Forces'),
		(8, u'Drivers'),
		(9, u'Motor Trade'),
		(10, u'Housewife/Husband'),
		(11, u'Proprietor'),
		(12, u'Student'),
		(13, u'Retired'),
		(14, u'Unemployed')
    )
    occupation = models.DecimalField(max_digits=3, decimal_places=0, choices=OCCUPATIONS, verbose_name='Occupation', blank=True, null=True)
    LICENCE_TYPES = (
    (u'FULL', u'Full'),
    (u'PROV', u'Provisional')
    )
    licence_type = models.CharField(max_length=4, choices=LICENCE_TYPES, verbose_name='Type of licence', blank=True)
    LICENCE_PERIODS = (
    (0, u'0 years'),
    (1, u'1 year'),
    (2, u'2 years'),
    (3, u'3 or more years')
    )
    licence_period = models.DecimalField(max_digits=1, decimal_places=0, choices=LICENCE_PERIODS, verbose_name='Period licence held', blank=True, null=True)
    NCD_PERIODS = (
    (0, u'0 years'),
    (1, u'1 year'),
    (2, u'2 years'),
    (3, u'3 years'),
    (4, u'4 year'),
    (5, u'5 years'),
    (6, u'6 years'),
    (7, u'7 year'),
    (8, u'8 years'),
    (9, u'9 or more years')
    )
    no_claims_discount = models.DecimalField(max_digits=1, decimal_places=0, choices=NCD_PERIODS, verbose_name='No claims discount entitlement', blank=True, null=True)
    mobile_num = models.CharField(max_length=15, blank=True)
    notify_emails = models.BooleanField(default=False)
    news_emails = models.BooleanField(default=False)
    is_betatester = models.BooleanField(default=False)

    def __unicode__(self):
        return self.user.username

    def create_motorfleet_profile(sender, instance, created, **kwargs):
        """Create the UserProfile when a new User is saved"""
        if created:
            profile = MotorfleetProfile()
            profile.user = instance
            profile.save()

    post_save.connect(create_motorfleet_profile, sender=User)


class Policy(models.Model):
    holder = models.ForeignKey(User, related_name='policy_holder', verbose_name='Policy Holder')
    renewal_date = models.DateField(verbose_name='Renewal Date', default=datetime.date.today())
    number = models.CharField(max_length=30, verbose_name='Policy Number')
    is_onrisk = models.BooleanField(default=False)

    def __unicode__(self):
        return self.number

class Claim(models.Model):
    claimant = models.ForeignKey(User, related_name='claimant', verbose_name='Driver')
    TYPES_CHOICES = (
		(31, u'Theft Or Attempted Theft Of Car - Claim Made'),
		(32, u'Theft Or Attempted Theft From Car - Claim Made'),
		(33, u'Malicious Damage/Vandalism - Claim Made'),
		(34, u'Fire/Flood/Water Damage - Claim Made'),
		(35, u'You Hit Third Party Vehicle/Object - Claim Made'),
		(36, u'You Hit Third Party Person - Claim Made/Pending'),
		(37, u'Accident - Partial Blame - Claim Made'),
		(38, u'Third Party Vehicle/Object Hit You - Recovery O/S'),
		(39, u'Unknown Third Party Hit You - Claim Made'),
		(40, u'Unknown Accident - Historical - Claim Made'),
		(51, u'Theft Or Attempted Theft Of Car - No Claim Made'),
		(52, u'Theft Or Attempted Theft From Car - No Claim Made'),
		(53, u'Malicious Damage/Vandalism - No Claim Made'),
		(54, u'Fire/Flood/Water Damage - No Claim Made'),
		(55, u'Windscreen/Glass Damage'),
		(56, u'You Hit Third Party Vehicle/Object - No Claim Made'),
		(57, u'You Hit Third Party Person - No Claim Made'),
		(58, u'Accident - Partial Blame - No Claim Made'),
		(59, u'Third Party Vehicle/Object Hit You - Recovery Made'),
		(60, u'Unknown Third Party Hit You - No Claim Made'),
		(61, u'Unknown Accident - Historical - No Claim Made')
		)
    type = models.DecimalField(max_digits=2, decimal_places=0, verbose_name='Claim type', choices = TYPES_CHOICES, blank=True, null=True)
    date = models.DateField(verbose_name='Date of claim', default=datetime.date.today())

    def __unicode__(self):
        return self.date


class Conviction(models.Model):
    convicted = models.ForeignKey(User, related_name='convicted', verbose_name='Convicted driver')
    TYPES_CHOICES = (
		('AC10', u'AC10 Failing To Stop And/Or Give Details After Accident'),
		('AC12', u'AC12 Aiding, Abetting, Counselling Or Procuring Ac10'),
		('AC14', u'AC14 Causing Or Permitting Ac10'),
		('AC16', u'AC16 Inciting Ac10'),
		('AC20', u'AC20 Failing To Report An Accident Within 24 Hours'),
		('AC22', u'AC22 Aiding, Abetting, Counselling Or Procuring Ac20'),
		('AC24', u'AC24 Causing Or Permitting Ac20'),
		('AC26', u'AC26 Inciting Ac20'),
		('AC30', u'AC30 Undefined Accident Offence'),
		('AC32', u'AC32 Aiding, Abetting, Counselling Or Procuring Ac30'),
		('AC34', u'AC34 Causing Or Permitting Ac30'),
		('AC36', u'AC36 Inciting Ac30'),
		('BA10', u'BA10 Driving While Disqualified'),
		('BA12', u'BA12 Aiding, Abetting, Counselling Or Procuring Ba10'),
		('BA14', u'BA14 Causing Or Permitting Ba10'),
		('BA16', u'BA16 Inciting Ba10'),
		('BA20', u'BA20 Driving While Disqualified By Reason Of Age'),
		('BA22', u'BA22 Aiding, Abetting, Counselling Or Procuring Ba20'),
		('BA24', u'BA24 Causing Or Permitting Ba20'),
		('BA26', u'BA26 Inciting Ba20'),
		('BA30', u'BA30 To Attempt To Drive While Disqualified'),
		('BA32', u'BA32 Aiding, Abetting, Counselling Or Procuring Ba30'),
		('BA34', u'BA34 Causing Or Permitting Ba30'),
		('BA36', u'BA36 Inciting Ba30'),
		('CD10', u'CD10 Driving Without Due Care And Attention'),
		('CD12', u'CD12 Aiding, Abetting, Counselling Or Procuring Cd10'),
		('CD14', u'CD14 Causing Or Permitting Cd10'),
		('CD16', u'CD16 Inciting Cd10'),
		('CD20', u'CD20 Driving Without Reasonable Consideration'),
		('CD22', u'CD22 Aiding, Abetting, Counselling Or Procuring Cd20'),
		('CD24', u'CD24 Causing Or Permitting Cd20'),
		('CD26', u'CD26 Inciting Cd20'),
		('CD30', u'CD30 Driving Without Due Care/Att. Or Consideration'),
		('CD32', u'CD32 Aiding, Abetting, Counselling Or Procuring Cd30'),
		('CD34', u'CD34 Causing Or Permitting Cd30'),
		('CD36', u'CD36 Inciting Cd30'),
		('CD40', u'CD40 Causing Death Through Careless Driving When Drunk'),
		('CD42', u'CD42 Aiding, Abetting, Counselling Or Procuring Cd40'),
		('CD44', u'CD44 Causing Or Permitting Cd40'),
		('CD46', u'CD46 Inciting Cd40'),
		('CD50', u'CD50 Causing Death By Careless Driving Through Drugs'),
		('CD52', u'CD52 Aiding, Abetting, Counselling Or Procuring Cd50'),
		('CD54', u'CD54 Causing Or Permitting Cd50'),
		('CD56', u'CD56 Inciting Cd50'),
		('CD60', u'CD60 Causing Death By Careless Driving Over Drink Limit'),
		('CD62', u'CD62 Aiding, Abetting, Counselling Or Procuring Cd60'),
		('CD64', u'CD64 Causing Or Permitting Cd60'),
		('CD66', u'CD66 Inciting Cd60'),
		('CD70', u'CD70 Causing Death By Careless Driving And No Specimen'),
		('CD71', u'CD71 Cause Death By Careless Driving And No Drugs Test'),
		('CD72', u'CD72 Aiding, Abetting, Counselling Or Procuring Cd70'),
		('CD74', u'CD74 Causing Or Permitting Cd70'),
		('CD76', u'CD76 Inciting Cd70'),
		('CD80', u'CD80 Causing Death By Careless/Inconsiderate Driving'),
		('CD82', u'CD82 Aiding, Abetting, Couselling Or Procuring Cd80'),
		('CD84', u'CD84 Causing Or Permitting Cd80'),
		('CD86', u'CD86 Inciting Cd80'),
		('CD90', u'CD90 Causing Death By Driving Unlicensed/Disq/Uninsured'),
		('CD92', u'CD92 Aiding, Abetting, Couselling Or Procuring Cd90'),
		('CD94', u'CD94 Causing Or Permitting Cd90'),
		('CD96', u'CD96 Inciting Cd90'),
		('CU10', u'CU10 Using A Vehicle With Defective Brakes'),
		('CU12', u'CU12 Aiding, Abetting, Couselling Or Procuring Cu10'),
		('CU14', u'CU14 Causing Or Permitting Cu10'),
		('CU16', u'CU16 Inciting Cu10'),
		('CU20', u'CU20 Dangerous Cond. Of Veh.(Ex. Brakes/Steering/Tyres)'),
		('CU22', u'CU22 Aiding, Abetting, Couselling Or Procuring Cu20'),
		('CU24', u'CU24 Causing Or Permitting Cu20'),
		('CU26', u'CU26 Inciting Cu20'),
		('CU30', u'CU30 Using A Vehicle With Defective Tyres'),
		('CU32', u'CU32 Aiding, Abetting, Counselling Or Procuring Cu30'),
		('CU34', u'CU34 Causing Or Permitting Cu30'),
		('CU36', u'CU36 Inciting Cu30'),
		('CU40', u'CU40 Using A Vehicle With Defective Steering'),
		('CU42', u'CU42 Aiding, Abetting, Counselling Or Procuring Cu40'),
		('CU44', u'CU44 Causing Or Permitting Cu40'),
		('CU46', u'CU46 Inciting Cu40'),
		('CU50', u'CU50 Causing Danger By Reason Of Load Or Passengers'),
		('CU52', u'CU52 Aiding, Abetting, Counselling Or Procuring Cu50'),
		('CU54', u'CU54 Causing Or Permitting Cu50'),
		('CU56', u'CU56 Inciting Cu50'),
		('CU60', u'CU60 Fail To Comply With Construct. And Use Regulations'),
		('CU62', u'CU62 Aiding, Abetting, Counselling Or Procuring Cu60'),
		('CU64', u'CU64 Causing Or Permitting Cu60'),
		('CU66', u'CU66 Inciting Cu60'),
		('CU80', u'CU80 Driving Whilst Using A Hand-Held Mobile Phone'),
		('CU82', u'CU82 Aiding, Abetting, Counselling Or Procuring Cu80'),
		('CU84', u'CU84 Causing Or Permitting Cu80'),
		('CU86', u'CU86 Inciting Cu80'),
		('DD10', u'DD10 Driving In A Dangerous Manner'),
		('DD12', u'DD12 Aiding, Abetting, Counselling Or Procuring Dd10'),
		('DD14', u'DD14 Causing Or Permitting Dd10'),
		('DD16', u'DD16 Inciting Dd10'),
		('DD20', u'DD20 Driving At A Dangerous Speed'),
		('DD22', u'DD22 Aiding, Abetting, Counselling Or Procuring Dd20'),
		('DD24', u'DD24 Causing Or Permitting Dd20'),
		('DD26', u'DD26 Inciting Dd20'),
		('DD30', u'DD30 Reckless Driving'),
		('DD32', u'DD32 Aiding, Abetting, Counselling Or Procuring Dd30'),
		('DD34', u'DD34 Causing Or Permitting Dd30'),
		('DD36', u'DD36 Inciting Dd30'),
		('DD40', u'DD40 Driving In A Dangerous Manner/Speed/Recklessly'),
		('DD42', u'DD42 Aiding, Abetting, Counseling Or Procuring Dd40'),
		('DD44', u'DD44 Causing Or Permitting Dd40'),
		('DD46', u'DD46 Inciting Dd40'),
		('DD50', u'DD50 Causing Death By Dangerous Driving'),
		('DD52', u'DD52 Aiding, Abetting, Counselling Or Procuring Dd50'),
		('DD54', u'DD54 Causing Or Permitting Dd50'),
		('DD56', u'DD56 Inciting Dd50'),
		('DD60', u'DD60 Culpable Homicide While Driving A Vehicle'),
		('DD62', u'DD62 Aiding, Abetting, Counselling Or Procuring Dd60'),
		('DD64', u'DD64 Causing Or Permitting Dd60'),
		('DD66', u'DD66 Inciting Dd60'),
		('DD70', u'DD70 Causing Death By Reckless Driving'),
		('DD72', u'DD72 Aiding, Abetting, Counselling Or Procuring Dd70'),
		('DD74', u'DD74 Causing Or Permitting Dd70'),
		('DD76', u'DD76 Inciting Dd70'),
		('DD80', u'DD80 Causing Death By Dangerous Driving'),
		('DD82', u'DD82 Aiding, Abetting, Counselling Or Procuring Dd80'),
		('DD84', u'DD84 Causing Or Permitting Dd80'),
		('DD86', u'DD86 Inciting Dd80'),
		('DD90', u'DD90 Furious Driving'),
		('DD92', u'DD92 Aiding And Abetting - Relating To Dd90'),
		('DD94', u'DD94 Causing Or Permitting - Relating To Dd90'),
		('DD96', u'DD96 Inciting - Relating To Dd90'),
		('DR10', u'DR10 To Attempt Or Drive With Blood Alcohol Above Limit'),
		('DR12', u'DR12 Aiding, Abetting, Counselling Or Procuring Dr10'),
		('DR14', u'DR14 Causing Or Permitting Dr10'),
		('DR16', u'DR16 Inciting Dr10'),
		('DR20', u'DR20 To Attempt Or Drive While Unfit Through Drink/Drug'),
		('DR22', u'DR22 Aiding, Abetting, Counselling Or Procuring Dr20'),
		('DR24', u'DR24 Causing Or Permitting Dr20'),
		('DR26', u'DR26 Inciting Dr20'),
		('DR30', u'DR30 To Attempt Or Drive Then Refuse Blood/Urine Test'),
		('DR31', u'DR31 To Attempt Or Drive Then Refuse A Drugs Test'),
		('DR32', u'DR32 Aiding, Abetting, Counselling Or Procuring Dr30'),
		('DR34', u'DR34 Causing Or Permitting Dr30'),
		('DR36', u'DR36 Inciting Dr30'),
		('DR40', u'DR40 In Charge Of Veh. With Blood Alcohol Above Limit'),
		('DR42', u'DR42 Aiding, Abetting, Counselling Or Procuring Dr40'),
		('DR44', u'DR44 Causing Or Permitting Dr40'),
		('DR46', u'DR46 Inciting Dr40'),
		('DR50', u'DR50 In Charge Of Veh. While Unfit Through Drink/Drugs'),
		('DR52', u'DR52 Aiding, Abetting, Counselling Or Procuring Dr50'),
		('DR54', u'DR54 Causing Or Permitting Dr50'),
		('DR56', u'DR56 Inciting Dr50'),
		('DR60', u'DR60 In Charge Of Veh. Then Refuse Blood/Urine Test'),
		('DR61', u'DR61 In Charge Of Veh. Then Refuse A Drugs Test'),
		('DR62', u'DR62 Aiding, Abetting, Counselling Or Procuring Dr60'),
		('DR64', u'DR64 Causing Or Permitting Dr60'),
		('DR66', u'DR66 Inciting Dr60'),
		('DR70', u'DR70 Failing To Provide Specimen For Breath Test'),
		('DR72', u'DR72 Aiding, Abetting, Counselling Or Procuring Dr70'),
		('DR74', u'DR74 Causing Or Permitting Dr70'),
		('DR76', u'DR76 Inciting Dr70'),
		('DR80', u'DR80 Driving Or Attempting To When Unfit Through Drugs'),
		('DR82', u'DR82 Aiding, Abetting, Counselling Or Procuring Dr80'),
		('DR84', u'DR84 Causing Or Permitting Dr80'),
		('DR86', u'DR86 Inciting Dr80'),
		('DR90', u'DR90 In Charge Of A Vehicle When Unfit Through Drugs'),
		('DR92', u'DR92 Aiding, Abetting, Counselling Or Procuring Dr90'),
		('DR94', u'DR94 Causing Or Permitting Dr90'),
		('DR96', u'DR96 Inciting Dr90'),
		('IN10', u'IN10 Using A Veh. Uninsured Against Third Party Risks'),
		('IN12', u'IN12 Aiding, Abetting, Counselling Or Procuring In10'),
		('IN14', u'IN14 Causing Or Permitting In10'),
		('IN16', u'IN16 Inciting In1o'),
		('LC10', u'LC10 Driving Without A Licence'),
		('LC12', u'LC12 Aiding, Abetting, Counselling Or Procuring Lc10'),
		('LC14', u'LC14 Causing Or Permitting Lc10'),
		('LC16', u'LC16 Inciting Lc10'),
		('LC20', u'LC20 Driving Otherwise Than In Accordance With A Lic'),
		('LC22', u'LC22 Aiding, Abetting, Counselling Or Procuring Lc20'),
		('LC24', u'LC24 Causing Or Permitting Lc20'),
		('LC26', u'LC26 Inciting Lc20'),
		('LC30', u'LC30 False Health Declaration When Applying For Licence'),
		('LC32', u'LC32 Aiding, Abetting, Counselling Or Procuring Lc30'),
		('LC34', u'LC34 Causing Or Permitting Lc30'),
		('LC36', u'LC36 Inciting Lc30'),
		('LC40', u'LC40 Driving A Veh Having Failed To Notify A Disibility'),
		('LC42', u'LC42 Aiding, Abetting, Counselling Or Procuring Lc40'),
		('LC44', u'LC44 Causing Or Permitting Lc40'),
		('LC46', u'LC46 Inciting Lc40'),
		('LC50', u'LC50 Driving After Licence Has Been Revoked For Health'),
		('LC52', u'LC52 Aiding, Abetting, Counselling Or Procuring Lc50'),
		('LC54', u'LC54 Causing Or Permitting Lc50'),
		('LC56', u'LC56 Inciting Lc50'),
		('MR09', u'MR09 Dangerous/Reckless Driving Roi'),
		('MR19', u'MR19 Failure To Stop/Give Details After An Accident Roi'),
		('MR29', u'MR29 Drive/Attempt To Drive + Fail To Give Specimen Roi'),
		('MR39', u'MR39 Speeding On A Public Road Or Motorway Roi'),
		('MR49', u'MR49 Driving Whilst Disqualified Roi'),
		('MR59', u'MR59 Miscellaneous No Other Code Roi'),
		('MS10', u'MS10 Leaving A Veh. In A Dangerous Position'),
		('MS12', u'MS12 Aiding, Abetting, Counselling Or Procuring Ms10'),
		('MS14', u'MS14 Causing Or Permitting Ms10'),
		('MS16', u'MS16 Inciting Ms10'),
		('MS20', u'MS20 Unlawful Pillion Riding'),
		('MS22', u'MS22 Aiding, Abetting, Counselling Or Procuring Ms20'),
		('MS24', u'MS24 Causing Or Permitting'),
		('MS26', u'MS26 Inciting Ms20'),
		('MS30', u'MS30 Playstreet Offences'),
		('MS32', u'MS32 Aiding, Abetting, Counselling Or Procuring Ms30'),
		('MS34', u'MS34 Causing Or Permitting Ms30'),
		('MS36', u'MS36 Inciting Ms30'),
		('MS40', u'MS40 Drive With Uncorrected Eyesight Or Refuse Test'),
		('MS42', u'MS42 Aiding, Abetting, Counselling Or Procuring Ms40'),
		('MS44', u'MS44 Causing Or Permitting Ms40'),
		('MS46', u'MS46 Inciting Ms40'),
		('MS50', u'MS50 Motor Racing On The Highway'),
		('MS52', u'MS52 Aiding, Abetting, Counselling Or Procuring Ms50'),
		('MS54', u'MS54 Causing Or Permitting Ms50'),
		('MS56', u'MS56 Inciting Ms50'),
		('MS60', u'MS60 Offences Not Covered By Other Codes'),
		('MS62', u'MS62 Aiding, Abetting, Counselling Or Procuring Ms60'),
		('MS64', u'MS64 Causing Or Permitting Ms60'),
		('MS66', u'MS66 Inciting Ms60'),
		('MS70', u'MS70 Driving With Uncorrected Defective Eyesight'),
		('MS72', u'MS72 Aiding, Abetting, Counselling Or Procuring Ms70'),
		('MS74', u'MS74 Causing Or Permitting Ms70'),
		('MS76', u'MS76 Inciting Ms70'),
		('MS80', u'MS80 Refusing To Submit To An Eyesight Test'),
		('MS82', u'MS82 Aiding, Abetting, Counselling Or Procuring Ms80'),
		('MS84', u'MS84 Causing Or Permitting Ms80'),
		('MS86', u'MS86 Inciting Ms80'),
		('MS90', u'MS90 Failure To Give Info As To Identity Of Driver Etc'),
		('MS92', u'MS92 Aiding, Abetting, Counselling Or Procuring Ms90'),
		('MS94', u'MS94 Causing Or Permitting Ms90'),
		('MS96', u'MS96 Inciting Ms90'),
		('MW10', u'MW10 Disobey Special Road Regulations (Ex. Speed Limit)'),
		('MW12', u'MW12 Aiding, Abetting, Counselling Or Procuring Mw10'),
		('MW14', u'MW14 Causing Or Permitting Mw10'),
		('MW16', u'MW16 Inciting Mw10'),
		('NE96', u'NE96 Disqualification Under Child Support Act 2000'),
		('NE97', u'NE97 Interim Disqualification No Sentence Within 6month'),
		('NE98', u'NE98 Misc Disqualification - Anti Socoal Behaviour'),
		('NE99', u'NE99 Non Endorsable Offence-Can Be Banned (Ie Crim Ac)'),
		('NI09', u'NI09 Gb Driver Disqualified In Northern Ireland'),
		('NR09', u'NR09 Gb Driver Revoked Under New Drivers Act In Ni'),
		('PC10', u'PC10 Undefined Contravention Of Pedestrian Crossing'),
		('PC12', u'PC12 Aiding, Abetting, Counselling Or Procuring Pc10'),
		('PC14', u'PC14 Causing Or Permitting Pc10'),
		('PC16', u'PC16 Inciting Pc10'),
		('PC20', u'PC20 Contravention Of Ped/Crossing With Moving Vehicle'),
		('PC22', u'PC22 Aiding, Abetting, Counselling Or Procuring Pc20'),
		('PC24', u'PC24 Causing Or Permitting Pc20'),
		('PC26', u'PC26 Inciting Pc20'),
		('PC30', u'PC30 Contravention Of Ped/Crossing With Stationary Veh.'),
		('PC32', u'PC32 Aiding, Abetting, Counselling Or Procuring Pc30'),
		('PC34', u'PC34 Causing Or Permitting Pc30'),
		('PC36', u'PC36 Inciting Pc30'),
		('PL10', u'PL10 Driving Without &quot;L&quot; Plates'),
		('PL12', u'PL12 Aiding, Abetting, Counselling Or Procuring Pl10'),
		('PL14', u'PL14 Causing Or Permitting Pl10'),
		('PL16', u'PL16 Inciting Pl10'),
		('PL20', u'PL20 Not Accompanied By A Qualified Driver'),
		('PL22', u'PL22 Aiding, Abetting, Counselling Or Procuring Pl20'),
		('PL24', u'PL24 Causing Or Permitting Pl20'),
		('PL26', u'PL26 Inciting Pl20'),
		('PL30', u'PL30 Carrying A Person Not Qualified'),
		('PL32', u'PL32 Aiding, Abetting, Counselling Or Procuring Pl30'),
		('PL34', u'PL34 Causing Or Permitting Pl30'),
		('PL36', u'PL36 Inciting Pl30'),
		('PL40', u'PL40 Drawing An Unauthorised Trailer'),
		('PL42', u'PL42 Aiding, Abetting, Counselling Or Procuring Pl40'),
		('PL44', u'PL44 Causing Or Permitting Pl40'),
		('PL46', u'PL46 Inciting Pl40'),
		('PL50', u'PL50 Failure To Comply With Conditions Of A Prov/Lic'),
		('PL52', u'PL52 Aiding, Abetting, Counselling Or Procuring Pl50'),
		('PL54', u'PL54 Causing Or Permitting Pl50'),
		('PL56', u'PL56 Inciting Pl50'),
		('QI09', u'QI09 Gb Driver Disqualified In Isle Of Man'),
		('SE19', u'SE19 Disqualification Under Totting Up Procedure(Se19)'),
		('SE35', u'SE35 Disqualification Under Totting Up Procedure(Se35)'),
		('SP10', u'SP10 Exceeding Goods Vehicle Speed Limit'),
		('SP12', u'SP12 Aiding, Abetting, Counselling Or Procuring Sp10'),
		('SP14', u'SP14 Causing Or Permitting Sp10'),
		('SP16', u'SP16 Inciting Sp10'),
		('SP20', u'SP20 Exceed Speed For Type Of Veh (Ex Goods/Passenger)'),
		('SP22', u'SP22 Aiding, Abetting, Counselling Or Procuring Sp20'),
		('SP24', u'SP24 Causing Or Permitting Sp20'),
		('SP26', u'SP26 Inciting Sp20'),
		('SP30', u'SP30 Exceeding Speed Limit On A Public Road'),
		('SP32', u'SP32 Aiding, Abetting, Counselling Or Procuring Sp30'),
		('SP34', u'SP34 Causing Or Permitting Sp30'),
		('SP36', u'SP36 Inciting Sp30'),
		('SP40', u'SP40 Exceeding Passenger Vehicle Speed Limit'),
		('SP42', u'SP42 Aiding, Abetting, Counselling Or Procuring Sp40'),
		('SP44', u'SP44 Causing Or Permitting Sp40'),
		('SP46', u'SP46 Inciting Sp40'),
		('SP50', u'SP50 Exceeding Speed Limit On A Motorway'),
		('SP52', u'SP52 Aiding, Abetting, Counselling Or Procuring Sp50'),
		('SP54', u'SP54 Causing Or Permitting Sp50'),
		('SP56', u'SP56 Inciting Sp50'),
		('SP60', u'SP60 Undefined Speed Limit Offence'),
		('SP62', u'SP62 Aiding, Abetting, Couselling Or Procuring Sp60'),
		('SP64', u'SP64 Causing Or Permitting Sp60'),
		('SP66', u'SP66 Inciting Sp60'),
		('TS10', u'TS10 Failing To Comply With Traffic Light Signals'),
		('TS12', u'TS12 Aiding, Abetting, Couselling Or Procuring Ts10'),
		('TS14', u'TS14 Causing Or Permitting Ts10'),
		('TS16', u'TS16 Inciting Ts10'),
		('TS20', u'TS20 Failing To Comply With Double White Lines'),
		('TS22', u'TS22 Aiding, Abetting, Counselling Or Procuring Ts20'),
		('TS24', u'TS24 Causing Or Permitting Ts20'),
		('TS26', u'TS26 Inciting Ts20'),
		('TS30', u'TS30 Failing To Comply With A &quot;Stop&quot; Sign'),
		('TS32', u'TS32 Aiding, Abetting, Couselling Or Procuring Ts30'),
		('TS34', u'TS34 Causing Or Permitting Ts30'),
		('TS36', u'TS36 Inciting Ts30'),
		('TS40', u'TS40 Failing To Comply With Directions Of Traff/Police'),
		('TS42', u'TS42 Aiding, Abetting, Counselling Or Procuring Ts40'),
		('TS44', u'TS44 Causing Or Permitting Ts40'),
		('TS46', u'TS46 Inciting Ts40'),
		('TS50', u'TS50 Fail To Traff/Sign Ex Stop,Traff/Light,Dble W/Line'),
		('TS52', u'TS52 Aiding, Abetting, Counselling Or Procuring Ts50'),
		('TS54', u'TS54 Causing Or Permitting Ts50'),
		('TS56', u'TS56 Inciting Ts50'),
		('TS60', u'TS60 Failing To Comply With School Crossing Patrol Sign'),
		('TS62', u'TS62 Aiding, Abetting, Counselling Or Procuring Ts60'),
		('TS64', u'TS64 Causing Or Permitting Ts60'),
		('TS66', u'TS66 Inciting Ts60'),
		('TS70', u'TS70 Failure To Comply With Traffic Direction Or Sign'),
		('TS72', u'TS72 Aiding, Abetting, Counselling Or Procuring Ts70'),
		('TS74', u'TS74 Causing Or Permitting Ts70'),
		('TS76', u'TS76 Inciting Ts70'),
		('TT99', u'TT99 Disqualification Under The &quot;Totting Up&quot; Procedure'),
		('UT10', u'UT10 Take/Drive Away Veh Without Consent Or Attempt'),
		('UT12', u'UT12 Aiding, Abetting, Counselling Or Procuring Ut10'),
		('UT14', u'UT14 Causing Or Permitting Ut10'),
		('UT16', u'UT16 Inciting Ut10'),
		('UT20', u'UT20 Stealing Or Attempting To Steal A Vehicle'),
		('UT22', u'UT22 Aiding, Abetting, Counselling Or Procuring Ut20'),
		('UT24', u'UT24 Causing Or Permitting Ut20'),
		('UT26', u'UT26 Inciting Ut20'),
		('UT30', u'UT30 Going Equipped For Stealing Or Taking A Vehicle'),
		('UT32', u'UT32 Aiding, Abetting, Counselling Or Procuring Ut30'),
		('UT34', u'UT34 Causing Or Permitting Ut30'),
		('UT36', u'UT36 Inciting Ut30'),
		('UT40', u'UT40 Take/Drive (Attempt);Carried In;Veh W/Out Consent'),
		('UT42', u'UT42 Aiding, Abetting, Counselling Or Procuring Ut40'),
		('UT44', u'UT44 Causing Or Permitting Ut40'),
		('UT46', u'UT46 Inciting Ut40'),
		('UT50', u'UT50 Aggravated Taking Of A Vehicle'),
		('UT52', u'UT52 Aiding, Abetting, Counselling Or Procuring Ut50'),
		('UT54', u'UT54 Causing Or Permitting Ut50'),
		('UT56', u'UT56 Inciting Ut50'),
		('XX99', u'XX99 Disqualification Under The &quot;Totting Up&quot; Procedure')
		)
    type = models.CharField(max_length=4, choices=TYPES_CHOICES, verbose_name='Conviction type')
    date = models.DateField(verbose_name='Date of clconviction', default=datetime.date.today())

    def __unicode__(self):
        return self.date


class Vehicle(models.Model):
    owner = models.ForeignKey(User, related_name='owner', verbose_name='Owner')
    additionaldrivers = models.ManyToManyField(User, related_name='additionaldriver')
    reg = models.CharField(max_length=10, verbose_name='Registration')
    MILAGES = (
        (5000, u'up to 5000'),
        (10000, u'up to 10000'),
        (20000, u'up to 20000'),
        (30000, u'up to 30000'),
        (40000, u'up to 40000'),
        (50000, u'up to 50000')
    )
    annual_milage = models.DecimalField(max_digits=6, decimal_places=0, choices=MILAGES, verbose_name='Annual milage')
    value = models.DecimalField(max_digits=6, decimal_places=0, verbose_name='Estimated value')
    VEHICLE_MAKES = (
		('AC', u'AC'),
		('ACURA', u'ACURA'),
		('ADLY', u'ADLY'),
		('AEON', u'AEON'),
		('AIXAM', u'AIXAM'),
		('AJP', u'AJP'),
		('AJS', u'AJS'),
		('AJW', u'AJW'),
		('ALFA ROMEO', u'ALFA ROMEO'),
		('AMC', u'AMC'),
		('ANT', u'ANT'),
		('APRILIA', u'APRILIA'),
		('ARO', u'ARO'),
		('ASIA', u'ASIA'),
		('ASTON MARTIN', u'ASTON MARTIN'),
		('AUDI', u'AUDI'),
		('AUSTIN', u'AUSTIN'),
		('BAOTIAN', u'BAOTIAN'),
		('BEDFORD', u'BEDFORD'),
		('BENELLI', u'BENELLI'),
		('BENTLEY', u'BENTLEY'),
		('BETA', u'BETA'),
		('BITTER', u'BITTER'),
		('BL', u'BL'),
		('BMW', u'BMW'),
		('BOND', u'BOND'),
		('BRISTOL', u'BRISTOL'),
		('BSA', u'BSA'),
		('BUELL', u'BUELL'),
		('BUICK', u'BUICK'),
		('CADILLAC', u'CADILLAC'),
		('CAGIVA', u'CAGIVA'),
		('CATERHAM', u'CATERHAM'),
		('CCM', u'CCM'),
		('CHEVROLET', u'CHEVROLET'),
		('CHRYSLER', u'CHRYSLER'),
		('CITROEN', u'CITROEN'),
		('CLUB CAR', u'CLUB CAR'),
		('COLT', u'COLT'),
		('COMMER', u'COMMER'),
		('CPI', u'CPI'),
		('DACIA', u'DACIA'),
		('DAELIM', u'DAELIM'),
		('DAEWOO', u'DAEWOO'),
		('DAF', u'DAF'),
		('DAIHATSU', u'DAIHATSU'),
		('DAIMLER', u'DAIMLER'),
		('DALLAS', u'DALLAS'),
		('DATSUN', u'DATSUN'),
		('DE TOMASO', u'DE TOMASO'),
		('DELOREAN', u'DELOREAN'),
		('DERBI', u'DERBI'),
		('DFSK', u'DFSK'),
		('DODGE', u'DODGE'),
		('DUCATI', u'DUCATI'),
		('EASY RIDER', u'EASY RIDER'),
		('EBRO', u'EBRO'),
		('FBS', u'FBS'),
		('FERRARI', u'FERRARI'),
		('FIAT', u'FIAT'),
		('FORD', u'FORD'),
		('FORD (AUS)', u'FORD (AUS)'),
		('FORD (USA)', u'FORD (USA)'),
		('FREIGHT ROVER', u'FREIGHT ROVER'),
		('FSO', u'FSO'),
		('GEM', u'GEM'),
		('GILBERN', u'GILBERN'),
		('GILERA', u'GILERA'),
		('GINETTA', u'GINETTA'),
		('GREEVES', u'GREEVES'),
		('HARLEY DAVIDSON', u'HARLEY DAVIDSON'),
		('HARTFORD', u'HARTFORD'),
		('HERO', u'HERO'),
		('HESKETH', u'HESKETH'),
		('HILLMAN', u'HILLMAN'),
		('HINDUSTAN', u'HINDUSTAN'),
		('HOLDEN', u'HOLDEN'),
		('HONDA', u'HONDA'),
		('HUMMER', u'HUMMER'),
		('HUSABERG', u'HUSABERG'),
		('HUSQVARNA', u'HUSQVARNA'),
		('HYOSUNG', u'HYOSUNG'),
		('HYUNDAI', u'HYUNDAI'),
		('INDIAN', u'INDIAN'),
		('INFINITI', u'INFINITI'),
		('ISUZU', u'ISUZU'),
		('IVECO', u'IVECO'),
		('JAGUAR', u'JAGUAR'),
		('JAWA', u'JAWA'),
		('JEEP', u'JEEP'),
		('JENSEN', u'JENSEN'),
		('JIALING', u'JIALING'),
		('JINLUN', u'JINLUN'),
		('KAISAR', u'KAISAR'),
		('KAWASAKI', u'KAWASAKI'),
		('KEEWAY', u'KEEWAY'),
		('KENOS', u'KENOS'),
		('KHALEEJ', u'KHALEEJ'),
		('KIA', u'KIA'),
		('KTM', u'KTM'),
		('KYMCO', u'KYMCO'),
		('LADA', u'LADA'),
		('LAMBORGHINI', u'LAMBORGHINI'),
		('LAMBRETTA', u'LAMBRETTA'),
		('LANCIA', u'LANCIA'),
		('LAND ROVER', u'LAND ROVER'),
		('LAVERDA', u'LAVERDA'),
		('LDV', u'LDV'),
		('LEXUS', u'LEXUS'),
		('LEXUS (USA)', u'LEXUS (USA)'),
		('LEYLAND-DAF', u'LEYLAND-DAF'),
		('LIFAN', u'LIFAN'),
		('LIGIER', u'LIGIER'),
		('LINCOLN', u'LINCOLN'),
		('LML', u'LML'),
		('LONSDALE', u'LONSDALE'),
		('LOTUS', u'LOTUS'),
		('MAHINDRA', u'MAHINDRA'),
		('MALAGUTI', u'MALAGUTI'),
		('MARANELLO', u'MARANELLO'),
		('MARCOS', u'MARCOS'),
		('MARLIN', u'MARLIN'),
		('MASERATI', u'MASERATI'),
		('MATCHLESS', u'MATCHLESS'),
		('MAYBACH', u'MAYBACH'),
		('MAZDA', u'MAZDA'),
		('MCC', u'MCC'),
		('MERCEDES', u'MERCEDES'),
		('MERCURY', u'MERCURY'),
		('MG', u'MG'),
		('MG-MOTOR UK', u'MG-MOTOR UK'),
		('MICROCAR', u'MICROCAR'),
		('MINI', u'MINI'),
		('MITSUBISHI', u'MITSUBISHI'),
		('MORGAN', u'MORGAN'),
		('MORRIS', u'MORRIS'),
		('MOSLER', u'MOSLER'),
		('MOTO GUZZI', u'MOTO GUZZI'),
		('MOTO MORINI', u'MOTO MORINI'),
		('MYCAR', u'MYCAR'),
		('MZ', u'MZ'),
		('NAC MG', u'NAC MG'),
		('NISSAN', u'NISSAN'),
		('NOBLE', u'NOBLE'),
		('NORTON', u'NORTON'),
		('NSU', u'NSU'),
		('OKA', u'OKA'),
		('OPEL', u'OPEL'),
		('PANTHER', u'PANTHER'),
		('PERODUA', u'PERODUA'),
		('PEUGEOT', u'PEUGEOT'),
		('PGO', u'PGO'),
		('PIAGGIO', u'PIAGGIO'),
		('PORSCHE', u'PORSCHE'),
		('PORTARO', u'PORTARO'),
		('PROTON', u'PROTON'),
		('RANGE ROVER', u'RANGE ROVER'),
		('REIJU', u'REIJU'),
		('RELIANT', u'RELIANT'),
		('RENAULT', u'RENAULT'),
		('REVA', u'REVA'),
		('ROLLS ROYCE', u'ROLLS ROYCE'),
		('ROVER', u'ROVER'),
		('ROYAL ENFIELD', u'ROYAL ENFIELD'),
		('SAAB', u'SAAB'),
		('SACHS', u'SACHS'),
		('SAN', u'SAN'),
		('SANTANA', u'SANTANA'),
		('SAO', u'SAO'),
		('SEAT', u'SEAT'),
		('SECMA', u'SECMA'),
		('SHERCO', u'SHERCO'),
		('SIAMOTO', u'SIAMOTO'),
		('SIMCA', u'SIMCA'),
		('SKODA', u'SKODA'),
		('SSANGYONG', u'SSANGYONG'),
		('STEVENS', u'STEVENS'),
		('SUBARU', u'SUBARU'),
		('SUZUKI', u'SUZUKI'),
		('SYM', u'SYM'),
		('TALBOT', u'TALBOT'),
		('TATA', u'TATA'),
		('TD', u'TD'),
		('TESLA', u'TESLA'),
		('TGB', u'TGB'),
		('TOYOTA', u'TOYOTA'),
		('TRIUMPH', u'TRIUMPH'),
		('TVR', u'TVR'),
		('URAL', u'URAL'),
		('VANDEN PLAS', u'VANDEN PLAS'),
		('VAUXHALL', u'VAUXHALL'),
		('VENTURI', u'VENTURI'),
		('VESPA', u'VESPA'),
		('VEXEL', u'VEXEL'),
		('VICTORY', u'VICTORY'),
		('VOLKSWAGEN', u'VOLKSWAGEN'),
		('VOLKSWAGEN (MEXICO)', u'VOLKSWAGEN (MEXICO)'),
		('VOLVO', u'VOLVO'),
		('YAMAHA', u'YAMAHA'),
		('YIBEN', u'YIBEN'),
		('YIYANG', u'YIYANG'),
		('YUEJIN', u'YUEJIN'),
		('YUGO', u'YUGO')
    )
    make = models.CharField(max_length=2, choices=VEHICLE_MAKES, verbose_name='Make')
    model = models.CharField(max_length=30, verbose_name='Model')

    def __unicode__(self):
        return self.make

class Fleet(models.Model):
    group = models.ForeignKey(Group, related_name='motorfleet')
    name = models.CharField(max_length=150)
    desc = models.CharField(max_length=400, blank=True)
    currency = models.CharField(max_length=3, blank=True, default=u'\u0024')
    start_date = models.DateField(default=datetime.date.today())
    host = models.ForeignKey(User, null=True, related_name='motorfleet_host')
    notify_emails = models.BooleanField(default=False)
    is_deleted = models.BooleanField(default=False)





