Add TemplateHistory.redact_personalisation attribute

TemplateHistory objects need to be connected to the template's
TemplateRedacted record. This requires setting up a new SQLAlchemy
relationship to allow accessing redact_personalisation from
TemplateHistory instances.

We can avoid creating a foreign key in this case by setting up an
explicit `primaryjoin` expression. Since TemplateHistory.id is
created from Template.id and TemplateRedacted.template_id is
already a foreign key to Template.id the foreign key should always
be valid even without a DB constraint.
This commit is contained in:
Alexey Bezhan
2017-11-09 14:50:18 +00:00
parent 79d417f13b
commit bdcc89b403

View File

@@ -645,6 +645,11 @@ class TemplateHistory(db.Model):
nullable=False,
default=NORMAL)
template_redacted = db.relationship('TemplateRedacted', foreign_keys=[id],
primaryjoin='TemplateRedacted.template_id == TemplateHistory.id')
redact_personalisation = association_proxy('template_redacted', 'redact_personalisation')
def get_link(self):
return url_for(
"v2_template.get_template_by_id",