From e034013b81b36bdfb65d2c457a58c39cb143748d Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 20 Feb 2023 20:04:10 -0500 Subject: [PATCH] clean up, add provider, defaults --- doab_check/doab_oai.py | 3 ++ ...nk_provider_alter_linkrel_role_and_more.py | 28 +++++++++++++++++++ doab_check/models.py | 14 +++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 doab_check/migrations/0002_link_provider_alter_linkrel_role_and_more.py diff --git a/doab_check/doab_oai.py b/doab_check/doab_oai.py index 235fd3c..a75b5bb 100644 --- a/doab_check/doab_oai.py +++ b/doab_check/doab_oai.py @@ -75,6 +75,9 @@ def load_doab_record(doab_id, title, item_type, urls, timestamps, **kwargs): """ logger.info('load doab %s', doab_id) (new_item, created) = Item.objects.get_or_create(doab=doab_id) + new_item.title = title + new_item.resource_type = item_type + new_item.save() new_record = Record.objects.create(item=new_item) for timestamp in timestamps: (new_timestamp, created) = Timestamp.objects.get_or_create( diff --git a/doab_check/migrations/0002_link_provider_alter_linkrel_role_and_more.py b/doab_check/migrations/0002_link_provider_alter_linkrel_role_and_more.py new file mode 100644 index 0000000..bc56f0d --- /dev/null +++ b/doab_check/migrations/0002_link_provider_alter_linkrel_role_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.7 on 2023-02-21 00:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('doab_check', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='link', + name='provider', + field=models.CharField(default='', max_length=255), + ), + migrations.AlterField( + model_name='linkrel', + name='role', + field=models.CharField(default='identifier', max_length=10), + ), + migrations.AlterField( + model_name='timestamp', + name='created', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/doab_check/models.py b/doab_check/models.py index 09f86d7..bc77f50 100644 --- a/doab_check/models.py +++ b/doab_check/models.py @@ -1,4 +1,5 @@ +from urllib.parse import urlparse from django.db import models @@ -27,6 +28,17 @@ class Link(models.Model): # so we can set it to dead instead of deleting live = models.BooleanField(default=True) + + # derived from url so we can do sorting, etc. + provider = models.CharField(max_length=255, default='') + + def save(self, *args, **kwargs): + if self.url: + netloc = urlparse(self.url).netloc.lower() + if netloc.startswith('www.'): + netloc = netloc[4:] + self.provider = netloc + super().save(*args, **kwargs) class Timestamp(models.Model): ''' timestamp of the record returned by doab. records can have multiple timestamps ''' @@ -43,7 +55,7 @@ class Record(models.Model): class LinkRel(models.Model): ''' association between an item and a link ''' # might be 'cover' - role = models.CharField(max_length=10, null=True) + role = models.CharField(max_length=10, default='identifier') link = models.ForeignKey("Link", related_name='related', on_delete=models.CASCADE) item = models.ForeignKey("Item", related_name='related', on_delete=models.CASCADE)