fixed link creation and updated model
This commit is contained in:
parent
2e2144a9e3
commit
8b6f7bd7cb
@ -18,13 +18,13 @@ class EmojiWidget(forms.TextInput):
|
||||
class EditRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords', 'path', 'storage', 'file_uid')
|
||||
fields = ('name', 'category', 'keywords', 'file_path', 'storage', 'file_uid')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
'path': _('Path'),
|
||||
'file_path': _('Path'),
|
||||
'file_uid': _('Storage UID'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
@ -72,13 +72,13 @@ class BatchEditForm(forms.Form):
|
||||
class ImportRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords', 'path', 'file_uid')
|
||||
fields = ('name', 'category', 'keywords', 'file_path', 'file_uid')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
'path': _('Path'),
|
||||
'file_path': _('Path'),
|
||||
'file_uid': _('File ID'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
@ -31,9 +31,9 @@ def import_all(monitor):
|
||||
import_count = 0
|
||||
for recipe in recipes['entries']: # TODO check if has_more is set and import that as well
|
||||
path = recipe['path_lower']
|
||||
if not Recipe.objects.filter(path=path).exists() and not RecipeImport.objects.filter(path=path).exists():
|
||||
if not Recipe.objects.filter(file_path=path).exists() and not RecipeImport.objects.filter(file_path=path).exists():
|
||||
name = os.path.splitext(recipe['name'])[0]
|
||||
new_recipe = RecipeImport(name=name, path=path, storage=monitor.storage, file_uid=recipe['id'])
|
||||
new_recipe = RecipeImport(name=name, file_path=path, storage=monitor.storage, file_uid=recipe['id'])
|
||||
new_recipe.save()
|
||||
import_count += 1
|
||||
|
||||
@ -46,16 +46,16 @@ def import_all(monitor):
|
||||
return True
|
||||
|
||||
|
||||
def get_share_link(recipe_path):
|
||||
url = "https://api.dropboxapi.com/2/sharing/create_shared_link"
|
||||
def get_share_link(recipe):
|
||||
url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"
|
||||
|
||||
headers = {
|
||||
"Authorization": "Bearer " + settings.DROPBOX_API_KEY,
|
||||
"Authorization": "Bearer " + recipe.storage.token,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
data = {
|
||||
"path": recipe_path
|
||||
"path": recipe.file_uid
|
||||
}
|
||||
|
||||
r = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Generated by Django 2.0.5 on 2018-06-06 20:53
|
||||
# Generated by Django 2.0.5 on 2018-06-06 21:31
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
@ -41,8 +41,8 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128)),
|
||||
('path', models.CharField(default='', max_length=512)),
|
||||
('storage_uid', models.CharField(default='', max_length=256)),
|
||||
('file_uid', models.CharField(default='', max_length=256)),
|
||||
('file_path', models.CharField(default='', max_length=512)),
|
||||
('link', models.CharField(default='', max_length=512)),
|
||||
('created_by', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
@ -56,8 +56,8 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128)),
|
||||
('storage_uid', models.CharField(default='', max_length=256)),
|
||||
('path', models.CharField(default='', max_length=512)),
|
||||
('file_uid', models.CharField(default='', max_length=256)),
|
||||
('file_path', models.CharField(default='', max_length=512)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
],
|
||||
),
|
||||
|
@ -1,23 +0,0 @@
|
||||
# Generated by Django 2.0.5 on 2018-06-06 21:00
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='recipe',
|
||||
old_name='storage_uid',
|
||||
new_name='file_uid',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='recipeimport',
|
||||
old_name='storage_uid',
|
||||
new_name='file_uid',
|
||||
),
|
||||
]
|
@ -60,9 +60,9 @@ class Category(models.Model):
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
path = models.CharField(max_length=512, default="")
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||
file_uid = models.CharField(max_length=256, default="")
|
||||
file_path = models.CharField(max_length=512, default="")
|
||||
link = models.CharField(max_length=512, default="")
|
||||
category = models.ForeignKey(Category, blank=True, on_delete=models.SET_NULL, null=True)
|
||||
keywords = models.ManyToManyField(Keyword, blank=True)
|
||||
@ -82,7 +82,7 @@ class RecipeImport(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||
file_uid = models.CharField(max_length=256, default="")
|
||||
path = models.CharField(max_length=512, default="")
|
||||
file_path = models.CharField(max_length=512, default="")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -78,7 +78,7 @@ class SyncTable(tables.Table):
|
||||
class Meta:
|
||||
model = Sync
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'path', 'storage', 'last_checked')
|
||||
fields = ('id', 'file_path', 'storage', 'last_checked')
|
||||
|
||||
|
||||
class RecipeImportTable(tables.Table):
|
||||
@ -88,4 +88,4 @@ class RecipeImportTable(tables.Table):
|
||||
class Meta:
|
||||
model = RecipeImport
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'name', 'path')
|
||||
fields = ('id', 'name', 'file_path')
|
||||
|
@ -14,7 +14,7 @@ def get_file_link(request, recipe_id):
|
||||
|
||||
if recipe.storage.method == Storage.DROPBOX:
|
||||
if recipe.link == "":
|
||||
response = dropbox.get_share_link(recipe.path) # TODO response validation
|
||||
response = dropbox.get_share_link(recipe) # TODO response validation
|
||||
recipe.link = response['url']
|
||||
recipe.save()
|
||||
|
||||
|
@ -40,7 +40,7 @@ def sync_wait(request):
|
||||
def batch_import(request):
|
||||
imports = RecipeImport.objects.all()
|
||||
for new_recipe in imports:
|
||||
recipe = Recipe(name=new_recipe.name, path=new_recipe.path, storage=new_recipe.storage, file_uid=new_recipe.file_uid)
|
||||
recipe = Recipe(name=new_recipe.name, file_path=new_recipe.path, storage=new_recipe.storage, file_uid=new_recipe.file_uid)
|
||||
recipe.save()
|
||||
new_recipe.delete()
|
||||
|
||||
|
@ -67,7 +67,7 @@ def create_new_recipe(request, import_id):
|
||||
recipe = Recipe()
|
||||
recipe.storage = new_recipe.storage
|
||||
recipe.name = form.cleaned_data['name']
|
||||
recipe.path = form.cleaned_data['path']
|
||||
recipe.file_path = form.cleaned_data['file_path']
|
||||
recipe.file_uid = form.cleaned_data['file_uid']
|
||||
recipe.category = form.cleaned_data['category']
|
||||
|
||||
@ -83,6 +83,6 @@ def create_new_recipe(request, import_id):
|
||||
messages.add_message(request, messages.ERROR, _('There was an error importing this recipe!'))
|
||||
else:
|
||||
new_recipe = RecipeImport.objects.get(id=import_id)
|
||||
form = ImportRecipeForm(initial={'path': new_recipe.path, 'name': new_recipe.name, 'file_uid': new_recipe.file_uid})
|
||||
form = ImportRecipeForm(initial={'file_path': new_recipe.file_path, 'name': new_recipe.name, 'file_uid': new_recipe.file_uid})
|
||||
|
||||
return render(request, 'forms/edit_import_recipe.html', {'form': form})
|
||||
|
Loading…
Reference in New Issue
Block a user