combo/combo/apps/wcs/forms.py

53 lines
2.0 KiB
Python

# combo - content management system
# Copyright (C) 2014-2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from .models import WcsFormCell, WcsCategoryCell, WcsFormsOfCategoryCell
from .utils import get_wcs_options
class WcsFormCellForm(forms.ModelForm):
class Meta:
model = WcsFormCell
fields = ('formdef_reference',)
def __init__(self, *args, **kwargs):
super(WcsFormCellForm, self).__init__(*args, **kwargs)
formdef_references = get_wcs_options('json')
self.fields['formdef_reference'].widget = forms.Select(choices=formdef_references)
class WcsCategoryCellForm(forms.ModelForm):
class Meta:
model = WcsCategoryCell
fields = ('category_reference',)
def __init__(self, *args, **kwargs):
super(WcsCategoryCellForm, self).__init__(*args, **kwargs)
references = get_wcs_options('categories')
self.fields['category_reference'].widget = forms.Select(choices=references)
class WcsFormsOfCategoryCellForm(forms.ModelForm):
class Meta:
model = WcsFormsOfCategoryCell
fields = ('category_reference', 'ordering', 'limit')
def __init__(self, *args, **kwargs):
super(WcsFormsOfCategoryCellForm, self).__init__(*args, **kwargs)
references = get_wcs_options('categories')
self.fields['category_reference'].widget = forms.Select(choices=references)