From c5d0e021660accf32706c34ca0146b10632c4cec Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Jan 2020 01:05:27 -0800 Subject: [PATCH] openlibrary search --- fedireads/forms.py | 43 ++++++++++++++++++ fedireads/incoming.py | 1 - fedireads/migrations/0001_initial.py | 18 +------- fedireads/models.py | 12 +---- fedireads/openlibrary.py | 43 +++++++++--------- fedireads/outgoing.py | 1 - fedireads/static/images/default_avi.jpg | Bin 0 -> 6756 bytes fedireads/static/images/no_cover.jpg | Bin 0 -> 8205 bytes fedireads/templates/book_results.html | 13 ++++++ fedireads/templates/feed.html | 2 + .../{results.html => user_results.html} | 0 fedireads/urls.py | 2 +- fedireads/views.py | 15 +++--- rebuilddb.sh | 4 +- 14 files changed, 91 insertions(+), 63 deletions(-) create mode 100644 fedireads/forms.py create mode 100644 fedireads/static/images/default_avi.jpg create mode 100644 fedireads/static/images/no_cover.jpg create mode 100644 fedireads/templates/book_results.html rename fedireads/templates/{results.html => user_results.html} (100%) diff --git a/fedireads/forms.py b/fedireads/forms.py new file mode 100644 index 000000000..25870fef8 --- /dev/null +++ b/fedireads/forms.py @@ -0,0 +1,43 @@ +''' usin django model forms ''' +from django.forms import ModelForm, PasswordInput + +from fedireads import models + + +class LoginForm(ModelForm): + class Meta: + model = models.User + fields = ['username', 'password'] + help_texts = {f: None for f in fields} + widgets = { + 'password': PasswordInput(), + } + + +class RegisterForm(ModelForm): + class Meta: + model = models.User + fields = ['username', 'email', 'password'] + help_texts = {f: None for f in fields} + widgets = { + 'password': PasswordInput(), + } + + +class ReviewForm(ModelForm): + class Meta: + model = models.Review + fields = ['name', 'review_content', 'rating'] + help_texts = {f: None for f in fields} + labels = { + 'name': 'Title', + 'review_content': 'Review', + 'rating': 'Rating (out of 5)', + } + + +class EditUserForm(ModelForm): + class Meta: + model = models.User + fields = ['avatar', 'name', 'summary'] + help_texts = {f: None for f in fields} diff --git a/fedireads/incoming.py b/fedireads/incoming.py index d5ebaf559..bb7b0fca4 100644 --- a/fedireads/incoming.py +++ b/fedireads/incoming.py @@ -193,7 +193,6 @@ def handle_incoming_create(activity): content=activity, activity_type='Article', book=book, - work=book.works.first(), name=activity['object']['name'], rating=activity['object']['rating'], review_content=activity['objet']['content'], diff --git a/fedireads/migrations/0001_initial.py b/fedireads/migrations/0001_initial.py index 5bbe22373..962fab954 100644 --- a/fedireads/migrations/0001_initial.py +++ b/fedireads/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.2 on 2020-01-29 07:36 +# Generated by Django 3.0.2 on 2020-01-29 09:04 from django.conf import settings import django.contrib.auth.models @@ -109,16 +109,6 @@ class Migration(migrations.Migration): ('updated_date', models.DateTimeField(auto_now=True)), ], ), - migrations.CreateModel( - name='Work', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('openlibrary_key', models.CharField(max_length=255)), - ('data', django.contrib.postgres.fields.jsonb.JSONField()), - ('added_date', models.DateTimeField(auto_now_add=True)), - ('updated_date', models.DateTimeField(auto_now=True)), - ], - ), migrations.CreateModel( name='Note', fields=[ @@ -154,11 +144,6 @@ class Migration(migrations.Migration): name='shelves', field=models.ManyToManyField(through='fedireads.ShelfBook', to='fedireads.Shelf'), ), - migrations.AddField( - model_name='book', - name='works', - field=models.ManyToManyField(to='fedireads.Work'), - ), migrations.CreateModel( name='ShelveActivity', fields=[ @@ -180,7 +165,6 @@ class Migration(migrations.Migration): ('rating', models.IntegerField(default=0)), ('review_content', models.TextField()), ('book', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fedireads.Book')), - ('work', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fedireads.Work')), ], bases=('fedireads.activity',), ), diff --git a/fedireads/models.py b/fedireads/models.py index 7feecce68..47783ad1b 100644 --- a/fedireads/models.py +++ b/fedireads/models.py @@ -133,7 +133,6 @@ class FollowActivity(Activity): class Review(Activity): ''' a book review ''' book = models.ForeignKey('Book', on_delete=models.PROTECT) - work = models.ForeignKey('Work', on_delete=models.PROTECT) name = models.CharField(max_length=255) # TODO: validation rating = models.IntegerField(default=0) @@ -200,11 +199,10 @@ class ShelfBook(models.Model): class Book(models.Model): - ''' a non-canonical copy from open library ''' + ''' a non-canonical copy of a work (not book) from open library ''' activitypub_id = models.CharField(max_length=255) openlibrary_key = models.CharField(max_length=255, unique=True) data = JSONField() - works = models.ManyToManyField('Work') authors = models.ManyToManyField('Author') cover = models.ImageField(upload_to='covers/', blank=True, null=True) shelves = models.ManyToManyField( @@ -227,14 +225,6 @@ class Book(models.Model): super().save(*args, **kwargs) -class Work(models.Model): - ''' encompassses all editions of a book ''' - openlibrary_key = models.CharField(max_length=255) - data = JSONField() - added_date = models.DateTimeField(auto_now_add=True) - updated_date = models.DateTimeField(auto_now=True) - - class Author(models.Model): openlibrary_key = models.CharField(max_length=255) data = JSONField() diff --git a/fedireads/openlibrary.py b/fedireads/openlibrary.py index 964792bd7..94dcde77e 100644 --- a/fedireads/openlibrary.py +++ b/fedireads/openlibrary.py @@ -3,10 +3,27 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.files.base import ContentFile import requests -from fedireads.models import Author, Book, Work +from fedireads.models import Author, Book from fedireads.settings import OL_URL +def book_search(query): + ''' look up a book ''' + response = requests.get('%s/search.json' % OL_URL, params={'q': query}) + if not response.ok: + response.raise_for_status() + data = response.json() + results = [] + for doc in data['docs'][:5]: + key = doc['key'].split('/')[-1] + results.append({ + 'title': doc['title'], + 'olkey': key, + 'year': doc['first_publish_year'], + 'author': doc['author_name'][0], + }) + return results + def get_or_create_book(olkey, user=None, update=False): ''' add a book ''' # TODO: check if this is a valid open library key, and a book @@ -36,13 +53,9 @@ def get_or_create_book(olkey, user=None, update=False): # great, we can update our book. book.save() - # we also need to know the author and works related to this book. - for work_id in data['works']: - work_id = work_id['key'] - book.works.add(get_or_create_work(work_id)) - - for author_id in data['authors']: - author_id = author_id['key'] + # we also need to know the author get the cover + for author_blob in data['authors']: + author_id = author_blob['author']['key'] book.authors.add(get_or_create_author(author_id)) if len(data['covers']): @@ -62,20 +75,6 @@ def get_cover(cover_id): return [image_name, image_content] -def get_or_create_work(olkey): - ''' load em up ''' - # TODO: validate that this is a work key - # TODO: error handling - try: - work = Work.objects.get(openlibrary_key=olkey) - except ObjectDoesNotExist: - response = requests.get(OL_URL + olkey + '.json') - data = response.json() - work = Work(openlibrary_key=olkey, data=data) - work.save() - return work - - def get_or_create_author(olkey): ''' load that author ''' # TODO: validate that this is an author key diff --git a/fedireads/outgoing.py b/fedireads/outgoing.py index ec9b8ea05..f645b7f00 100644 --- a/fedireads/outgoing.py +++ b/fedireads/outgoing.py @@ -188,7 +188,6 @@ def handle_review(user, book, name, content, rating): content=activity, activity_type='Article', book=book, - work=book.works.first(), name=name, rating=rating, review_content=content, diff --git a/fedireads/static/images/default_avi.jpg b/fedireads/static/images/default_avi.jpg new file mode 100644 index 0000000000000000000000000000000000000000..80829abb82be7bd73f899eb9dac0805a7b13d999 GIT binary patch literal 6756 zcmbW42|SeD+sDs6`wX(nZtPn~*(GYMAxrkG4KeoYTS!H=NJvVGO7=UnI9=Xb7i=DvpZiZ%gQ4(J={0|){rU6d{W zv`G-J7eP4+fT<~v0RZ3t8e#)Tm>~ECAYOp}$p9RH_h9G0AFFF zk4*3V_Z4v!@!KQfD)JB0eQ66o&D<*>Bp}!;Adt9QekV}dZ)A$1j|kgO7XOJXg92%< zGe8Y$HXffhzrH_~_Kwlch(vNRw=~l?GSQ=p0*rNFcp_8D@?nK6FOVHF5;O6NH(Y&Yr(`$4{SMtV3saKYw@Fhd$>( zcRzPJcffomEYt&LqzTN4VHA&Wme+RazH*P1lK_+r~);h0knXJ;4kn5JO@Ky6ik3=Fb9^w8rXm!2n#Vm z><|wm1c^hk&@M;~+6(DHCXgj$54l2~kUta(#Xu*aR45C|hps`T&>g4=dI)tx{m^S@ z5}JiRLq8Bm1S5h2A%KuTC?M1j`w+$mD})om6LAa?g*b&ci^xM1Au15{h=+(Lh#|xT z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ALwsZE9UEYx-ewTAp$t{fxzj=uxg>4Qb&aicN!RXd|CRkFye}k zf;n4Q4n#HJJiUF1Z`gUZ*FukTFsSg1OM}aN!>x7Mj)pew81|zB5dn7DePtxV#|@3o zq%TbtFYuQ>yy)ERJuk;J3yiwDdsF@nsUz{s#wI@iFk<&vR#rhD_rhH#H z?x7l0_}#sG>2Z@1*Y9(;Qt#Tda588ku!)JXkGJP-486 z+Vo%xDTPowF=M#nxZ-e5-eSg$xQR=#T!SHICw?S0#qk*kwpAJ*^X4Xp?9|U(5`6mU zfspqmp`wz3^kUEMV*7~beRXG_92~f6>~lCGkxisBw{ci#C!PQ9vl`9y1u z>zv|tEC%KjnPh@g>D7iS)6_=R>j8Q^S8-mI!B;K$wSM0gL9g1>& zVXBola5$}!Nq+vdbC>q=N2aaWIs32XLtjzzi_zS~w6ptel;z?@>~*p>S9nhrI$AeR zdPZr}hW{juaN>xRrvby-L5zn}O<3r}*510_w$l=QizSxYBbLmw`3two(~acLe8I8n->K7f{s5sT$F6u+QqHs%ejBUv~G~yckc1bR3c|= zO7=n-pKbqTlPeq-!WTU)+ZGV;n9m2Os!Vqid@g*kKWMGfesa_2W>MwPc^hHNlyLX~ KP^+X(d;MQmZEijQ literal 0 HcmV?d00001 diff --git a/fedireads/static/images/no_cover.jpg b/fedireads/static/images/no_cover.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e6fbb3bca09d60c814c35413dcac395ada7c287f GIT binary patch literal 8205 zcmbVw2Ut^Ev-V0O^bP{jiy&2cClqNaB1n-MG4$S>Km-vL5d;MV6{J`IAvUULq$m~? z=>keeq^Ln!fRwxO+|P6V`#ksl-}6n#&YPK8YpoIFHGwcz2 zTMO$$=D!!nYIP_eGz`uOKuBnGq`jr7_%Rn(ar6fO2TXtgr~=@Hiwd_nYT>Xmr?t76 zcogLHd;UL{^}(Ge0O(V)IwCIqNB!>sE?jtIG?a)Vkh{9KPZSQq=@1T%iw@t>lOW7{ zB4`K0cVgs?gcb;4fgSA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44KamdgLiP4aGe=cyo>1KzsgVoGRxEXt<>Ch`2z^{D;3bmp-ZH9EtrR9k`1@HP=jf zHhl+TOM}?zTo@gc4L&a9aNGS#I9ikR{yKD2_bY@AXFTn|g0Gzf{3D8wEtJc9Gen zxwGGiPct*U>c|;CO%~x(Pn!oSe01YPHxZY!n_iy8w(`?KW@aaicyulM0I9(@c&I*! zE0~=38sE2y-$D!>W}z-zB~Ndb&*(smePwtNySjkiI%s%${oLGS==~@b% z2KgSMvtJ!V=enOOu4MFj29{i>_s}rb42rI3dz;2|oeuWA526FFpz*JDTOQbdJ@hgl zx{r+iMR%ruJ@f{slv?a7PbSjU4h)Ao*|t;2rnaGcELeTm^Oa17tfZy=g~AW7uj`@G$U8o5VKXQPMb*h?)p>$h69DA$f?$HrEW_#_D1#2cd2f>wkr>rqzGg;V2^Kkt;502ZDp-NrxCwZ3(gYz!C z*UoDU^finX4En7kPlpX(n9ezsl~Y6ZT)vef{n<@rL{dENi|7PK*g4I^b*<-P zTx*oaflJA)d{mE1jIDy`x&*?7=j=(!%b$ab6-Xa$rgSl`xT35xlBJEs)(8b1q?6+u zM`wl>h_9(bd$#u5xa!t&)52pRp84RZax^cdRsn+(rGCeaF}Z}#CBpbteIritDQnD` zu&@@4zIRo|u6=3v;iP?HBzf|5Cx&!5CrgN{V7jfLz(^uB(h-N3Jb~WkKJNGJRg18N zNp|@&eS#8xf`(og#$*YrTys&he0+Ic^Bs9ntb?*C{Q%eBFZ1|agy+?1mD70M7LjN9 zt)@m2Ehm9{Geqcg>`dhSd(+HKor-FfCS%V>$t)x{6EcD{(mvUFwsww~_I|eLVD%;B z<%8;>zVbx*>=*29M7v_4u-!s*;A1haU(&(*ILRPBG9d`x65~)4qV%?ac5mGkYV~+# zy6J;dN?E2H_{SU0av> +
+

