Locating templates

23 views
Skip to first unread message

Stephen Allsopp

unread,
Jul 30, 2017, 7:58:46 AM7/30/17
to OHC-OPAL
I have a question, which seems almost too trivial, but I have scoured the 'net for documentation and can't find any.

I'm tweaking the out-of-the-box app, and wanting to modify the templates. From what I can tell, it uses the templates embedded in the opal sources, but a new model (obviously) doesn't have templates. So it throws a 404.

What I'm trying to figure out is what exactly the paths are, relative to the local app, that it searches to find templates in such cases, and what it expects them to be called. I sense that the documentation could do with a little improvement in this regard, and I would love to be part of improving that documentation, once I've figured out myself how it works! 

So, is there some really obvious bit of information I'm missing here, or can you point me in a direction that can get me going?

One of the snags seems to be that nowhere in the logs does it actually tell me what the template it's looking for is, and any error page is lost when it goes to display the 404 page and (as it happens) can't find that.

Eagerly awaiting some enlightenment :)

David Miller

unread,
Jul 30, 2017, 8:42:09 AM7/30/17
to Stephen Allsopp, OHC-OPAL
Hi Stephen ! 

Sorry to hear that you couldn't find what you were looking for in the docs - but thanks for mailing the list and letting us know, that's how we get to improve them :)

To answer your question specifically, Opal looks for subrecord templates using the Django template loader logic in the following ways:

Display templates: {{ template_dir }}/records/{{ subrecord api name }}.html
Form templates: {{ template_dir }}/forms/{{ subrecord api name }}_form.html

That means you should be able to override e.g. the diagnosis display template from Opal by creating a template at yourapp/templates/records/diagnosis.html

Although, I suspect you'd have to understand the way things are wired up to make that an obvious place to look, which is clearly suboptimal.
(e.g. It's actually documenting the methods used to find the templates)

Perhaps we need to explain some of this somewhere like this: http://opal.openhealthcare.org.uk/docs/guides/templates/ ? 
Would be interested to know where you looked / expected it to be...

For new models specifically, we also have a commandline tool that will do some code generation that checks for migrations to be made/run and creates the display and form templates:

Interesting to know that there's not enough logging explaining what's going wrong.
From my perspective that's probably a bug - if a model template doesn't exist, we should be able to know that and at least tell you what we're expecting to find.

Do you have steps to reproduce the situation where you're not getting what you expect and some extra logging would help?
This is one of those things where we don't have/notice the problem because we're not new to Opal - but if it's happened to you it'll probably happen to someone else, so good to make it clearer!

Best

David

--
You received this message because you are subscribed to the Google Groups "OHC-OPAL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ohc-opal+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--------------------
David Miller
Open Health Care

Stephen Allsopp

unread,
Jul 30, 2017, 8:54:55 AM7/30/17
to OHC-OPAL, stephen...@gmail.com
Thank you for such a quick response!

I think I've got enough commits in git to be able to reproduce the steps I took to break everything, so I'll go back and do that. I'm about to go on holiday, though, so there will be a few days' hiatus until I'm installed and can do this. Meanwhile, I shall look at the links you supplied, and pore over the sources.

I very much like the way the Opal framework hangs together, though, and am looking forward to using it as the basis for an app to manage clients (patients!) in a GP surgery counselling operation. If I can give something back to the project along the way, so much the better...

Stephen

Stephen Allsopp

unread,
Jul 31, 2017, 4:11:11 AM7/31/17
to OHC-OPAL, stephen...@gmail.com
I did think, when I went to the docs about templates, that they did seem very "thin" compared to what I was expecting.

And you make a good point about newbies sometimes having insights that those more familiar with a technology may miss - I've been on the other side of that line many, many times.

I am going to start logging my activities as I work through this, with the intention of being able to put together a reasonable guide to getting things working that you may be able to use to enhance the documentation.

My initial thought is that the tutorial could benefit from expansion, and I'd be happy to do what I can to lay some groundwork for that as I learn my way through. Although I am now working as a therapist, I did 25 years in IT, so I know my way around things in general - so this is a novel learning experience for me! :)


On Sunday, 30 July 2017 13:42:09 UTC+1, David Miller wrote:

David Miller

unread,
Jul 31, 2017, 8:51:02 AM7/31/17
to Stephen Allsopp, OHC-OPAL
I completely agree WRT the tutorial.

The current plan is to write another two tutorials:

- Theming your application, which would walk you through various settings for e.g. logos, ways to change the basic colour scheme, right through to complete redesigns and an explanation of how to approach a complete re-skin.
- Working with forms, which would introduce the Pathway module and the various patterns available for working with relatively complex forms 

We'd then end the current tutorial by suggesting these as different next steps and readers could choose what they were most interested in.

I think we'd very much appreciate a guide to getting things working ! 
Pull requests or suggested alterations to the documentation are very much welcome.

Interested to see how you get on with the counselling patients application - feel free to mail with any bumps you run into. 

I think Opal is very well suited to writing that kind of application - although I suspect there may still be a couple of places where there are some assumptions from secondary care that don't make sense for that setting. (e.g. demographics coming with a hospital_number field) 

To my mind the goal for Opal is very much that it should definitely work for a setting like counselling in a GP surgery so we'd be keen to know about any of those you find!

Best

David
Reply all
Reply to author
Forward
0 new messages