WIP: Draft: Support OpenGraph-based discovery for ExternalLinkWidget #2467

Draft
magicfelix wants to merge 3 commits from 396-external-link-widet-auto-discovery into master
Member

Closes #396
First I tried to query the OGP just after submitting the Widget creation. But I found no method to do that.

Is there a better way than doing it every time the Dashboard (/Widget) is accessed?

Closes #396 First I tried to query the OGP just after submitting the Widget creation. But I found no method to do that. Is there a better way than doing it every time the Dashboard (/Widget) is accessed?
Author
Member

requested review from @nik

requested review from @nik
Author
Member

added 15 commits

  • 1e124513...ee119980 - 14 commits from branch master
  • 3cca5184 - Support OpenGraph-based discovery for ExternalLinkWidget

Compare with previous version

added 15 commits <ul><li>1e124513...ee119980 - 14 commits from branch <code>master</code></li><li>3cca5184 - Support OpenGraph-based discovery for ExternalLinkWidget</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=14622&start_sha=1e124513397deb22c29570aa1c7147c753bb4dbd)
Author
Member

marked this merge request as ready

marked this merge request as **ready**
Author
Member

added 9 commits

  • 3cca5184...9599d931 - 8 commits from branch master
  • 5e3472cd - Support OpenGraph-based discovery for ExternalLinkWidget

Compare with previous version

added 9 commits <ul><li>3cca5184...9599d931 - 8 commits from branch <code>master</code></li><li>5e3472cd - Support OpenGraph-based discovery for ExternalLinkWidget</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=14702&start_sha=3cca5184e23aeddd627288e2fd27feb4efa81772)
Owner

assigned to @nik

assigned to @nik
Owner
        if not self.icon_url:
```suggestion:-0+0 if not self.icon_url: ```
Owner

Is the OG data guaranteed to contain an image member?

Is the OG data guaranteed to contain an `image` member?
Owner

Please use urljoin

Please use [urljoin](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urljoin)
Owner

Some additional questions:

  • Can we enhance the widgets with more information from OpenGraph than jsut the icon?
  • Should we provide an option to enable/disable Opengraph retrieval, and if enabled, always update the data on saving even if, e.g., the icon URL was already filled?
Some additional questions: * Can we enhance the widgets with more information from OpenGraph than jsut the icon? * Should we provide an option to enable/disable Opengraph retrieval, and if enabled, always update the data on saving even if, e.g., the icon URL was already filled?
Owner

requested review from @hansegucker and removed review request for @nik

requested review from @hansegucker and removed review request for @nik
Owner

Lastly, please update the changelog (in a separate commit)

Lastly, please update the changelog (in a separate commit)
Author
Member

Yes. According to https://ogp.me/

The four required properties for every page are:
...
og:image - An image URL which should represent your object within the graph.
...

Yes. According to https://ogp.me/ > The four required properties for every page are: > ... > og:image - An image URL which should represent your object within the graph. > ...
Author
Member
  1. Maybe also the title. I gave it a short try, but stuck at the problem that one cannot leave that field empty.
  2. When I specify a URL manually I'd expect it not to be overwritten. So I think such an option is not necessary. But we should add an notice, that leaving the image URL field empty is possible.
1. Maybe also the title. I gave it a short try, but stuck at the problem that one cannot leave that field empty. 2. When I specify a URL manually I'd expect it not to be overwritten. So I think such an option is not necessary. But we should add an notice, that leaving the image URL field empty is possible.
Author
Member

changed this line in version 4 of the diff

changed this line in [version 4 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=14845&start_sha=5e3472cd3a24bb1ddd16d47948f1885813485796#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_887_887)
Author
Member

changed this line in version 4 of the diff

changed this line in [version 4 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=14845&start_sha=5e3472cd3a24bb1ddd16d47948f1885813485796#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_892_892)
Author
Member

added 17 commits

  • 5e3472cd...662f796e - 16 commits from branch master
  • 9c7340a1 - Support OpenGraph-based discovery for ExternalLinkWidget

Compare with previous version

added 17 commits <ul><li>5e3472cd...662f796e - 16 commits from branch <code>master</code></li><li>9c7340a1 - Support OpenGraph-based discovery for ExternalLinkWidget</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=14845&start_sha=5e3472cd3a24bb1ddd16d47948f1885813485796)
Owner

When I specify a URL manually I'd expect it not to be overwritten. So I think such an option is not necessary. But we should add an notice, that leaving the image URL field empty is possible.

But what if the icon URL in Opengraph changes, and it has to be updated? How do we distinguish that situation?

> When I specify a URL manually I'd expect it not to be overwritten. So I think such an option is not necessary. But we should add an notice, that leaving the image URL field empty is possible. But what if the icon URL in Opengraph changes, and it has to be updated? How do we distinguish that situation?
Author
Member

If the image URL (or any other field that could be filled using OGP) is empty, an internal field could be automatically set to "Use OpenGraph".

The (only) reason I see to not provide an UI option for OGP is, that it is a bit redundant. But maybe it's the better way, when we're going to retreive more information than only one field.

If the image URL (or any other field that could be filled using OGP) is empty, an internal field could be automatically set to "Use OpenGraph". The (only) reason I see to not provide an UI option for OGP is, that it is a bit redundant. But maybe it's the better way, when we're going to retreive more information than only one field.
Author
Member

changed this line in version 5 of the diff

changed this line in [version 5 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15320&start_sha=9c7340a156ef00480e3ccf5777f5f41b6ad81f2c#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_890_913)
Author
Member

added 82 commits

  • 9c7340a1...ca1c6df2 - 81 commits from branch master
  • 9477978e - Support OpenGraph-based discovery for ExternalLinkWidget

Compare with previous version

added 82 commits <ul><li>9c7340a1...ca1c6df2 - 81 commits from branch <code>master</code></li><li>9477978e - Support OpenGraph-based discovery for ExternalLinkWidget</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15320&start_sha=9c7340a156ef00480e3ccf5777f5f41b6ad81f2c)
Author
Member

marked this merge request as draft

marked this merge request as **draft**
Author
Member

added 18 commits

  • 9477978e...b215f55d - 17 commits from branch master
  • 3744d276 - Support OpenGraph-based discovery for ExternalLinkWidget

Compare with previous version

added 18 commits <ul><li>9477978e...b215f55d - 17 commits from branch <code>master</code></li><li>3744d276 - Support OpenGraph-based discovery for ExternalLinkWidget</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15428&start_sha=9477978e5974e09d2508668c83a5464ffad22fad)
Author
Member

resolved all threads

resolved all threads
Author
Member

added 1 commit

  • dcad8e66 - Update changelog

Compare with previous version

added 1 commit <ul><li>dcad8e66 - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15430&start_sha=3744d2769e2169e889037ebfab5cc0311005ddfb)
Author
Member

marked this merge request as ready

marked this merge request as **ready**
Author
Member

added 2 commits

  • 94e2022f - Support OpenGraph-based discovery for ExternalLinkWidget
  • 6e1def0b - Update changelog

Compare with previous version

added 2 commits <ul><li>94e2022f - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>6e1def0b - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15432&start_sha=dcad8e661313c25c13c3deb19d3f2ec93410334d)
Author
Member

added 2 commits

  • 623b379e - Support OpenGraph-based discovery for ExternalLinkWidget
  • 710764f3 - Update changelog

Compare with previous version

added 2 commits <ul><li>623b379e - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>710764f3 - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15434&start_sha=6e1def0b05212172fd05a6a5e40617c5cf912ca0)
Author
Member

added 2 commits

  • 2c860cb3 - Support OpenGraph-based discovery for ExternalLinkWidget
  • 61d52885 - Update changelog

Compare with previous version

added 2 commits <ul><li>2c860cb3 - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>61d52885 - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15436&start_sha=710764f313afe94d3d408dd6fcfe1c129a7244d9)
Owner

approved this merge request

approved this merge request
Owner

Please be more specific about which field is missing

Please be more specific about which field is missing
Owner

I think it should default to False.

I think it should default to `False`.
Owner

Please move the if from the insert_ogp_data method here.

Please move the `if` from the `insert_ogp_data` method here.
Owner

What does the call argument do? It is not used in the code, and it is never passed.

What does the `call` argument do? It is not used in the code, and it is never passed.
Owner

Can this raise an exception?

Can this raise an exception?
Owner

Please swap the branches, i.e. check for not is_valid here and raise then. This allows the rest of the code to be indentend one level less.

Please swap the branches, i.e. check for `not is_valid` here and raise then. This allows the rest of the code to be indentend one level less.
Owner
                if not self.icon_url.contains("://"):

This is protocol-agnostic, and allows for using :// literally (meaning "use the same protocol the site was loaded with")

```suggestion:-0+0 if not self.icon_url.contains("://"): ``` This is protocol-agnostic, and allows for using `://` literally (meaning "use the same protocol the site was loaded with")
Owner

See above.

See above.
Owner

Is this necessary? clean should be called anyway, so this would import OGP twice (please verify)

Is this necessary? `clean` should be called anyway, so this would import OGP twice (please verify)
Owner

The title should be checked as well, right?

The title should be checked as well, right?
Author
Member

This is already being checked in DashboardWidget's clean() method.

This is already being checked in DashboardWidget's clean() method.
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_918_918)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_949_950)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_954_955)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_960_964)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_963_967)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_966_967)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_971_967)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_974_970)
Author
Member

changed this line in version 11 of the diff

changed this line in [version 11 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_970_967)
Author
Member

added 2 commits

  • 7ea2513b - Support OpenGraph-based discovery for ExternalLinkWidget
  • 8d8c8c3b - Update changelog

Compare with previous version

added 2 commits <ul><li>7ea2513b - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>8d8c8c3b - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15445&start_sha=61d52885c2b44f00c36485d146f9f257b35a06f6)
Author
Member

Verified: Works.

Verified: Works.
Author
Member

resolved all threads

resolved all threads
Owner
            raise ValidationError(_("Please fill in the title."), code="field_missing")
```suggestion:-0+0 raise ValidationError(_("Please fill in the title."), code="field_missing") ```
Owner
            raise ValidationError(_("Please fill in the icon URL."), code="field_missing")
```suggestion:-0+0 raise ValidationError(_("Please fill in the icon URL."), code="field_missing") ```
Owner

On second thought, the original exceptions should be raised here, so we do not throw a (translated) ValidationError if this code is called from somewhere else than clean.

On second thought, the original exceptions should be raised here, so we do not throw a (translated) `ValidationError` if this code is called from somewhere else than `clean`.
Author
Member

changed this line in version 12 of the diff

changed this line in [version 12 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15447&start_sha=8d8c8c3bfb49fb82ef33e281b6c541cd22db2e9f#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_966_970)
Author
Member

changed this line in version 12 of the diff

changed this line in [version 12 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15447&start_sha=8d8c8c3bfb49fb82ef33e281b6c541cd22db2e9f#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_918_918)
Author
Member

changed this line in version 12 of the diff

changed this line in [version 12 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15447&start_sha=8d8c8c3bfb49fb82ef33e281b6c541cd22db2e9f#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_958_963)
Author
Member

changed this line in version 12 of the diff

changed this line in [version 12 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15447&start_sha=8d8c8c3bfb49fb82ef33e281b6c541cd22db2e9f#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_971_970)
Author
Member

added 2 commits

  • d008bddd - Support OpenGraph-based discovery for ExternalLinkWidget
  • 3d3461db - Update changelog

Compare with previous version

added 2 commits <ul><li>d008bddd - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>3d3461db - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15447&start_sha=8d8c8c3bfb49fb82ef33e281b6c541cd22db2e9f)
Author
Member

It's now called in clean()

It's now called in `clean()`
Author
Member

resolved all threads

resolved all threads
Author
Member

added 2 commits

  • 83061559 - Support OpenGraph-based discovery for ExternalLinkWidget
  • 3b77e26e - Update changelog

Compare with previous version

added 2 commits <ul><li>83061559 - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>3b77e26e - Update changelog</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15449&start_sha=3d3461dbf83ad3a35dfa9c44e0218d98c5ce0bde)
Owner
            raise RuntimeError("Invalid OpenGraph data")
```suggestion:-0+0 raise RuntimeError("Invalid OpenGraph data") ```
Owner

resolved all threads

resolved all threads
Owner

changed this line in version 14 of the diff

changed this line in [version 14 of the diff](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15451&start_sha=3b77e26ebb139e76e4fb0ad11461ce2f9747da0b#2e44ad1f61249cf0440bea20d23bd07cc7f3a61a_970_970)
Owner

added 1 commit

  • dbcaaff1 - Raise RuntimeError instead of base Exception

Compare with previous version

added 1 commit <ul><li>dbcaaff1 - Raise RuntimeError instead of base Exception</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=15451&start_sha=3b77e26ebb139e76e4fb0ad11461ce2f9747da0b)
nik scheduled this pull request to auto merge when all checks succeed 2021-12-30 20:45:33 +01:00
Owner

The clean method has to return a dictionary of cleand data, like described here: https://docs.djangoproject.com/en/4.0/ref/forms/validation/#validating-fields-with-clean

The `clean` method has to return a dictionary of cleand data, like described here: https://docs.djangoproject.com/en/4.0/ref/forms/validation/#validating-fields-with-clean
Author
Member

marked this merge request as draft

marked this merge request as **draft**
Author
Member

aborted the automatic merge because source branch was updated

aborted the automatic merge because source branch was updated
Author
Member

added 236 commits

  • dbcaaff1...dfef0f1f - 233 commits from branch master
  • 562bf06b - Support OpenGraph-based discovery for ExternalLinkWidget
  • cd2bb6a2 - Update changelog
  • ef5637ba - Raise RuntimeError instead of base Exception

Compare with previous version

added 236 commits <ul><li>dbcaaff1...dfef0f1f - 233 commits from branch <code>master</code></li><li>562bf06b - Support OpenGraph-based discovery for ExternalLinkWidget</li><li>cd2bb6a2 - Update changelog</li><li>ef5637ba - Raise RuntimeError instead of base Exception</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-Core/-/merge_requests/822/diffs?diff_id=17074&start_sha=dbcaaff1a12e72e3dd4df46578810262980e0aec)
Owner

removed review request for @hansegucker

removed review request for @hansegucker
This pull request has changes conflicting with the target branch.
  • aleksis/core/models.py
  • pyproject.toml
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 396-external-link-widet-auto-discovery:396-external-link-widet-auto-discovery
git switch 396-external-link-widet-auto-discovery

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff 396-external-link-widet-auto-discovery
git switch 396-external-link-widet-auto-discovery
git rebase master
git switch master
git merge --ff-only 396-external-link-widet-auto-discovery
git switch 396-external-link-widet-auto-discovery
git rebase master
git switch master
git merge --no-ff 396-external-link-widet-auto-discovery
git switch master
git merge --squash 396-external-link-widet-auto-discovery
git switch master
git merge --ff-only 396-external-link-widet-auto-discovery
git switch master
git merge 396-external-link-widet-auto-discovery
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aleksis/AlekSIS-Core!2467
No description provided.