sciapp / sampledb

Sample and Measurement Metadata Database
https://scientific-it-systems.iffgit.fz-juelich.de/SampleDB/
MIT License
21 stars 11 forks source link

Fix: Hide Change Language button for objects without translations #62

Closed timhallmann closed 1 month ago

FlorianRhiem commented 1 month ago

Hey @timhallmann, thanks for the PR, but I am slightly confused about it. The variable object_languages in the Python code is passed as languages to the templates in https://github.com/sciapp/sampledb/blob/06a0a424f0fee1f3cdd0410e957f011f06a47174/sampledb/frontend/objects/view.py#L144 and similarly the variable is called languages in https://github.com/sciapp/sampledb/blob/06a0a424f0fee1f3cdd0410e957f011f06a47174/sampledb/frontend/objects/versions.py#L69

I just tried the branch for this PR, and object_languages is simply undefined in the template.

timhallmann commented 1 month ago

Yep, this commit is a mess right now, sorry about that.

Anyway, languages in the template doesn't actually equal object_languages in view.py, nor does it equal template_kwargs['languages'] right before that is passed to render_template().

For example, try the following:

Result (on my system using the develop branch):

If I use object_languages in the template (and also pass it into the template...), everything works fine.

I have no idea where this goes wrong, I have not found a pesky jinja global or something like that.

FlorianRhiem commented 1 month ago

Ah, I've found the issue: The languages value is overridden by the result of get_object_form_template_kwargs(object_id) when using the inline_edit mode: https://github.com/sciapp/sampledb/blob/06a0a424f0fee1f3cdd0410e957f011f06a47174/sampledb/frontend/objects/view.py#L468 So renaming the object languages to object_languages would be the way to go, yes.

timhallmann commented 1 month ago

The update on line 461 was safe, so I thought it would be fine to place the log statement before the if condition... Well...

Have you already addressed this, or should I finish this later?

FlorianRhiem commented 1 month ago

I haven't fixed it, I figured since you were halfway there with the object_languages, you'd probably want to provide the other half. I can fix it, though, if you prefer that.

timhallmann commented 1 month ago

Done. I've unified the language code in view.py and versions.py.

I've also changed the "Change language" links to not remove the query arg for the diff view.

FlorianRhiem commented 1 month ago

Thanks again for the PR!