-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Template and TemplateCategory models #2212
Conversation
- Template.category is now Template.template_category - In Template and TemplateHistory, template_category now leverage a primary join to both allow the full TemplateCategory model to be loaded when fetching either, and to prevent a list of associated templates from being populated on a TemplateCategory model - Updated the Template and TemplateHistory schemas to include the TemplateCategory when returning data to API callers
|
||
db.session.delete(template_category) | ||
db.session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move the commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because with @transactional
we auto commit after the method executes. Buuuut in testing I had removed @transactional
. I'll add it back in - nice catch
def category(cls): | ||
return db.relationship("TemplateCategory") | ||
def template_category(cls): | ||
return db.relationship("TemplateCategory", primaryjoin="Template.template_category_id == TemplateCategory.id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
@@ -396,6 +396,7 @@ class TemplateSchema(BaseTemplateSchema): | |||
created_by = field_for(models.Template, "created_by", required=True) | |||
is_precompiled_letter = fields.Method("get_is_precompiled_letter") | |||
process_type = field_for(models.Template, "process_type") | |||
template_category = fields.Nested(TemplateCategorySchema, dump_only=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I missed adding the sms_sending_vehicle can we add it in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a simple type and the TemplateCategorySchema
references our model. Since you updated it there it picks it up okay in the front end. Here's what it looks like locally in Redis:
{
"id": "d59f9609-b965-4836-bb51-904ee9f3c2b7",
"name_en": "hmm",
"name_fr": "hmm",
"description_en": "hmm",
"description_fr": "hmm",
"sms_process_type": "normal",
"email_process_type": "priority",
"hidden": false,
"created_at": "2024-07-08T19:05:13.129712",
"updated_at": null,
"sms_sending_vehicle": "long_code"
}
template_categories:
{
"id": "b6c42a7e-2a26-4a07-802b-123a5c3198a9",
"name_en": "Authentication",
"name_fr": "Authentification",
"description_en": "Password resets and two factor verification",
"description_fr": "R\u00e9initialisations de mots de passe et v\u00e9rification \u00e0 deux facteurs",
"sms_process_type": "priority",
"email_process_type": "priority",
"hidden": false,
"created_at": "2024-07-08T17:03:08.501236",
"updated_at": "2024-07-08T17:03:08.501236",
"sms_sending_vehicle": "short_code"
},
{
"id": "977e2a00-f957-4ff0-92f2-ca3286b24786",
"name_en": "Automatic reply",
"name_fr": "R\u00e9ponse automatique",
"description_en": "No-reply and confirmation messages",
"description_fr": "Messages auxquels il est impossible de r\u00e9pondre et messages de confirmation",
"sms_process_type": "priority",
"email_process_type": "priority",
"hidden": false,
"created_at": "2024-07-08T17:03:08.501236",
"updated_at": "2024-07-08T17:03:08.501236",
"sms_sending_vehicle": "short_code"
},
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
- Restored @transactional decorator - Simplified setting the default template categories during a delete
Summary | Résumé
Template.category
is nowTemplate.template_category
Template
andTemplateHistory
, thetemplate_category
attribute now leverage a primary join to:Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
TODO: Fill in test instructions for the reviewer.
Release Instructions | Instructions pour le déploiement
None.
Reviewer checklist | Liste de vérification du réviseur