from radar.validation.core import Field, Validation, ListField, ValidationError
from radar.validation.meta import MetaValidationMixin
from radar.validation.validators import not_empty, none_if_blank, optional, email_address, max_length, required, upper, lower
from radar.validation.number_validators import gmc_number


class GroupConsultantValidation(MetaValidationMixin, Validation):
    group = Field([required()])

    def validate_group(self, group):
        if group.type != 'HOSPITAL':
            raise ValidationError('Must be a hospital.')

        return group


class ConsultantValidation(MetaValidationMixin, Validation):
    first_name = Field([not_empty(), upper(), max_length(100)])
    last_name = Field([not_empty(), upper(), max_length(100)])
    email = Field([none_if_blank(), optional(), lower(), email_address()])
    telephone_number = Field([none_if_blank(), optional(), max_length(100)])
    gmc_number = Field([optional(), gmc_number()])
    group_consultants = ListField(GroupConsultantValidation())

@@ -567,16 +567,620 @@
 group%0A%0A%0A
+class GroupConsultantListField(ListField):%0A    def __init__(self, chain=None):%0A        super(GroupConsultantListField, self).__init__(GroupConsultantValidation(), chain=chain)%0A%0A    def validate(self, group_consultants):%0A        print 'hello!'%0A%0A        group_ids = set()%0A%0A        for i, group_consultant in enumerate(group_consultants):%0A            group_id = group_consultant.group.id%0A%0A            if group_id in group_ids:%0A                raise ValidationError(%7Bi: %7B'group': 'Consultant already in group.'%7D%7D)%0A            else:%0A                group_ids.add(group_id)%0A%0A        return group_consultants%0A%0A%0A
 class Co
@@ -1228,24 +1228,24 @@
 alidation):%0A
-
     first_na
@@ -1586,26 +1586,16 @@
 tants = 
-ListField(
 GroupCon
@@ -1601,22 +1601,20 @@
 nsultant
-Validation()
+ListField(
 )%0A

Check consultant groups aren't duplicated