django-survey
django-survey copied to clipboard
Survey.template option throws an exception "TemplateDoesNotExist"
When using the template option in a survey, it's hard to know what can be entered, and you can get an error.
Created from #31
Has progress been made on this issue? I am currently trying to find a way to create a survey from a template but am unsure how to use this field. Can you please give further instruction as to how the field is intended to be used in terms of what to do after you have assigned a template name to a survey and want to use that survey as a template to create a new survey?
Hello,
I looked at the code right now. Here's a relevant extract:
if survey.template is not None and len(survey.template) > 4:
template_name = survey.template
else:
if survey.display_by_question:
template_name = "survey/survey.html"
else:
template_name = "survey/one_page_survey.html"
So the value provided should probably be something like survey/survey_custom.html. I did not test it. But I think it should at least work without error if you put survey/survey.html in the field. If you have the time to make it more explicit in the documentation or inside the error raised when the value is incorrect, I'll be glad to merge your changes to the codebase and release a new version.
Changed to enhancement instead of bug because the error message appear if your template does not exist, and is explicit. If using survey/survey.html still raises an error it would be a bug.
I think, I would try this one, but I am not sure if I understand correctly. Do you want to have a warning in the admin if the template filename string is not valid or do you want the application to use a fallback if the custom survey template cannot be found?
I think an explicit translated error directly inside the model object would be nice. This way it should show an error in the admin if an impossible value is set. I don't know if there is another possible error than the template file that does not exist. Maybe we can check that we can render a template for this survey with the value given when we modify a Survey object? But if it's complicated let's just check that the given path to the template file is valid.
I also have a feeling that the template used is implicit because it works even if nothing is set in a Survey model. So by adding a default value (survey/survey.html) and using the value given all the time, we could make this more logical. What do you think ?