diff --git a/beesgospel/forms.py b/beesgospel/forms.py index c6be86c..2189a0d 100644 --- a/beesgospel/forms.py +++ b/beesgospel/forms.py @@ -55,6 +55,27 @@ class MembreEditForm(BootstrapMixin, forms.ModelForm): return super().save(**kwargs) +class ChantDocForm(BootstrapMixin, forms.ModelForm): + class Meta: + model = ChantDoc + fields = ["fichier", "lien", "titre"] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + if self.instance.pk and not self.instance.lien: + del self.fields["lien"] + if self.instance.pk:# and not self.instance.fichier: + del self.fields["fichier"] + + def clean(self): + data = super().clean() + if not data.get("fichier") and not data.get("lien"): + raise forms.ValidationError("Vous devez indiquer un fichier ou un lien") + elif data.get("fichier") and data.get("lien"): + raise forms.ValidationError("Vous ne pouvez pas indiquer à la fois un fichier et un lien") + return data + + class ChantEditForm(BootstrapMixin, forms.ModelForm): class Meta: model = Chant @@ -64,7 +85,7 @@ class ChantEditForm(BootstrapMixin, forms.ModelForm): super().__init__(**kwargs) self.formset = None if self.instance.pk: - DocFormSet = forms.inlineformset_factory(Chant, ChantDoc, fields=["fichier", "titre"], extra=1) + DocFormSet = forms.inlineformset_factory(Chant, ChantDoc, form=ChantDocForm, extra=1) self.formset = DocFormSet(data=kwargs.get("data"), files=kwargs.get("files"), instance=self.instance) def is_valid(self): diff --git a/beesgospel/migrations/0008_chantdoc_lien.py b/beesgospel/migrations/0008_chantdoc_lien.py new file mode 100644 index 0000000..c4aacc6 --- /dev/null +++ b/beesgospel/migrations/0008_chantdoc_lien.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('beesgospel', '0007_chantdoc'), + ] + + operations = [ + migrations.AddField( + model_name='chantdoc', + name='lien', + field=models.URLField(blank=True, verbose_name='Lien'), + ), + ] diff --git a/beesgospel/models.py b/beesgospel/models.py index e9cafe2..29039fc 100644 --- a/beesgospel/models.py +++ b/beesgospel/models.py @@ -123,6 +123,7 @@ class Chant(models.Model): class ChantDoc(models.Model): chant = models.ForeignKey(Chant, on_delete=models.CASCADE) fichier = models.FileField("Fichier", upload_to="chants", blank=True) + lien = models.URLField("Lien", blank=True) titre = models.CharField("Titre", max_length=200) def __str__(self): diff --git a/beesgospel/static/css/main.css b/beesgospel/static/css/main.css index 77bcfe4..d910ef9 100644 --- a/beesgospel/static/css/main.css +++ b/beesgospel/static/css/main.css @@ -58,6 +58,7 @@ nav { .red-bottom { border-bottom: 1px solid red; } .overleft { margin-left: -4rem; } .overright { margin-right: -4rem; } +.icon { max-width: 1.5rem; } .harlow { font-family: "Harlow Solid"; } .homeurl { color: white; text-decoration: none; } .homeurl:hover { color: lightgrey; } diff --git a/beesgospel/static/img/web-icon.svg b/beesgospel/static/img/web-icon.svg new file mode 100644 index 0000000..b8a6caf --- /dev/null +++ b/beesgospel/static/img/web-icon.svg @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/templates/membres/chant_edit.html b/templates/membres/chant_edit.html index 3420565..58a1cea 100644 --- a/templates/membres/chant_edit.html +++ b/templates/membres/chant_edit.html @@ -11,7 +11,13 @@ {% for subform in form.formset %}