internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: bookwyrm-social/bookwyrm

Issue:
403 attempting to login
![6A0CC90F-F750-4128-83AA-BB02D4E649BD](https://user-images.githubusercontent.com/918105/109430197-f2d43600-79b4-11eb-8855-a58decfda03e.png)

It looks like if I open another tab I am logged into my account though. 


Discussion:
yikes!

Resolving patch:
diff --git a/bookwyrm/views/authentication.py b/bookwyrm/views/authentication.py
--- a/bookwyrm/views/authentication.py
+++ b/bookwyrm/views/authentication.py
@@ -6,6 +6,7 @@
 from django.template.response import TemplateResponse
 from django.utils import timezone
 from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import csrf_exempt
 from django.views import View
 
 from bookwyrm import forms, models
@@ -13,6 +14,7 @@
 
 
 # pylint: disable= no-self-use
+@method_decorator(csrf_exempt, name='dispatch')
 class Login(View):
     ''' authenticate an existing user '''
     def get(self, request):
@@ -29,6 +31,8 @@ def get(self, request):
 
     def post(self, request):
         ''' authentication action '''
+        if request.user.is_authenticated:
+            return redirect('/')
         login_form = forms.LoginForm(request.POST)
 
         localname = login_form.data['localname']


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Add publisher as a book field
Currently, the only way to distinguish editions is by their cover and their publication date. It would be nice if editions were also referred to by their publisher.

This is especially useful as part of the alt text of a cover for screen reader users, but also great for people who would like to catalog which edition is by which publisher. I believe OpenLibrary provides a publisher field as well, so this could be automagically filled during an import.


Discussion:
Luckily this data is in the database, it's just not being displayed anywhere :)
I merged that PR preemptively, oops
I don't see an issue with that ☺️

Checking this in production, the only thing that is missing at the moment is a field on the edit page to be able to edit the publisher.
Edit: This is also true for the /create-book page.

I'd also change the alt text on the covers to be in the format: Format, Publisher, Publication year. This will make it so that editions can be also distinguished by their cover via a screen reader.
yep, those two changes are the ones I meant to do before I merged that and closed this issue

Resolving patch:
diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py
--- a/bookwyrm/models/book.py
+++ b/bookwyrm/models/book.py
@@ -96,6 +96,7 @@ def edition_info(self):
             if self.languages and self.languages[0] != "English"
             else None,
             str(self.published_date.year) if self.published_date else None,
+            ", ".join(self.publishers) if hasattr(self, "publishers") else None,
         ]
         return ", ".join(i for i in items if i)
 


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Can't create Invites
**Describe the bug**
When creating a new invite, the following appears:
![screenshot that says ERRORS: invitees - This field is required](https://user-images.githubusercontent.com/66644064/113598361-4f261780-963d-11eb-96b4-6f712cc4d8fe.png)
Rest of the page is blank.

It appeared since the last update I did a few days ago (don't know at which commit exactly, sorry) and didn't change with the last one.

**Additional context**
It doesn't matter what I set for Expiry and Use limit.
Also, there's an invite in the list that has "Max uses: None" that I'm not sure where it comes from.



Discussion:
oh I know exactly how I broke this! should be a simple fix, just a sec

Resolving patch:
diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py
--- a/bookwyrm/forms.py
+++ b/bookwyrm/forms.py
@@ -233,7 +233,7 @@ class Meta:
 class CreateInviteForm(CustomForm):
     class Meta:
         model = models.SiteInvite
-        exclude = ["code", "user", "times_used"]
+        exclude = ["code", "user", "times_used", "invitees"]
         widgets = {
             "expiry": ExpiryWidget(
                 choices=[


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Make user handle search case insensitive
**Is your feature request related to a problem? Please describe.**
I'm not sure if this is intentional, but currently, you can only look up users if you spell their name witht he correct cases. This is also the case when you try to find BW users from Mastodon. I don't think case sensitivity makes much sense here.

**Additional context**
Mastodon hase case insensitive user names as well.

One can also register `Tofuwabohu` when there is a `tofuwabohu` already. I think that should be prevented before instances get opened?


Discussion:

Resolving patch:
diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py
--- a/bookwyrm/views/helpers.py
+++ b/bookwyrm/views/helpers.py
@@ -124,7 +124,7 @@ def handle_remote_webfinger(query):
         return None
 
     try:
-        user = models.User.objects.get(username=query)
+        user = models.User.objects.get(username__iexact=query)
     except models.User.DoesNotExist:
         url = "https://%s/.well-known/webfinger?resource=acct:%s" % (domain, query)
         try:
diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py
--- a/bookwyrm/views/search.py
+++ b/bookwyrm/views/search.py
@@ -34,7 +34,7 @@ def get(self, request):
         if query and re.match(regex.full_username, query):
             handle_remote_webfinger(query)
 
-        # do a  user search
+        # do a user search
         user_results = (
             models.User.viewer_aware_objects(request.user)
             .annotate(


Test patch:
diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py
--- a/bookwyrm/tests/views/test_helpers.py
+++ b/bookwyrm/tests/views/test_helpers.py
@@ -112,6 +112,9 @@ def test_existing_user(self, _):
         result = views.helpers.handle_remote_webfinger("mouse@local.com")
         self.assertEqual(result, self.local_user)
 
+        result = views.helpers.handle_remote_webfinger("mOuSe@loCal.cOm")
+        self.assertEqual(result, self.local_user)
+
     @responses.activate
     def test_load_user(self, _):
         """ find a remote user using webfinger """
Repository: bookwyrm-social/bookwyrm

Issue:
Books with same title but different subtitle are hard to distinguish in TL
**Is your feature request related to a problem? Please describe.**
Sometimes a book series has the same title for all books but different subtitles. Example: [Saga: Book One](https://bookwyrm.social/book/39501), [Saga: Book Two](https://bookwyrm.social/book/39471), [Saga: Book Three](https://bookwyrm.social/book/39465). This leads to confusion when something about a book is in my TL and only the title is shown.

**Describe the solution you'd like**
Can we include the subtitle in statuses, if it isn't too long? Maybe if title + subtitle is < X characters, show subtitle?

**Additional context**
![screenshot_2021-04-23T10:25:32](https://user-images.githubusercontent.com/3681516/115842957-a1797d80-a41e-11eb-8151-a60b55da64fd.png)
 The bottom is “Saga: Book One” and the top is “Saga: Book Two”.



Discussion:

Resolving patch:
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -168,6 +168,17 @@ def get_next_shelf(current_shelf):
     return "to-read"
 
 
+@register.filter(name="title")
+def get_title(book):
+    """ display the subtitle if the title is short """
+    if not book:
+        return ""
+    title = book.title
+    if len(title) < 6 and book.subtitle:
+        title = "{:s}: {:s}".format(title, book.subtitle)
+    return title
+
+
 @register.simple_tag(takes_context=False)
 def related_status(notification):
     """ for notifications """


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Additional data fields for author
It would be nice if authors had "pseudonym" or "AKA" fields.
This would allow you to find works by the same author written under different pseudonyms.




Discussion:
Yes! This field exists in the database but not in the UI. I think it would be straightforward and useful to display it and make it editable, and include it in the fields that search looks at
> I think it would be straightforward and useful to display it and make it editable, and include it in the fields that search looks at.

It would be the best solution!

Resolving patch:
diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py
--- a/bookwyrm/views/author.py
+++ b/bookwyrm/views/author.py
@@ -29,7 +29,7 @@ def get(self, request, author_id):
             "author": author,
             "books": [b.default_edition for b in books],
         }
-        return TemplateResponse(request, "author.html", data)
+        return TemplateResponse(request, "author/author.html", data)
 
 
 @method_decorator(login_required, name="dispatch")
@@ -43,7 +43,7 @@ def get(self, request, author_id):
         """info about a book"""
         author = get_object_or_404(models.Author, id=author_id)
         data = {"author": author, "form": forms.AuthorForm(instance=author)}
-        return TemplateResponse(request, "edit_author.html", data)
+        return TemplateResponse(request, "author/edit_author.html", data)
 
     def post(self, request, author_id):
         """edit a author cool"""
@@ -52,7 +52,7 @@ def post(self, request, author_id):
         form = forms.AuthorForm(request.POST, request.FILES, instance=author)
         if not form.is_valid():
             data = {"author": author, "form": form}
-            return TemplateResponse(request, "edit_author.html", data)
+            return TemplateResponse(request, "author/edit_author.html", data)
         author = form.save()
 
         return redirect("/author/%s" % author.id)


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Reduce detail level of timestamp on posts
**Is your feature request related to a problem? Please describe.**
I think the time when a post was posted is a tad too detailed. For posts in the last 24h, it changes every time you refresh.
![image](https://user-images.githubusercontent.com/66644064/116756620-b355b480-aa0c-11eb-98de-e77ec1c4b2f2.png)

**Describe the solution you'd like**
I think the firstmost unit would be enough.

Also, after a few days (I suggest 3), the date (Apr 28) rather than "2 weeks(, 4 days in the current version)" seems a bit more helpful. After 1 year, the date could be shown in "Apr 2021",

This is subjective of course, but imho Bookwyrm is a platform where the "when" doesn't really matter (in comparison to e.g. Mastodon where many are posting news and other stuff where the temporal context is more important). 

**Describe alternatives you've considered**
Hovering over the time could show the exact time as a tooltip. I think of this rather as an addition than an alternative and think both would complement each other.


Discussion:
super agree! I originally wrote an ultra-concise version of this based on Mastodon (which uses "23s" "17m" "3h" "5d" "Apr 12"), but I didn't think about internationalization at the time, so the quick fix was to sub in this built-in and already translated filter.

It would be very possible to update that old filter or write a new one that is translated, in whatever format makes the most sense.

Resolving patch:
diff --git a/bookwyrm/templatetags/status_display.py b/bookwyrm/templatetags/status_display.py
--- a/bookwyrm/templatetags/status_display.py
+++ b/bookwyrm/templatetags/status_display.py
@@ -1,6 +1,8 @@
 """ template filters """
+from dateutil.relativedelta import relativedelta
 from django import template
-
+from django.contrib.humanize.templatetags.humanize import naturaltime, naturalday
+from django.utils import timezone
 from bookwyrm import models
 from bookwyrm.templatetags.utilities import get_user_identifier
 
@@ -41,3 +43,17 @@ def get_parent(status):
 def get_boosted(boost):
     """load a boosted status. have to do this or it won't get foreign keys"""
     return models.Status.objects.select_subclasses().get(id=boost.boosted_status.id)
+
+
+@register.filter(name="published_date")
+def get_published_date(date):
+    """less verbose combo of humanize filters"""
+    if not date:
+        return ""
+    now = timezone.now()
+    delta = relativedelta(now, date)
+    if delta.years:
+        return naturalday(date)
+    if delta.days:
+        return naturalday(date, "M j")
+    return naturaltime(date)


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Pending import csv lines displayed under "Successful" title until tried
Importing a CSV into Bookwyrm shows titles being "successfully imported" but they do not show up in the library.

Here's screenshots of the import results, neither the successful nor the failed imports seem to show up:
![](https://i.imgur.com/7NYKkMk.png)
![](https://i.imgur.com/4GCNCUd.png)


[Attached is the file which I attempted to import.](https://github.com/bookwyrm-social/bookwyrm/files/6523421/Tomat0.s.Library.csv)




Discussion:
Looking further, it seems as if the successfully imported books have been changed to failed imports. The issue in that case might be the site incorrectly displaying certain books as imported before the import is completed.

Resolving patch:
diff --git a/bookwyrm/views/import_data.py b/bookwyrm/views/import_data.py
--- a/bookwyrm/views/import_data.py
+++ b/bookwyrm/views/import_data.py
@@ -78,13 +78,15 @@ class ImportStatus(View):
 
     def get(self, request, job_id):
         """status of an import job"""
-        job = models.ImportJob.objects.get(id=job_id)
+        job = get_object_or_404(models.ImportJob, id=job_id)
         if job.user != request.user:
             raise PermissionDenied
+
         try:
             task = app.AsyncResult(job.task_id)
         except ValueError:
             task = None
+
         items = job.items.order_by("index").all()
         failed_items = [i for i in items if i.fail_reason]
         items = [i for i in items if not i.fail_reason]


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Deleted review is still counted
**Describe the bug**
I wrote a review, but associated it with [the wrong book](https://bookwyrm.social/book/134512). I deleted the review. Under the book, it shows that there are 0 total reviews and 1 review by me.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a review
2. Delete the review
3. Look at book page

**Expected behavior**
I expected that there are 0 reviews by me.

**Screenshots**

![screenshot_2021-07-05T22:24:57](https://user-images.githubusercontent.com/3681516/124515542-0454a100-dde0-11eb-9ee0-08f304b69cdd.png)

**Instance**
bookwyrm.social

---

**Desktop (please complete the following information):**
    - OS: Gentoo Linux
    - Browser: Firefox
    - Version: 78.11.0esr


Discussion:

Resolving patch:
diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py
--- a/bookwyrm/views/books.py
+++ b/bookwyrm/views/books.py
@@ -59,7 +59,7 @@ def get(self, request, book_id, user_statuses=False):
                 queryset = book.comment_set
             else:
                 queryset = book.quotation_set
-            queryset = queryset.filter(user=request.user)
+            queryset = queryset.filter(user=request.user, deleted=False)
         else:
             queryset = reviews.exclude(Q(content__isnull=True) | Q(content=""))
         queryset = queryset.select_related("user")
@@ -102,10 +102,11 @@ def get(self, request, book_id, user_statuses=False):
                 book__parent_work=book.parent_work,
             ).select_related("shelf", "book")
 
+            filters = {"user": request.user, "deleted": False}
             data["user_statuses"] = {
-                "review_count": book.review_set.filter(user=request.user).count(),
-                "comment_count": book.comment_set.filter(user=request.user).count(),
-                "quotation_count": book.quotation_set.filter(user=request.user).count(),
+                "review_count": book.review_set.filter(**filters).count(),
+                "comment_count": book.comment_set.filter(**filters).count(),
+                "quotation_count": book.quotation_set.filter(**filters).count(),
             }
 
         return TemplateResponse(request, "book/book.html", data)


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
full links not recognized
**Describe the bug**
Only the first part of a link with a /@ in it is being linked so https://mastodon.social/@username only auto links https://mastodon.social and strips '@username' from being a link

**To Reproduce**
here is an example https://bookwyrm.social/user/wakest/comment/30867

**Expected behavior**
When a link is in a comment, the whole link should be turned into a link not just part of it

**Screenshots**
<img width="858" alt="image" src="https://user-images.githubusercontent.com/7890201/124171841-ae45cd80-da6e-11eb-9071-a74596df184a.png">

**Instance**
https://bookwyrm.social


Discussion:
here is another link that is broken by the # symbol https://bookwyrm.social/user/wakest/comment/31183

Resolving patch:
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -150,7 +150,7 @@ def find_mentions(content):
 def format_links(content):
     """detect and format links"""
     return re.sub(
-        r'([^(href=")]|^|\()(https?:\/\/(%s([\w\.\-_\/+&\?=:;,])*))' % regex.DOMAIN,
+        r'([^(href=")]|^|\()(https?:\/\/(%s([\w\.\-_\/+&\?=:;,@#])*))' % regex.DOMAIN,
         r'\g<1><a href="\g<2>">\g<3></a>',
         content,
     )


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Error 404 when trying to edit book
**Describe the bug**
When I'm on a book page and look at “Your Reviews”, and then try to edit the book, it says “Not Found”.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to a book page of a book you have reviewed
2. Click on “Your reviews”
3. Click on “Edit Book”
4. See error

**Instance**
bookwyrm.social

**Additional context**
The URL it tries to reach is `https://bookwyrm.social/book/<ID>/<ID>/edit`, but it should be `https://bookwyrm.social/book/<ID>/edit`.


Discussion:

Resolving patch:
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -295,7 +295,7 @@
         views.Book.as_view(),
         name="book-user-statuses",
     ),
-    re_path(r"%s/edit/?$" % BOOK_PATH, views.EditBook.as_view()),
+    re_path(r"%s/edit/?$" % BOOK_PATH, views.EditBook.as_view(), name="edit-book"),
     re_path(r"%s/confirm/?$" % BOOK_PATH, views.ConfirmEditBook.as_view()),
     re_path(r"^create-book/?$", views.EditBook.as_view(), name="create-book"),
     re_path(r"^create-book/confirm?$", views.ConfirmEditBook.as_view()),


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Failing to set remote servers
When a remote user is added to the database, a task spins off to configure the information about the user's server. The task seems to be routinely hitting a race condition (?) in which the user ID it received is not available when it tried to look the user up in the database. The ID is correct and I have been able to look the users up successfully later, but at the time the task runs, the ID appears not to be set.

The function lives here: https://github.com/mouse-reeve/bookwyrm/blob/main/bookwyrm/models/user.py#L349, the error occurs on line 351



Discussion:

Resolving patch:
diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py
--- a/bookwyrm/models/user.py
+++ b/bookwyrm/models/user.py
@@ -7,7 +7,7 @@
 from django.contrib.postgres.fields import CICharField
 from django.core.validators import MinValueValidator
 from django.dispatch import receiver
-from django.db import models
+from django.db import models, transaction
 from django.utils import timezone
 from model_utils import FieldTracker
 import pytz
@@ -253,7 +253,7 @@ def save(self, *args, **kwargs):
         # this is a new remote user, we need to set their remote server field
         if not self.local:
             super().save(*args, **kwargs)
-            set_remote_server.delay(self.id)
+            transaction.on_commit(lambda: set_remote_server.delay(self.id))
             return
 
         # populate fields for local users


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Cannot make other users admin on the website
**Describe the bug**
For the moment, there is no way to promote an user to be an admin. One has to do it in the "./bw-dev shell"

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Admin' and then the page of the user you want to promote
2. Promote the user and save
3. The "promoted user" logins in
4. Nope, not promoted

**Expected behavior**
The logged in promoted user should see the admin panel.



Discussion:

Resolving patch:
diff --git a/bookwyrm/views/user_admin.py b/bookwyrm/views/user_admin.py
--- a/bookwyrm/views/user_admin.py
+++ b/bookwyrm/views/user_admin.py
@@ -13,7 +13,7 @@
 # pylint: disable= no-self-use
 @method_decorator(login_required, name="dispatch")
 @method_decorator(
-    permission_required("bookwyrm.moderate_users", raise_exception=True),
+    permission_required("bookwyrm.moderate_user", raise_exception=True),
     name="dispatch",
 )
 class UserAdminList(View):


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Import from Goodreads doesn't work correctly
**Describe the bug**

Import  from goodreads csv imports only first line of csv and stops with 'success' status. If user tries to reimport same csv again importer takes the same first imported line yet again. 

Broken import examples https://bookwyrm.social/import/775 https://bookwyrm.social/import/776

**Expected behavior**
Importer correctly imports all lines of csv or returns error message to user


Discussion:
How frustrating! Would you be able to upload the csv here? that way I can test against it locally.
@RedwanFox I think I figured out the issue for you - it seems like you may have hit a database validation constraint around read dates. I can fix it shortly

@Raineer I need to clarify this in the ui! There are two ways to export data from GoodReads -- there's a full user data download, which is what you did, and there's a csv export, which is what you need to do the import. You can download the csv here: https://www.goodreads.com/review/import and it should only take a few minutes. Thanks for raising - I know you're not the only one who has ended up with the wrong type of export.
@mouse-reeve I had deleted my comment because I figured it out and felt dumb... but yes this was the exact issue. Once I exported from the right section, the import worked correctly. Thank you greatly for all the hard work.
Not dumb at all! It's really non-obvious and I think a little info on the import page would help a lot 
[goodreads_library_export.csv](https://github.com/bookwyrm-social/bookwyrm/files/7123574/goodreads_library_export.csv)

@mouse-reeve  thanks for fast response. Here is my csv. Even though you have found source of problem, I think this data can be used in test suites. 

Resolving patch:
diff --git a/bookwyrm/views/import_data.py b/bookwyrm/views/import_data.py
--- a/bookwyrm/views/import_data.py
+++ b/bookwyrm/views/import_data.py
@@ -28,7 +28,7 @@ def get(self, request):
         """load import page"""
         return TemplateResponse(
             request,
-            "import.html",
+            "import/import.html",
             {
                 "import_form": forms.ImportForm(),
                 "jobs": models.ImportJob.objects.filter(user=request.user).order_by(
@@ -94,7 +94,7 @@ def get(self, request, job_id):
         items = [i for i in items if not i.fail_reason]
         return TemplateResponse(
             request,
-            "import_status.html",
+            "import/import_status.html",
             {"job": job, "items": items, "failed_items": failed_items, "task": task},
         )
 


Test patch: