class CatalogItemForm(forms.ModelForm): id = forms.ModelChoiceField(queryset=CatalogItem.objects.all(), widget=forms.HiddenInput()) mainimage = forms.ImageField(widget=AdmImageWidget(), label=u'Zdjęcie główne', required=False) category = forms.ModelChoiceField(queryset=CatalogCategory.objects.all(), label=u'Kategoria ogłoszeń') tags = TagField(required=False) class Meta: model = CatalogItem fields = ('id', 'category', 'date', 'mainimage', 'tags', 'permissions') def __init__(self, *args, **kwargs): super(CatalogItemForm, self).__init__(*args, **kwargs) try: root_pgroup = PermisionGroup.objects.filter(model='CatalogItem') except Exception, e: print 'form/catalog.py: ', e root_pgroup = None self.fields[ 'permissions'].label = u'Uprawnienia - pozostaw puste jeśli mają być domyślne' if root_pgroup is not None: pgroups = [] for rg in root_pgroup: pg = PermisionGroup.objects.filter(parent=rg) for group in pg: pgroups.append((group.id, mark_safe(group.name))) self.fields['permissions'].choices = pgroups
class CatalogImageItemForm(forms.ModelForm): id = forms.ModelChoiceField(queryset=CatalogImage.objects.all(), widget=forms.HiddenInput()) temp = forms.BooleanField(widget=forms.HiddenInput(), required=False) date = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget()) date.widget.widgets = (forms.TextInput({'class': 'vDateField'}), forms.TextInput({'class': 'vTimeField'})) image = forms.ImageField(widget=AdmImageWidget(), label=u'Zdjęcie', required=False) tags = TagField(required=False) class Meta: model = CatalogImage fields = ('id', 'temp', 'date', 'image', 'sites', 'active', 'tags', 'permissions') def __init__(self, *args, **kwargs): super(CatalogImageItemForm, self).__init__(*args, **kwargs) try: root_pgroup = PermisionGroup.objects.filter(model='CatalogImage') except Exception, e: print 'form/catalog.py: ', e root_pgroup = None self.fields[ 'permissions'].label = u'Uprawnienia - pozostaw puste jeśli mają być domyślne' if root_pgroup is not None: pgroups = [] for rg in root_pgroup: pg = PermisionGroup.objects.filter(parent=rg) for group in pg: pgroups.append((group.id, mark_safe(group.name))) self.fields['permissions'].choices = pgroups
class AdsItemForm(forms.ModelForm): id = forms.ModelChoiceField(queryset=Ad.objects.all(), widget=forms.HiddenInput()) mainimage = forms.ImageField(widget=AdmImageWidget(), label=u'Zdjęcie główne', required=False) category = forms.ModelChoiceField(queryset=AdCategory.objects.all(), label=u'Kategoria ogłoszeń') datestart = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget()) datestart.widget.widgets = (forms.TextInput({'class': 'vDateField'}), forms.TextInput({'class': 'vTimeField'})) dateend = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget(), required=False) dateend.widget.widgets = (forms.TextInput({'class': 'vDateField'}), forms.TextInput({'class': 'vTimeField'})) tags = TagField(required=False) class Meta: model = Ad fields = ('id', 'category', 'date', 'mainimage', 'tags', 'images', 'bold', 'distinction', 'datestart', 'dateend', 'permissions') def __init__(self, *args, **kwargs): super(AdsItemForm, self).__init__(*args, **kwargs) try: root_pgroup = PermisionGroup.objects.filter(model='Ad') except Exception, e: print 'form/ads.py: ', e root_pgroup = None self.fields[ 'permissions'].label = u'Uprawnienia - pozostaw puste jeśli mają być domyślne' if root_pgroup is not None: pgroups = [] for rg in root_pgroup: pg = PermisionGroup.objects.filter(parent=rg) for group in pg: pgroups.append((group.id, mark_safe(group.name))) self.fields['permissions'].choices = pgroups