LUN-368 -- fix to handle orphan templates and templates assigned to shar...

...ed sites (PBS)

see also LUN-368 on lunchbox and LUN-368 on django-dbtemplates