From 8618f208937b1bb3dd762d256064f266597859df Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Sun, 8 Mar 2020 16:26:42 +0000 Subject: [PATCH 1/2] Add default author aliases as empty list. Fixes null constraint trying to rebuilddb. --- .../migrations/0012_auto_20200308_1625.py | 19 +++++++++++++++++++ fedireads/models/book.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 fedireads/migrations/0012_auto_20200308_1625.py diff --git a/fedireads/migrations/0012_auto_20200308_1625.py b/fedireads/migrations/0012_auto_20200308_1625.py new file mode 100644 index 00000000..17071d1c --- /dev/null +++ b/fedireads/migrations/0012_auto_20200308_1625.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.3 on 2020-03-08 16:25 + +from django.db import migrations, models +import fedireads.utils.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('fedireads', '0011_notification'), + ] + + operations = [ + migrations.AlterField( + model_name='author', + name='aliases', + field=fedireads.utils.fields.ArrayField(base_field=models.CharField(max_length=255), blank=True, default=list, size=None), + ), + ] diff --git a/fedireads/models/book.py b/fedireads/models/book.py index 4ca1460e..04451d0d 100644 --- a/fedireads/models/book.py +++ b/fedireads/models/book.py @@ -79,6 +79,6 @@ class Author(FedireadsModel): name = models.CharField(max_length=255) last_name = models.CharField(max_length=255, null=True) first_name = models.CharField(max_length=255, null=True) - aliases = ArrayField(models.CharField(max_length=255), blank=True) + aliases = ArrayField(models.CharField(max_length=255), blank=True, default=list) bio = models.TextField(null=True, blank=True) From c038888f637a236a5f8074dd4cf17c3ca36bc76b Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Sun, 8 Mar 2020 16:39:59 +0000 Subject: [PATCH 2/2] Change url for edit_profile_page. Fixes inaccessible edit form. /user/edit/ resolved to a user called edit first. Also prevents a user accessing another user's edit form. --- fedireads/templates/user.html | 2 +- fedireads/urls.py | 3 +-- fedireads/views.py | 7 ++----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/fedireads/templates/user.html b/fedireads/templates/user.html index 79605dbe..0e5ba6a4 100644 --- a/fedireads/templates/user.html +++ b/fedireads/templates/user.html @@ -16,7 +16,7 @@ {% if is_self %} {% endif %} diff --git a/fedireads/urls.py b/fedireads/urls.py index 4e1c5fee..d962671b 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -41,8 +41,7 @@ urlpatterns = [ re_path(r'^logout/?$', views.user_logout), re_path(r'^notifications/?', views.notifications_page), re_path(r'%s/?$' % user_path, views.user_page), - re_path(r'%s/edit/?$' % user_path, views.edit_profile_page), - re_path(r'^user/edit/?$', views.edit_profile_page), + re_path(r'edit_profile_page/?$', views.edit_profile_page), re_path(r'%s/?$' % status_path, views.status_page), re_path(r'^book/(?P\w+)/?$', views.book_page), re_path(r'^book/(?P\w+)/(?Pfriends|local|federated)?$', views.book_page), diff --git a/fedireads/views.py b/fedireads/views.py index 8899f9a5..17f183fa 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -204,12 +204,9 @@ def status_page(request, username, status_id): @login_required -def edit_profile_page(request, username): +def edit_profile_page(request): ''' profile page for a user ''' - try: - user = models.User.objects.get(localname=username) - except models.User.DoesNotExist: - return HttpResponseNotFound() + user = request.user form = forms.EditUserForm(instance=request.user) data = {