Example #1
0
    def clean(self):
        super(CommonCharacterForm, self).clean()

        # check model and level
        from muddery.worlddata.dao.common_mappers import CHARACTER_MODELS

        try:
            CHARACTER_MODELS.get(key=self.model, level=self.level)
        except Exception, e:
            message = "Can not get the level data."
            levels = CHARACTER_MODELS.filter(key=self.model)
            available = [str(level.level) for level in levels]
            if len(available) == 1:
                message += " Available level: " + available[0]
            elif len(available) > 1:
                message += " Available levels: " + ", ".join(available)
            raise forms.ValidationError({"level": message})
Example #2
0
    def clean(self):
        cleaned_data = super(CharacterForm, self).clean()
        data_model = cleaned_data["model"]
        data_level = cleaned_data["level"]

        # check model and level
        from muddery.worlddata.dao.common_mappers import CHARACTER_MODELS

        try:
            CHARACTER_MODELS.get(key=data_model, level=data_level)
        except Exception, e:
            message = "Can not get the level data."
            levels = CHARACTER_MODELS.filter(key=data_model)
            available = [str(level.level) for level in levels]
            if len(available) == 1:
                message += " Available level: " + available[0]
            elif len(available) > 1:
                message += " Available levels: " + ", ".join(available)
            raise forms.ValidationError({"level": message})