clean up, add provider, defaults
parent
1c64bc33a8
commit
e034013b81
|
@ -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(
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue