Fix delete templates that are in use

Fixes: bug #1201876

Change-Id: I458f9986f924bf553e68fd7c41390c853c340b2b
Merge "Fix delete templates that are in use"