-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn reference URLs into hyperlinks (#2234)
References in the References section should include a link, if a URL is provided. Fixes issue #658. I changed my mind many times about how this should be implemented. At first, I thought that we should separately provide "description" and "URL" fields for authors to edit. But now I think, actually, the URL is part of the formal reference, and should be displayed as text for transparency's sake. So I think it's better for the URL to be extracted automatically from the description. On the other hand, I don't want to have ad-hoc parsing rules applied at runtime to published content. (It's possible those rules might change in the future, which I think is okay for active but not for published projects.) So I ended up with this approach: - For active projects, the URL is extracted by a regular expression whenever it's needed. - When a project is published, the automatically-extracted URL is saved as a model field. - For published projects, it's possible to edit the `description` and `url` separately via Django admin, but it will only appear as a link if the `url` appears verbatim within the `description`.
- Loading branch information
Showing
13 changed files
with
90 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
physionet-django/project/migrations/0075_publishedreference_url.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 4.2.11 on 2024-05-13 20:18 | ||
|
||
import re | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def migrate_forward(apps, schema_editor): | ||
pattern = re.compile(r'\bhttps?://[^\s<>"\']+', re.IGNORECASE) | ||
|
||
PublishedReference = apps.get_model('project', 'PublishedReference') | ||
for reference in PublishedReference.objects.all(): | ||
m = pattern.search(reference.description) | ||
if m: | ||
reference.url = m.group() | ||
reference.save(update_fields=['url']) | ||
|
||
|
||
def migrate_backward(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("project", "0074_migrate_archived_to_active"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="publishedreference", | ||
name="url", | ||
field=models.URLField(blank=True, null=True), | ||
), | ||
migrations.RunPython(migrate_forward, migrate_backward), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
physionet-django/project/templates/project/reference_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ol> | ||
{% for reference in references %} | ||
<li>{{ reference.html_description }}</li> | ||
{% endfor %} | ||
</ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters