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

fix: tooltips for class docstrings, whitespace issues #463

Closed
wants to merge 1 commit into from

Conversation

koeaw
Copy link
Contributor

@koeaw koeaw commented Dec 7, 2023

  • fixes linebreaks between text and HTML tags caused by templatetag
  • checks for existence of proper docstring for classes (see PEP 257) instead of falling back on class definition

References:
https://peps.python.org/pep-0257/

Copy link
Contributor

github-actions bot commented Dec 7, 2023

Thanks for your contribution! ⚠️ there seems to be a problem with your commit messages - they should adhere to the https://conventionalcommits.org specification. Please fix that!

@koeaw koeaw force-pushed the kk/fix/template_whhitespace branch from d3e4ce9 to 398dcd8 Compare December 7, 2023 14:48
Copy link
Contributor

github-actions bot commented Dec 7, 2023

Thanks for your contribution! ⚠️ there seems to be a problem with your commit messages - they should adhere to the https://conventionalcommits.org specification. Please fix that!

@koeaw
Copy link
Contributor Author

koeaw commented Dec 7, 2023

That link in the bot message is broken (... and I dunno why it doesn't like the formatting of my commit message).

Edit: ah, line length, got it.

@b1rger
Copy link
Contributor

b1rger commented Dec 7, 2023

That link in the bot message is broken

yeah, I think I'll turn of the commenting - its rather annoying and the check output is probably enough as feedback

@koeaw koeaw force-pushed the kk/fix/template_whhitespace branch from 398dcd8 to 8731b3b Compare December 7, 2023 15:00
@koeaw koeaw linked an issue Dec 7, 2023 that may be closed by this pull request
@koeaw koeaw marked this pull request as ready for review December 7, 2023 15:43
@koeaw
Copy link
Contributor Author

koeaw commented Dec 7, 2023

Hm, hold on, still need to check something...

@koeaw koeaw marked this pull request as draft December 7, 2023 15:45
@koeaw
Copy link
Contributor Author

koeaw commented Dec 7, 2023

... Well, that docstring check is rather useless, oups.

- fixes occasional linebreaks between regular text and <abbr> HTML
  tags for tooltips with class meta information
- checks for existence of actual docstrings for classes to display
  on frontend over defaulting to class definitions "Class(a, b)"
@koeaw koeaw force-pushed the kk/fix/template_whhitespace branch from 8731b3b to 6471227 Compare December 11, 2023 11:55
@koeaw
Copy link
Contributor Author

koeaw commented Dec 11, 2023

The original PR description is outdated after a refactor and force push and/but this is still set to draft because:

  • I hadn't considered the ramifications of my proposed CSS change on the placement of the "Create new" button on entity (list) pages (side note: button text could be shortened to "Create"),
  • I had to give up tracking down how model.__doc__ is constructed when there is no docstring due to time constraints, so it's possible there is an easier/more elegant way to check for & exclude the not-so-helpful fallback.

@b1rger
Copy link
Contributor

b1rger commented Dec 11, 2023

I had to give up tracking down how model.__doc__ is constructed when there is no docstring due to time constraints, so it's possible there is an easier/more elegant way to check for & exclude the not-so-helpful fallback.

https://github.com/django/django/blob/b287af5dc954628d4b336aefc5027b2edceee64b/django/db/models/base.py#L399

@koeaw
Copy link
Contributor Author

koeaw commented Dec 11, 2023

I had to give up tracking down how model.__doc__ is constructed when there is no docstring due to time constraints, so it's possible there is an easier/more elegant way to check for & exclude the not-so-helpful fallback.

https://github.com/django/django/blob/b287af5dc954628d4b336aefc5027b2edceee64b/django/db/models/base.py#L399

Thank you!

@birger I wanted to tag you anyway because while I don't consider this finished yet/was expecting to work on this more, as per my previous comment, please let me know if you have any notes/feedback (if not a proper review yet). Just had to get that earlier update out of the way.

@b1rger
Copy link
Contributor

b1rger commented Dec 11, 2023

please let me know if you have any notes/feedback

I would put the logic of "calculating" the docstring into the class - either the AbstractEntity, but we might even use this for non entity models, so RootObject might make more sense. For example something like this:

@classmethod
@property
def description(cls):
    return cls.__doc__ 

That way we don't have to add it to the context, because a ListView has access to the model class via the queryset anyway - and in the template we can simply use {{ object_list.model.description }}. There is one problem though, the class_definition templatetag "filters" the context and only passes the two variables in:

@register.inclusion_tag("apis_metainfo/tags/class_definition.html", takes_context=True)

I think the whole vodoo with the values should be removed from that templatetag. But if we do that, then the whole templatetag becomes unnecesarry, and then the question is, why not add a second classmethod classname and simply replace the whole templatetag with <abbr title="{{ object_list.model.description }}">{{ object_list.model.classname }}</abbr> in the generic_list.html template itself... (the class_definition templatetag isn't being used anywhere else, afaics)

(updated after hitting submit too early...)

@koeaw koeaw self-assigned this Feb 8, 2024
@b1rger
Copy link
Contributor

b1rger commented Feb 14, 2024

The issue this PR tries to fix was fixed by using the generic app for the entities, so I think this can be closed?

@koeaw koeaw closed this Mar 20, 2024
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

Successfully merging this pull request may close these issues.

Unhelpful hints about classes on frontend + whitespace issue
2 participants