diff --git a/cookbook/migrations/0026_auto_20200219_1605.py b/cookbook/migrations/0026_auto_20200219_1605.py new file mode 100644 index 000000000..70aff6a66 --- /dev/null +++ b/cookbook/migrations/0026_auto_20200219_1605.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.2 on 2020-02-19 15:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0025_userpreference_nav_color'), + ] + + operations = [ + migrations.AddField( + model_name='recipe', + name='cors_link', + field=models.CharField(blank=True, max_length=1024, null=True), + ), + migrations.AlterField( + model_name='recipe', + name='link', + field=models.CharField(blank=True, max_length=512, null=True), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index d40da63ec..cb3a6d17d 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -84,7 +84,8 @@ class Recipe(models.Model): storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True) file_uid = models.CharField(max_length=256, default="") file_path = models.CharField(max_length=512, default="") - link = models.CharField(max_length=512, default="") + link = models.CharField(max_length=512, null=True, blank=True) + cors_link = models.CharField(max_length=1024, null=True, blank=True) keywords = models.ManyToManyField(Keyword, blank=True) working_time = models.IntegerField(default=0) waiting_time = models.IntegerField(default=0) diff --git a/cookbook/provider/dropbox.py b/cookbook/provider/dropbox.py index 8d31b8a5b..c6641202e 100644 --- a/cookbook/provider/dropbox.py +++ b/cookbook/provider/dropbox.py @@ -88,6 +88,16 @@ class Dropbox(Provider): response = Dropbox.create_share_link(recipe) return response['url'] + @staticmethod + def get_cors_link(recipe): + if not recipe.link: + recipe.link = Dropbox.get_share_link(recipe) + recipe.save() + + recipe.cors_link = recipe.link.replace('www.dropbox.', 'dl.dropboxusercontent.') + + return recipe.cors_link + @staticmethod def rename_file(recipe, new_name): url = "https://api.dropboxapi.com/2/files/move_v2" diff --git a/cookbook/provider/provider.py b/cookbook/provider/provider.py index cecb7728b..ad84430ec 100644 --- a/cookbook/provider/provider.py +++ b/cookbook/provider/provider.py @@ -11,10 +11,14 @@ class Provider: def get_share_link(recipe): raise Exception('Method not implemented in storage provider') + @staticmethod + def get_cors_link(recipe): + raise Exception('Method not implemented in storage provider') + @staticmethod def rename_file(recipe, new_name): raise Exception('Method not implemented in storage provider') @staticmethod - def delete_file(recipe, new_name): + def delete_file(recipe): raise Exception('Method not implemented in storage provider') diff --git a/cookbook/tables.py b/cookbook/tables.py index aba98fec3..0282bf8bd 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -8,8 +8,7 @@ from .models import * class RecipeTable(tables.Table): id = tables.LinkColumn('edit_recipe', args=[A('id')]) - name = tables.TemplateColumn( - "{{record.name}}") + name = tables.LinkColumn('view_recipe', args=[A('id')]) all_tags = tables.Column( attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}}) diff --git a/cookbook/templates/books.html b/cookbook/templates/books.html index c22c41870..b1186c68c 100644 --- a/cookbook/templates/books.html +++ b/cookbook/templates/books.html @@ -41,7 +41,7 @@ {% for r in b.recipes %}