Exemplo n.º 1
0
    def clean(self):
        #TODO(nicoechaniz): this whole form validation could be simplified if we were not using our custom AjaxChoiceField and fields were actually marked as not null in the model definition. The problem is that the standard form validation will check for valid choices, so we should set choices to valid ones for each choicefield at form init time.

        data = self.cleaned_data
        if not data['DELETE']:
            if data['object_id'] == '':
                data['object_id'] = None

            if not data['content_type']:
                raise(ValidationError(_(u'Content type can not be empty')))

            else:
                if not data['region']:
                    raise(ValidationError(_(u'You need to select a region')))
                if data['content_view'] == '' or not data['content_view']:
                    raise(ValidationError(
                        _(u'You need to select a content view')))
                else:
                    view = site.get_view(data['content_type'].model_class(),
                                         data['content_view'])
                    if view.is_instance_view and data['object_id'] is None:
                        raise(ValidationError(
                            _(u'The selected view requires a content object')))
                    elif not view.is_instance_view:
                        # if not an instance it does not need a content object
                        if data['object_id'] is not None:
                            data['object_id'] = None

        return super(RegionViewInlineForm, self).clean()
Exemplo n.º 2
0
    def clean(self):
        data = self.cleaned_data
        data['content_object'] = data.get('content_object')

        if data['custom_url'] and (data.get('content_type')
                                   or data.get('content_object')
                                   or data.get('content_view')):
            raise ValidationError(
                _(u'You can not set a Custom URL for menu entries \
                    with associated content'))

        else:
            if data['content_type']:
                if data['content_view'] == '' or not data['content_view']:
                    raise(ValidationError(
                        _(u'You need to select a content view')))
                else:
                    view = site.get_view(data['content_type'].model_class(),
                                         data['content_view'])
                    if view.is_instance_view and data['content_object'] is None:
                        raise(ValidationError(
                            _(u'The selected view requires a content object')))
                    elif not view.is_instance_view:
                        # if not an instance it does not need a content object
                        if data['content_object'] is not None:
                            data['content_object'] = None

        return super(MenuItemAdminForm, self).clean()
Exemplo n.º 3
0
    def set_initial_view_options(self, obj, model):
        view_name = getattr(obj, self.view_field_name)
        if not view_name:
            return
        view = site.get_view(model, view_name)

        self.fields[self.options_field_name] = MultipleField(form=view.options_form,
                                                             required=False)

        initial_options = self.fields[self.options_field_name].initial
        actual_options = getattr(obj, self.options_field_name)
        self.initial[self.options_field_name] = actual_options or initial_options
Exemplo n.º 4
0
 def get_view(self, values):
     return site.get_view(self.model, values[self.view_field_name])
Exemplo n.º 5
0
 def get_view(self, values):
     return site.get_view(values['content_type'].model_class(),
                           values[self.view_field_name])