class CompetitionForm(forms.ModelForm): shown_date = FuzzyDateField(label="Date", required=False) production_type = ProductionTypeChoiceField(required=False, queryset=ProductionType.objects.all()) platform = forms.ModelChoiceField(required=False, queryset=Platform.objects.all()) def log_creation(self, user): Edit.objects.create(action_type='create_competiton', focus=self.instance, focus2=self.instance.party, description=(u"Added competition %s" % self.instance.name), user=user) @property def changed_data_description(self): descriptions = [] changed_fields = self.changed_data if 'name' in changed_fields: descriptions.append(u"name to %s" % self.cleaned_data['name']) if 'shown_date' in changed_fields: descriptions.append(u"date to %s" % self.cleaned_data['shown_date']) if 'platform' in changed_fields: descriptions.append(u"platform to %s" % self.cleaned_data['platform']) if 'production_type' in changed_fields: descriptions.append(u"production type to %s" % self.cleaned_data['production_type']) if descriptions: return u"Set %s" % (u", ".join(descriptions)) def log_edit(self, user): description = self.changed_data_description if description: Edit.objects.create(action_type='edit_competition', focus=self.instance, description=description, user=user) class Meta: model = Competition fields = ('name', 'shown_date', 'platform', 'production_type')
def __init__(self, *args, **kwargs): super(CreateGraphicsForm, self).__init__(*args, **kwargs) self.fields['type'] = ProductionTypeChoiceField( queryset=ProductionType.graphic_types(), initial=ProductionType.objects.get(internal_name='graphics')) self.fields['platform'] = forms.ModelChoiceField( required=False, queryset=Platform.objects.all(), empty_label='Any')
class MusicIndexFilterForm(forms.Form): platform = forms.ModelChoiceField(required=False, queryset=Platform.objects.all(), empty_label='All platforms') production_type = ProductionTypeChoiceField(required=False, queryset=ProductionType.objects.none(), empty_label='All types') def __init__(self, *args, **kwargs): super(MusicIndexFilterForm, self).__init__(*args, **kwargs) self.fields['production_type'].queryset = ProductionType.music_types()
class MusicIndexFilterForm(forms.Form): platform = forms.ModelChoiceField(required=False, queryset=Platform.objects.all(), empty_label='All platforms') production_type = ProductionTypeChoiceField( required=False, queryset=ProductionType.music_types(), empty_label='All types')
def __init__(self, attrs=None, types_to_set=[], supertype=None, show_production_type_field=False): self.id_widget = forms.HiddenInput() self.title_widget = forms.TextInput() self.byline_widget = BylineWidget() self.types_to_set = types_to_set self.supertype = supertype self.production_type_widget = ProductionTypeChoiceField(queryset=ProductionType.objects.all()).widget self.show_production_type_field = show_production_type_field super().__init__(attrs=attrs)
def __init__(self, *args, **kwargs): super(GraphicsEditCoreDetailsForm, self).__init__(*args, **kwargs) self.has_multiple_types = False try: initial_type = self.instance.types.all()[0].id except IndexError: initial_type = None self.fields['type'] = ProductionTypeChoiceField( queryset=ProductionType.graphic_types(), initial=initial_type)