Search results

+ {% for result in results %} +
+ {{ result.title }} by {{ result.author }} ({{ result.year }}) +
+ {% endfor %} +
+ +{% endblock %} diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index 51ae43f1c..dcfea25bf 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -82,6 +82,7 @@ {{ activity.book.data.title }} by {{ activity.book.authors.first.data.name }} +
{{ book.data.description }}

{% elif activity.fedireads_type == 'Review' %} @@ -94,6 +95,7 @@ {{ activity.book.data.title }} by {{ activity.book.authors.first.data.name }} +
{{ book.data.description }}

{{ activity.name }}

diff --git a/fedireads/templates/results.html b/fedireads/templates/user_results.html similarity index 100% rename from fedireads/templates/results.html rename to fedireads/templates/user_results.html diff --git a/fedireads/urls.py b/fedireads/urls.py index 7aad76632..c551871f3 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -23,7 +23,7 @@ urlpatterns = [ path('logout/', views.user_logout), path('user/', views.user_profile), path('user//edit/', views.user_profile_edit), - path('book/', views.book_page), + path('work/', views.book_page), # internal action endpoints path('review/', views.review), diff --git a/fedireads/views.py b/fedireads/views.py index 271176be1..563dd1d4a 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -26,7 +26,7 @@ def home(request): user_books = models.Book.objects.filter(shelves__user=request.user).all() recent_books = models.Book.objects.order_by( 'added_date' - )[:10] + )[:5] following = models.User.objects.filter( Q(followers=request.user) | Q(id=request.user.id) @@ -163,10 +163,8 @@ def edit_profile(request): @login_required def book_page(request, book_identifier): ''' info about a book ''' - book = openlibrary.get_or_create_book('/book/' + book_identifier) - reviews = models.Review.objects.filter( - Q(work=book.works.first()) | Q(book=book) - ) + book = openlibrary.get_or_create_book('/work/' + book_identifier) + reviews = models.Review.objects.filter(book=book) rating = reviews.aggregate(Avg('rating')) review_form = forms.ReviewForm() data = { @@ -244,9 +242,10 @@ def search(request): query = request.GET.get('q') if re.match(r'\w+@\w+.\w+', query): results = [api.handle_account_search(query)] + template = 'user_results.html' else: - # TODO: book search - results = [] + results = openlibrary.book_search(query) + template = 'book_results.html' - return TemplateResponse(request, 'results.html', {'results': results}) + return TemplateResponse(request, template, {'results': results}) diff --git a/rebuilddb.sh b/rebuilddb.sh index 9792e8335..6ac61b478 100755 --- a/rebuilddb.sh +++ b/rebuilddb.sh @@ -12,6 +12,6 @@ echo "from fedireads.models import User User.objects.create_user('rat', 'rat@rat.com', 'ratword') User.objects.get(id=1).followers.add(User.objects.get(id=2))" | python manage.py shell echo "from fedireads.openlibrary import get_or_create_book -get_or_create_book('/book/OL13549170M') -get_or_create_book('/book/OL24738110M')" | python manage.py shell +get_or_create_book('/work/OL1715344W') +get_or_create_book('/work/OL102749W')" | python manage.py shell python manage.py runserver