diff --git a/cookbook/migrations/0117_bookmarkletimport.py b/cookbook/migrations/0118_auto_20210329_0605.py similarity index 79% rename from cookbook/migrations/0117_bookmarkletimport.py rename to cookbook/migrations/0118_auto_20210329_0605.py index 7b023017..a34dd673 100644 --- a/cookbook/migrations/0117_bookmarkletimport.py +++ b/cookbook/migrations/0118_auto_20210329_0605.py @@ -1,4 +1,4 @@ -# Generated by Django 3.1.7 on 2021-03-26 17:42 +# Generated by Django 3.1.7 on 2021-03-29 11:05 import cookbook.models from django.conf import settings @@ -10,10 +10,15 @@ class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('cookbook', '0116_auto_20210319_0012'), + ('cookbook', '0117_space_max_recipes'), ] operations = [ + migrations.AlterField( + model_name='userpreference', + name='use_fractions', + field=models.BooleanField(default=True), + ), migrations.CreateModel( name='BookmarkletImport', fields=[ diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 49179f34..28625b18 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -474,10 +474,13 @@ class ImportLogSerializer(serializers.ModelSerializer): read_only_fields = ('created_by',) +# CORS, REST and Scopes aren't currently working +# Scopes are evaluating before REST has authenticated the user assiging a None space +# I've made the change below to fix the bookmarklet, other serializers likely need a similar/better fix class BookmarkletImportSerializer(serializers.ModelSerializer): def create(self, validated_data): validated_data['created_by'] = self.context['request'].user - validated_data['space'] = self.context['request'].space + validated_data['space'] = self.context['request'].user.userpreference.space return super().create(validated_data) class Meta: diff --git a/cookbook/static/js/bookmarklet.js b/cookbook/static/js/bookmarklet.js index f8a94725..52a90112 100644 --- a/cookbook/static/js/bookmarklet.js +++ b/cookbook/static/js/bookmarklet.js @@ -37,6 +37,7 @@ if (xhr.readyState == 4 && xhr.status == 201) { // parse JSON data console.log(JSON.parse(xhr.response)); + window.open(redirect.concat('?id=', JSON.parse(xhr.response).id) ) } else { console.error('Error!'); } diff --git a/cookbook/views/data.py b/cookbook/views/data.py index 3092a831..84223a6b 100644 --- a/cookbook/views/data.py +++ b/cookbook/views/data.py @@ -94,9 +94,7 @@ def batch_edit(request): msg = ngettext( 'Batch edit done. %(count)d recipe was updated.', 'Batch edit done. %(count)d Recipes where updated.', - count) % { - 'count': count, - } + count) % {'count': count, } messages.add_message(request, messages.SUCCESS, msg) return redirect('data_batch_edit') @@ -191,7 +189,7 @@ def import_url(request): return HttpResponse(reverse('view_recipe', args=[recipe.pk])) - return render(request, 'url_import.html', {'recipe_json': 'undefined', 'recipe_tree': 'undefined', 'recipe_html': 'undefined', 'preview': 'false'}) + return render(request, 'url_import.html', {}) class Object(object):