Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using TranslationAdmin with different admin template. #606

Open
hovi opened this issue Jul 17, 2021 · 3 comments
Open

Using TranslationAdmin with different admin template. #606

hovi opened this issue Jul 17, 2021 · 3 comments

Comments

@hovi
Copy link
Contributor

hovi commented Jul 17, 2021

Happy user of this package. I recently tried switching admin to other templates (currently experimenting with django-jazzmin).
Sadly tabs are not working there. Been debugging for a while and I think it is mostly (or only) because html structure does not match what is expected in JS code.

For example main select expects h1 to exist in #content to append it there (. In case of this template when I removed requirement for inner h1, main select started working, but not the rest.
https://github.com/deschler/django-modeltranslation/blob/master/modeltranslation/static/modeltranslation/js/tabbed_translation_fields.js#L466

Now after I already spent some time on this I'd like to know, if there's any documentation on this - what kind of structure is required for javascript to work or any hints, where should I look in javascript?

Think ideal scenario is if those hook elements in the templates could be somehow configurable using css selectors, but I expect that could require some more extensive refactoring. I am happy to create PR with some guidance if we find some easy solution, that can work nicely for everyone.

@last-partizan
Copy link
Collaborator

last-partizan commented Jul 17, 2021

Hi

There is no documentation on required structure, it just expects default django strcuture.

You are looking in right direction. If you want to make it work, you need to identify selectors which are different from django defaults, and create something like mapping.

const DefaultDjangoSelectors = {
  mainHeader: () => $("#content").find("h1")
};
const Djazzmin = {
  mainHeader: ...
};

const selectors = detectCurrentTemplate(); // this should return appropriate selectors.

And then refactor code to use those custom selectors.

@hovi
Copy link
Contributor Author

hovi commented Jul 17, 2021

Alright. If I create these configurations and function to detect template, are you willing to merge it?

One more step further, this configuration can also contain classes that are used to mark created html. Mostly meaning language switching tabs. I might as well use css framework I am using (at least I hope I could do that by just modifying css, one more step would be possibility to change html too, but I don't wanna go that far).

Edit:
Still it's a bit unfinished since existing configurations would be hardcoded in the file (but at least's it's step in the right direction). Will need some more to it. Maybe put in separate .js file that would just add/override configuration.

@last-partizan
Copy link
Collaborator

Yes, i'll merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants