77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
from django import forms
|
|
from crispy_forms.helper import FormHelper
|
|
from crispy_forms.layout import Submit, HTML, Div
|
|
from crispy_bulma.layout import FormGroup
|
|
|
|
from . import models, fields
|
|
|
|
|
|
class BaseForm(forms.Form):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.helper = self.get_form_helper()
|
|
|
|
def get_form_helper(self):
|
|
helper = FormHelper(self)
|
|
# helper.add_input(Submit('submit', 'Submit', css_class='button is-link'))
|
|
# helper.layout.subm append(HTML('<a class="button is-light">Cancel</a>'))
|
|
# print(helper.layout)
|
|
helper.layout.append(
|
|
FormGroup(
|
|
Submit("submit", "Save", css_class="button is-primary"),
|
|
HTML(
|
|
'{% if view.cancel_url %}<div class="control"><a href="{{ view.cancel_url }}" class="button is-light">Cancel</a></div>{% endif %}'
|
|
),
|
|
)
|
|
)
|
|
return helper
|
|
|
|
|
|
class ProjectForm(forms.ModelForm, BaseForm):
|
|
class Meta:
|
|
model = models.Project
|
|
fields = ["name", "description", "modules", "event_date"]
|
|
# widgets = {
|
|
# 'event_date': forms.DateTimeInput(attrs={'type': 'date'})
|
|
# }
|
|
|
|
modules = forms.MultipleChoiceField(
|
|
choices=[(x, x.title()) for x in models.settings.POLYPHONIC_MODULES],
|
|
widget=forms.CheckboxSelectMultiple,
|
|
required=False,
|
|
)
|
|
|
|
|
|
class ResourceForm(forms.ModelForm, BaseForm):
|
|
class Meta:
|
|
model = models.Resource
|
|
fields = ["name", "media_type", "description", "file"]
|
|
|
|
def get_form_helper(self):
|
|
helper = super().get_form_helper()
|
|
helper[3].wrap(fields.BulmaFileUpload)
|
|
return helper
|
|
|
|
|
|
class WikiForm(forms.ModelForm, BaseForm):
|
|
class Meta:
|
|
model = models.WikiPage
|
|
fields = ["title", "markdown"]
|
|
|
|
|
|
class CodeForm(BaseForm):
|
|
code = forms.CharField(
|
|
max_length=14,
|
|
widget=forms.TextInput(
|
|
attrs={"placeholder": "xxx-xxx-xxx", "inputmode": "numeric"}
|
|
),
|
|
)
|
|
passphrase = forms.CharField(max_length=32)
|
|
|
|
|
|
class ResourceUploadForm(forms.Form):
|
|
pass
|
|
|
|
|
|
# file = S3UploadField()
|