-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework ads form, and add ADS.ads_in_use
- Loading branch information
Showing
13 changed files
with
494 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.forms.fields import BooleanField | ||
|
||
|
||
class NullBooleanField(BooleanField): | ||
"""NullBooleanField allows the following: | ||
>>> from mesads.app.widgets import BooleanSelect | ||
>>> class MyModel(models.Model): | ||
... myfield = models.BooleanField(blank=False, null=False) | ||
>>> class MyForm(forms.ModelForm): | ||
... class Meta: | ||
... model = MyModel | ||
... fields = ['myfield'] | ||
... myfield = NullBooleanField(widget=BooleanSelect) | ||
If BooleanField was used instead of NullBooleanField, and the the HTML form | ||
submits an empty value (because the first default option submitted is | ||
`<option disabled selected value>Select an option</option>`), the form would | ||
return an error because the field is required (because `blank=False`), but | ||
also when the "false" option is selected. | ||
NullBooleanField makes the distinction between the "false" option and the | ||
empty value. | ||
""" | ||
|
||
def to_python(self, value): | ||
"""Override the behavior of the base class which converts None to False.""" | ||
if value is None: | ||
return None | ||
return super().to_python(value) | ||
|
||
def validate(self, value): | ||
"""Override the behavior of the base class which triggers an error when value is False.""" | ||
if value is None and self.required: | ||
raise ValidationError(self.error_messages["required"], code="required") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 4.1.9 on 2024-02-15 15:45 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0069_adsmanageradministrator_referent_emails"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="ads", | ||
name="ads_in_use", | ||
field=models.BooleanField( | ||
default=True, verbose_name="L'ADS est-elle actuellement exploitée ?" | ||
), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.