Merge pull request #500 from mouse-reeve/import-bugs

Import bugs
This commit is contained in:
Mouse Reeve 2021-01-07 09:33:03 -08:00 committed by GitHub
commit eb47836bba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 4 deletions

View file

@ -34,10 +34,15 @@ class AbstractMinimalConnector(ABC):
for field in self_fields:
setattr(self, field, getattr(info, field))
def search(self, query, min_confidence=None):# pylint: disable=unused-argument
def search(self, query, min_confidence=None):
''' free text search '''
params = {}
if min_confidence:
params['min_confidence'] = min_confidence
resp = requests.get(
'%s%s' % (self.search_url, query),
params=params,
headers={
'Accept': 'application/json; charset=utf-8',
'User-Agent': settings.USER_AGENT,

View file

@ -13,6 +13,8 @@ class Connector(AbstractConnector):
''' instantiate a connector '''
def search(self, query, min_confidence=0.1):
''' search your local database '''
if not query:
return []
# first, try searching unqiue identifiers
results = search_identifiers(query)
if not results:

View file

@ -69,3 +69,5 @@ def import_data(job_id):
item.save()
finally:
create_notification(job.user, 'IMPORT', related_import=job)
job.complete = True
job.save()

View file

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2021-01-07 16:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0033_siteinvite_created_date'),
]
operations = [
migrations.AddField(
model_name='importjob',
name='complete',
field=models.BooleanField(default=False),
),
]

View file

@ -42,6 +42,7 @@ class ImportJob(models.Model):
created_date = models.DateTimeField(default=timezone.now)
task_id = models.CharField(max_length=100, null=True)
include_reviews = models.BooleanField(default=True)
complete = models.BooleanField(default=False)
privacy = models.CharField(
max_length=255,
default='public',

View file

@ -8,7 +8,7 @@
<p>
Import started: {{ job.created_date | naturaltime }}
</p>
{% if task.successful %}
{% if job.complete %}
<p>
Import completed: {{ task.date_done | naturaltime }}
</p>

View file

@ -258,10 +258,12 @@ def get_activity_feed(
def search(request):
''' that search bar up top '''
query = request.GET.get('q')
min_confidence = request.GET.get('min_confidence', 0.1)
if is_api_request(request):
# only return local book results via json so we don't cause a cascade
book_results = connector_manager.local_search(query)
book_results = connector_manager.local_search(
query, min_confidence=min_confidence)
return JsonResponse([r.json() for r in book_results], safe=False)
# use webfinger for mastodon style account@domain.com username
@ -278,7 +280,8 @@ def search(request):
similarity__gt=0.5,
).order_by('-similarity')[:10]
book_results = connector_manager.search(query)
book_results = connector_manager.search(
query, min_confidence=min_confidence)
data = {
'title': 'Search Results',
'book_results': book_results,