class ScriptFormUpdate(Form): """Form to update a script.""" required_css_class = 'required' script = ChoiceField( choices=[], label=ugettext_lazy('Script'), widget=forms.Select(attrs={'autofocus': True}), ) version = CharField( max_length=MAX_LENGTH_VERSION, label=ugettext_lazy('New version'), ) file = FileField( label=ugettext_lazy('File'), help_text=ugettext_lazy('The script.'), ) author = CharField( max_length=MAX_LENGTH_AUTHOR, label=ugettext_lazy('Your name or nick'), help_text=ugettext_lazy('Used for git commit.'), ) mail = EmailField( max_length=MAX_LENGTH_MAIL, label=ugettext_lazy('Your e-mail'), help_text=ugettext_lazy('Used for git commit.'), widget=Html5EmailInput(), ) comment = CharField( max_length=1024, label=ugettext_lazy('Comments'), help_text=ugettext_lazy('Changes in this release.'), widget=forms.Textarea(attrs={'rows': '3'}), ) test = TestField( max_length=64, label=ugettext_lazy('Are you a spammer?'), help_text=ugettext_lazy('Enter "no" if you are not a spammer.'), ) def __init__(self, *args, **kwargs): super(ScriptFormUpdate, self).__init__(*args, **kwargs) self.label_suffix = '' self.fields['script'].choices = get_script_choices()
class ThemeFormUpdate(Form): """Form to update a theme.""" required_css_class = 'required' theme = ChoiceField( choices=[], label=ugettext_lazy('Theme'), widget=forms.Select(attrs={'autofocus': True}), ) themefile = FileField( label=ugettext_lazy('File'), help_text=ugettext_lazy('The theme.'), ) author = CharField( max_length=MAX_LENGTH_AUTHOR, label=ugettext_lazy('Your name or nick'), ) mail = EmailField( max_length=MAX_LENGTH_MAIL, label=ugettext_lazy('Your e-mail'), help_text=ugettext_lazy('No spam, never displayed.'), widget=Html5EmailInput(), ) comment = CharField( required=False, max_length=1024, label=ugettext_lazy('Comments'), help_text=ugettext_lazy('Not displayed.'), widget=forms.Textarea(attrs={'rows': '3'}), ) test = TestField( max_length=64, label=ugettext_lazy('Are you a spammer?'), help_text=ugettext_lazy('Enter "no" if you are not a spammer.'), ) def __init__(self, *args, **kwargs): super(ThemeFormUpdate, self).__init__(*args, **kwargs) self.label_suffix = '' self.fields['theme'].choices = get_theme_choices() def clean_themefile(self): """Check if theme file is valid.""" _file = self.cleaned_data['themefile'] if _file.size > 512*1024: raise forms.ValidationError(ugettext('Theme file too big.')) content = _file.read() if isinstance(content, bytes): content = content.decode('utf-8') props = Theme.get_props(content) if 'name' not in props or 'weechat' not in props: raise forms.ValidationError(ugettext('Invalid theme file.')) theme = Theme.objects.get(id=self.cleaned_data['theme']) if not theme: raise forms.ValidationError(ugettext('Internal error.')) if props['name'] != theme.name: raise forms.ValidationError( ugettext('Invalid name: different from theme.')) release_stable = Release.objects.get(version='stable') release_devel = Release.objects.get(version='devel') if props['weechat'] not in (release_stable.description, re.sub('-.*', '', release_devel.description)): raise forms.ValidationError( ugettext('Invalid WeeChat version, too old!')) _file.seek(0) return _file
class ThemeFormAdd(Form): """Form to add a theme.""" required_css_class = 'required' themefile = FileField( label=ugettext_lazy('File'), help_text=ugettext_lazy('The theme.'), widget=forms.FileInput(attrs={'autofocus': True}), ) description = CharField( required=False, max_length=MAX_LENGTH_DESC, label=ugettext_lazy('Description'), ) author = CharField( max_length=MAX_LENGTH_AUTHOR, label=ugettext_lazy('Your name or nick'), help_text=ugettext_lazy('Used for themes page.'), ) mail = EmailField( max_length=MAX_LENGTH_MAIL, label=ugettext_lazy('Your e-mail'), help_text=ugettext_lazy('No spam, never displayed.'), widget=Html5EmailInput(), ) comment = CharField( required=False, max_length=1024, label=ugettext_lazy('Comments'), help_text=ugettext_lazy('Not displayed.'), widget=forms.Textarea(attrs={'rows': '3'}), ) test = TestField( max_length=64, label=ugettext_lazy('Are you a spammer?'), help_text=ugettext_lazy('Enter "no" if you are not a spammer.'), ) def __init__(self, *args, **kwargs): super(ThemeFormAdd, self).__init__(*args, **kwargs) self.label_suffix = '' def clean_themefile(self): """Check if theme file is valid.""" _file = self.cleaned_data['themefile'] if _file.size > 512*1024: raise forms.ValidationError(ugettext('Theme file too big.')) content = _file.read() if isinstance(content, bytes): content = content.decode('utf-8') props = Theme.get_props(content) if 'name' not in props or 'weechat' not in props: raise forms.ValidationError(ugettext('Invalid theme file.')) themes = Theme.objects.filter(name=props['name']) if themes: raise forms.ValidationError(ugettext('This name already exists.')) if not props['name'].endswith('.theme'): raise forms.ValidationError( ugettext('Invalid name inside theme file.')) shortname = props['name'][0:-6] if not re.search('^[A-Za-z0-9_]+$', shortname): raise forms.ValidationError( ugettext('Invalid name inside theme file.')) release_stable = Release.objects.get(version='stable') release_devel = Release.objects.get(version='devel') if props['weechat'] not in (release_stable.description, re.sub('-.*', '', release_devel.description)): raise forms.ValidationError( ugettext('Invalid WeeChat version, too old!')) _file.seek(0) return _file
class ScriptFormAdd(Form): """Form to add a script.""" languages = ( ('python', 'Python (.py)'), ('perl', 'Perl (.pl)'), ('ruby', 'Ruby (.rb)'), ('lua', 'Lua (.lua)'), ('tcl', 'Tcl (.tcl)'), ('guile', 'Scheme (.scm)'), ('javascript', 'Javascript (.js)'), ('php', 'PHP (.php)'), ) required_css_class = 'required' language = ChoiceField( choices=languages, label=pgettext_lazy(u'The programming language.', u'Language'), widget=forms.Select(attrs={'autofocus': True}), ) name = NameField( max_length=MAX_LENGTH_NAME, label=ugettext_lazy('Name'), ) version = CharField( max_length=MAX_LENGTH_VERSION, label=ugettext_lazy('Version'), help_text=ugettext_lazy('The version of script ' '(only digits or dots).'), ) license = CharField( max_length=MAX_LENGTH_LICENSE, label=ugettext_lazy('License'), help_text=ugettext_lazy('The license (for example: GPL3, BSD, etc.).'), ) file = FileField( label=ugettext_lazy('File'), help_text=ugettext_lazy('The script.'), ) description = CharField( max_length=MAX_LENGTH_DESC, label=ugettext_lazy('Description'), ) requirements = CharField( required=False, max_length=MAX_LENGTH_REQUIRE, label=ugettext_lazy('Requirements'), ) min_max = ChoiceField( choices=[], label=ugettext_lazy('Min/max WeeChat version.'), ) author = CharField( max_length=MAX_LENGTH_AUTHOR, label=ugettext_lazy('Your name or nick'), help_text=ugettext_lazy('Used for git commit and scripts page.'), ) mail = EmailField( max_length=MAX_LENGTH_MAIL, label=ugettext_lazy('Your e-mail'), help_text=ugettext_lazy('Used for git commit.'), widget=Html5EmailInput(), ) comment = CharField( required=False, max_length=1024, label=ugettext_lazy('Comments'), help_text=ugettext_lazy('Not displayed.'), widget=forms.Textarea(attrs={'rows': '3'}), ) test = TestField( max_length=64, label=ugettext_lazy('Are you a spammer?'), help_text=ugettext_lazy('Enter "no" if you are not a spammer.'), ) def __init__(self, *args, **kwargs): super(ScriptFormAdd, self).__init__(*args, **kwargs) self.label_suffix = '' self.fields['min_max'].choices = get_min_max_choices() self.fields['name'].help_text = ugettext( 'The short name of script (max {max_chars} chars, ' 'only lower case letters, digits or "_").').format( max_chars=MAX_LENGTH_NAME)