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 EditRecipeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'category', 'keywords', 'path', 'storage', 'file_uid')
|
fields = ('name', 'category', 'keywords', 'file_path', 'storage', 'file_uid')
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
'category': _('Category'),
|
'category': _('Category'),
|
||||||
'keywords': _('Keywords'),
|
'keywords': _('Keywords'),
|
||||||
'path': _('Path'),
|
'file_path': _('Path'),
|
||||||
'file_uid': _('Storage UID'),
|
'file_uid': _('Storage UID'),
|
||||||
}
|
}
|
||||||
widgets = {'keywords': MultiSelectWidget}
|
widgets = {'keywords': MultiSelectWidget}
|
||||||
@ -72,13 +72,13 @@ class BatchEditForm(forms.Form):
|
|||||||
class ImportRecipeForm(forms.ModelForm):
|
class ImportRecipeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'category', 'keywords', 'path', 'file_uid')
|
fields = ('name', 'category', 'keywords', 'file_path', 'file_uid')
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
'category': _('Category'),
|
'category': _('Category'),
|
||||||
'keywords': _('Keywords'),
|
'keywords': _('Keywords'),
|
||||||
'path': _('Path'),
|
'file_path': _('Path'),
|
||||||
'file_uid': _('File ID'),
|
'file_uid': _('File ID'),
|
||||||
}
|
}
|
||||||
widgets = {'keywords': MultiSelectWidget}
|
widgets = {'keywords': MultiSelectWidget}
|
||||||
|
@ -31,9 +31,9 @@ def import_all(monitor):
|
|||||||
import_count = 0
|
import_count = 0
|
||||||
for recipe in recipes['entries']: # TODO check if has_more is set and import that as well
|
for recipe in recipes['entries']: # TODO check if has_more is set and import that as well
|
||||||
path = recipe['path_lower']
|
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]
|
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()
|
new_recipe.save()
|
||||||
import_count += 1
|
import_count += 1
|
||||||
|
|
||||||
@ -46,16 +46,16 @@ def import_all(monitor):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_share_link(recipe_path):
|
def get_share_link(recipe):
|
||||||
url = "https://api.dropboxapi.com/2/sharing/create_shared_link"
|
url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": "Bearer " + settings.DROPBOX_API_KEY,
|
"Authorization": "Bearer " + recipe.storage.token,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"path": recipe_path
|
"path": recipe.file_uid
|
||||||
}
|
}
|
||||||
|
|
||||||
r = requests.post(url, headers=headers, data=json.dumps(data))
|
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
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
@ -41,8 +41,8 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(max_length=128)),
|
('name', models.CharField(max_length=128)),
|
||||||
('path', models.CharField(default='', max_length=512)),
|
('file_uid', models.CharField(default='', max_length=256)),
|
||||||
('storage_uid', models.CharField(default='', max_length=256)),
|
('file_path', models.CharField(default='', max_length=512)),
|
||||||
('link', models.CharField(default='', max_length=512)),
|
('link', models.CharField(default='', max_length=512)),
|
||||||
('created_by', models.IntegerField(default=0)),
|
('created_by', models.IntegerField(default=0)),
|
||||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
@ -56,8 +56,8 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(max_length=128)),
|
('name', models.CharField(max_length=128)),
|
||||||
('storage_uid', models.CharField(default='', max_length=256)),
|
('file_uid', models.CharField(default='', max_length=256)),
|
||||||
('path', models.CharField(default='', max_length=512)),
|
('file_path', models.CharField(default='', max_length=512)),
|
||||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
('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):
|
class Recipe(models.Model):
|
||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
path = models.CharField(max_length=512, default="")
|
|
||||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||||
file_uid = models.CharField(max_length=256, default="")
|
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, default="")
|
||||||
category = models.ForeignKey(Category, blank=True, on_delete=models.SET_NULL, null=True)
|
category = models.ForeignKey(Category, blank=True, on_delete=models.SET_NULL, null=True)
|
||||||
keywords = models.ManyToManyField(Keyword, blank=True)
|
keywords = models.ManyToManyField(Keyword, blank=True)
|
||||||
@ -82,7 +82,7 @@ class RecipeImport(models.Model):
|
|||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||||
file_uid = models.CharField(max_length=256, default="")
|
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)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -78,7 +78,7 @@ class SyncTable(tables.Table):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Sync
|
model = Sync
|
||||||
template_name = 'generic/table_template.html'
|
template_name = 'generic/table_template.html'
|
||||||
fields = ('id', 'path', 'storage', 'last_checked')
|
fields = ('id', 'file_path', 'storage', 'last_checked')
|
||||||
|
|
||||||
|
|
||||||
class RecipeImportTable(tables.Table):
|
class RecipeImportTable(tables.Table):
|
||||||
@ -88,4 +88,4 @@ class RecipeImportTable(tables.Table):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = RecipeImport
|
model = RecipeImport
|
||||||
template_name = 'generic/table_template.html'
|
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.storage.method == Storage.DROPBOX:
|
||||||
if recipe.link == "":
|
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.link = response['url']
|
||||||
recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def sync_wait(request):
|
|||||||
def batch_import(request):
|
def batch_import(request):
|
||||||
imports = RecipeImport.objects.all()
|
imports = RecipeImport.objects.all()
|
||||||
for new_recipe in imports:
|
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()
|
recipe.save()
|
||||||
new_recipe.delete()
|
new_recipe.delete()
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ def create_new_recipe(request, import_id):
|
|||||||
recipe = Recipe()
|
recipe = Recipe()
|
||||||
recipe.storage = new_recipe.storage
|
recipe.storage = new_recipe.storage
|
||||||
recipe.name = form.cleaned_data['name']
|
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.file_uid = form.cleaned_data['file_uid']
|
||||||
recipe.category = form.cleaned_data['category']
|
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!'))
|
messages.add_message(request, messages.ERROR, _('There was an error importing this recipe!'))
|
||||||
else:
|
else:
|
||||||
new_recipe = RecipeImport.objects.get(id=import_id)
|
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})
|
return render(request, 'forms/edit_import_recipe.html', {'form': form})
|
||||||
|
Loading…
Reference in New Issue
Block a user