raise ValidationError("Cannot remove all managers from an organsation!")
return self.cleaned_data['remove_manager']
+ def clean_remove_email(self):
+ if self.cleaned_data['remove_email']:
+ for e in self.cleaned_data['remove_email']:
+ if e.newsarticle_set.exists():
+ raise ValidationError("Cannot remove an email address that has been used to post news articles. Please contact webmaster@postgresql.org to have this removed.")
+ return self.cleaned_data['remove_email']
+
def save(self, commit=True):
model = super(OrganisationForm, self).save(commit=False)
migrations.AddField(
model_name='newsarticle',
name='email',
- field=models.ForeignKey(blank=True, help_text='Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.', null=True, on_delete=django.db.models.deletion.CASCADE, to='core.OrganisationEmail', verbose_name='Reply email'),
+ field=models.ForeignKey(blank=True, help_text='Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.OrganisationEmail', verbose_name='Reply email'),
),
]
class NewsArticle(TwoModeratorsMixin, TristateModerateModel):
org = models.ForeignKey(Organisation, null=False, blank=False, verbose_name="Organisation", help_text="If no organisations are listed, please check the <a href=\"/account/orglist/\">organisation list</a> and contact the organisation manager or <a href=\"mailto:webmaster@postgresql.org\">webmaster@postgresql.org</a> if none are listed.", on_delete=models.CASCADE)
- email = models.ForeignKey(OrganisationEmail, null=True, blank=True, verbose_name="Reply email", help_text="Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.", on_delete=models.CASCADE)
+ email = models.ForeignKey(OrganisationEmail, null=True, blank=True, verbose_name="Reply email", help_text="Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.", on_delete=models.PROTECT)
date = models.DateField(null=False, blank=False, default=date.today, db_index=True)
title = models.CharField(max_length=200, null=False, blank=False)
content = models.TextField(null=False, blank=False)