Пример #1
0
 def clean(self):
     self.cleaned_data = super(PageVersionForm, self).clean()
     # Check Latest Version is incremented
     latest_version = PageVersion.get_latest_version_id(
         language=self.data['language'], draft=self.data['draft'])
     if latest_version and 'version_id' in self.cleaned_data:
         new_version = self.cleaned_data['version_id']
         if latest_version >= new_version:
             raise forms.ValidationError("Version Id is not increased")
Пример #2
0
    def __init__(self, *args, **kwargs):
        super(PageVersionForm, self).__init__(*args, **kwargs)

        # Set Title as required
        if not ALLOW_BLANK_TITLE:
            self.fields['title'].required = True

        # Get Latest Version Id
        if kwargs.get('initial'):
            draft_page = kwargs.get('initial').get('draft')
            language = kwargs.get('initial').get('language')
            latest_version = PageVersion.get_latest_version_id(
                language=language, draft=draft_page) or VERSION_START_VALUE
            if latest_version:
                self.fields['version_id'].initial = str(latest_version)