Removes unused connector fields and adds active boolean

This commit is contained in:
Mouse Reeve 2021-05-11 09:54:04 -07:00
parent 9ea588b855
commit e7c5b77b4c
4 changed files with 35 additions and 21 deletions

View file

@ -102,13 +102,6 @@ class AbstractConnector(AbstractMinimalConnector):
# title we handle separately.
self.book_mappings = []
def is_available(self):
"""check if you're allowed to use this connector"""
if self.max_query_count is not None:
if self.connector.query_count >= self.max_query_count:
return False
return True
def get_or_create_book(self, remote_id):
"""translate arbitrary json into an Activitypub dataclass"""
# first, check if we have the origin_id saved

View file

@ -0,0 +1,34 @@
# Generated by Django 3.2 on 2021-05-11 16:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0073_sitesettings_footer_item"),
]
operations = [
migrations.RemoveField(
model_name="connector",
name="max_query_count",
),
migrations.RemoveField(
model_name="connector",
name="politeness_delay",
),
migrations.RemoveField(
model_name="connector",
name="query_count",
),
migrations.RemoveField(
model_name="connector",
name="query_count_expiry",
),
migrations.AddField(
model_name="connector",
name="active",
field=models.BooleanField(default=True),
),
]

View file

@ -17,6 +17,7 @@ class Connector(BookWyrmModel):
local = models.BooleanField(default=False)
connector_file = models.CharField(max_length=255, choices=ConnectorFiles.choices)
api_key = models.CharField(max_length=255, null=True, blank=True)
active = models.BooleanField(default=True)
base_url = models.CharField(max_length=255)
books_url = models.CharField(max_length=255)
@ -24,13 +25,6 @@ class Connector(BookWyrmModel):
search_url = models.CharField(max_length=255, null=True, blank=True)
isbn_search_url = models.CharField(max_length=255, null=True, blank=True)
politeness_delay = models.IntegerField(null=True, blank=True) # seconds
max_query_count = models.IntegerField(null=True, blank=True)
# how many queries executed in a unit of time, like a day
query_count = models.IntegerField(default=0)
# when to reset the query count back to 0 (ie, after 1 day)
query_count_expiry = models.DateTimeField(auto_now_add=True, blank=True)
def __str__(self):
return "{} ({})".format(
self.identifier,

View file

@ -84,13 +84,6 @@ class AbstractConnector(TestCase):
"""barebones connector for search with defaults"""
self.assertIsInstance(self.connector.book_mappings, list)
def test_is_available(self):
"""this isn't used...."""
self.assertTrue(self.connector.is_available())
self.connector.max_query_count = 1
self.connector.connector.query_count = 2
self.assertFalse(self.connector.is_available())
def test_get_or_create_book_existing(self):
"""find an existing book by remote/origin id"""
self.assertEqual(models.Book.objects.count(), 1)