From e7c5b77b4c2bdceb68e6a675c0f72b223f72e6c6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 11 May 2021 09:54:04 -0700 Subject: [PATCH] Removes unused connector fields and adds active boolean --- bookwyrm/connectors/abstract_connector.py | 7 ---- .../migrations/0074_auto_20210511_1651.py | 34 +++++++++++++++++++ bookwyrm/models/connector.py | 8 +---- .../connectors/test_abstract_connector.py | 7 ---- 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 bookwyrm/migrations/0074_auto_20210511_1651.py diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 18ccb942..f9496aa0 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -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 diff --git a/bookwyrm/migrations/0074_auto_20210511_1651.py b/bookwyrm/migrations/0074_auto_20210511_1651.py new file mode 100644 index 00000000..51e9e09c --- /dev/null +++ b/bookwyrm/migrations/0074_auto_20210511_1651.py @@ -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), + ), + ] diff --git a/bookwyrm/models/connector.py b/bookwyrm/models/connector.py index 625cdbed..4debcc3d 100644 --- a/bookwyrm/models/connector.py +++ b/bookwyrm/models/connector.py @@ -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, diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index 4497b4e5..5c50e4b7 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -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)