Exemplo n.º 1
0
class ProductionField(forms.Field):
    def __init__(self, *args, **kwargs):
        self.types_to_set = kwargs.pop('types_to_set', [])
        self.show_production_type_field = kwargs.pop('show_production_type_field', False)
        self.byline_field = BylineField(required=False)
        supertype = kwargs.pop('supertype', None)
        self.widget = ProductionWidget(
            types_to_set=self.types_to_set,
            supertype=supertype,
            show_production_type_field=self.show_production_type_field,
        )

        super().__init__(*args, **kwargs)

    def clean(self, value):
        if not value:
            value = None
        else:
            value = ProductionSelection.from_value(value, types_to_set=self.types_to_set)
            value.byline = self.byline_field.clean(value.byline_lookup)

        return super().clean(value)

    def has_changed(self, initial, data):
        initial = ProductionSelection.from_value(initial)
        data = ProductionSelection.from_value(data)
        return data != initial
Exemplo n.º 2
0
class ProductionField(forms.Field):
	def __init__(self, *args, **kwargs):
		self.types_to_set = kwargs.pop('types_to_set', [])
		self.show_production_type_field = kwargs.pop('show_production_type_field', False)
		self.byline_field = BylineField(required=False)
		supertype = kwargs.pop('supertype', None)
		self.widget = ProductionWidget(
			types_to_set=self.types_to_set,
			supertype=supertype,
			show_production_type_field=self.show_production_type_field,
		)

		super(ProductionField, self).__init__(*args, **kwargs)

	def clean(self, value):
		if not value:
			value = None
		else:
			value = ProductionSelection.from_value(value, types_to_set=self.types_to_set)
			value.byline = self.byline_field.clean(value.byline_lookup)

		return super(ProductionField, self).clean(value)