piki/pages/forms.py

17 lines
744 B
Python
Raw Normal View History

2024-10-05 16:22:40 +02:00
from typing import Any, Mapping
from django import forms
from django.forms.renderers import BaseRenderer
from django.forms.utils import ErrorList
class EditForm(forms.Form): # Note that it is not inheriting from forms.ModelForm
page_txt = forms.CharField(max_length=20000, label="Page source text", widget=forms.Textarea(attrs={"rows": "20"}))
2024-10-11 19:21:03 +02:00
page_tags = forms.CharField(max_length=20000, label="Tags (words separated by spaces)", required=False)
2024-10-05 16:22:40 +02:00
def __init__(self, *args, **kwargs) -> None:
page_data = kwargs.pop("page_data")
2024-10-11 14:23:50 +02:00
page_tags = kwargs.pop("page_tags")
2024-10-05 16:22:40 +02:00
super().__init__(*args, **kwargs)
2024-10-11 14:23:50 +02:00
self.fields['page_txt'].initial = page_data
self.fields['page_tags'].initial = page_tags