File: forms.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (46 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Django forms for configuring Feather Wiki."""

from django import forms
from django.core import validators
from django.utils.translation import gettext_lazy as _


def _validate_not_index_file(name):
    """Validate that the normalized file name is not 'index.html'."""
    if str(name) in ('index.html', 'index'):
        raise forms.ValidationError(
            _('Wiki files cannot be named "index.html".'))


class CreateWikiForm(forms.Form):
    """Form to create a new wiki file."""

    name = forms.CharField(
        label=_('Name of the wiki file, with file extension ".html"'),
        strip=True, validators=[_validate_not_index_file], help_text=_(
            'Wiki title and description can be set from within the wiki. '
            'This file name is independent of the wiki title.'))


class RenameWikiForm(forms.Form):
    """Form to rename a wiki file."""

    new_name = forms.CharField(
        label=_('New name for the wiki file, with file extension ".html"'),
        strip=True, validators=[_validate_not_index_file], help_text=_(
            'Renaming the file has no effect on the title of the wiki.'))


class UploadWikiForm(forms.Form):
    """Form to upload a wiki file."""

    file = forms.FileField(
        label=_('A Feather Wiki file with .html file extension'),
        required=True, validators=[
            validators.FileExtensionValidator(
                ['html'],
                _('Feather Wiki files must be in HTML format'),
            ), _validate_not_index_file
        ], help_text=_(
            'Upload an existing Feather Wiki file from this computer.'))