added file id
This commit is contained in:
parent
cb246a33d8
commit
2e2144a9e3
@ -18,13 +18,14 @@ 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')
|
fields = ('name', 'category', 'keywords', 'path', 'storage', 'file_uid')
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
'category': _('Category'),
|
'category': _('Category'),
|
||||||
'keywords': _('Keywords'),
|
'keywords': _('Keywords'),
|
||||||
'path': _('Path'),
|
'path': _('Path'),
|
||||||
|
'file_uid': _('Storage UID'),
|
||||||
}
|
}
|
||||||
widgets = {'keywords': MultiSelectWidget}
|
widgets = {'keywords': MultiSelectWidget}
|
||||||
|
|
||||||
@ -71,12 +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')
|
fields = ('name', 'category', 'keywords', 'path', 'file_uid')
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
'category': _('Category'),
|
'category': _('Category'),
|
||||||
'keywords': _('Keywords'),
|
'keywords': _('Keywords'),
|
||||||
'path': _('Path'),
|
'path': _('Path'),
|
||||||
|
'file_uid': _('File ID'),
|
||||||
}
|
}
|
||||||
widgets = {'keywords': MultiSelectWidget}
|
widgets = {'keywords': MultiSelectWidget}
|
||||||
|
@ -33,7 +33,7 @@ def import_all(monitor):
|
|||||||
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(path=path).exists() and not RecipeImport.objects.filter(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)
|
new_recipe = RecipeImport(name=name, path=path, storage=monitor.storage, file_uid=recipe['id'])
|
||||||
new_recipe.save()
|
new_recipe.save()
|
||||||
import_count += 1
|
import_count += 1
|
||||||
|
|
||||||
|
107
cookbook/migrations/0001_initial.py
Normal file
107
cookbook/migrations/0001_initial.py
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
# Generated by Django 2.0.5 on 2018-06-06 20:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Category',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=64, unique=True)),
|
||||||
|
('icon', models.CharField(blank=True, max_length=1, null=True)),
|
||||||
|
('description', models.TextField(blank=True, default='')),
|
||||||
|
('created_by', models.IntegerField(default=0)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Keyword',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=64, unique=True)),
|
||||||
|
('icon', models.CharField(blank=True, max_length=1, null=True)),
|
||||||
|
('description', models.TextField(blank=True, default='')),
|
||||||
|
('created_by', models.IntegerField(default=0)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Recipe',
|
||||||
|
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)),
|
||||||
|
('link', models.CharField(default='', max_length=512)),
|
||||||
|
('created_by', models.IntegerField(default=0)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cookbook.Category')),
|
||||||
|
('keywords', models.ManyToManyField(blank=True, to='cookbook.Keyword')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RecipeImport',
|
||||||
|
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)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Storage',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=128)),
|
||||||
|
('method', models.CharField(choices=[('DB', 'Dropbox')], default='DB', max_length=128)),
|
||||||
|
('username', models.CharField(blank=True, max_length=128, null=True)),
|
||||||
|
('password', models.CharField(blank=True, max_length=128, null=True)),
|
||||||
|
('token', models.CharField(blank=True, max_length=512, null=True)),
|
||||||
|
('url', models.URLField(blank=True, null=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Sync',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('path', models.CharField(default='', max_length=512)),
|
||||||
|
('last_checked', models.DateTimeField()),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
('storage', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Storage')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SyncLog',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('status', models.CharField(max_length=32)),
|
||||||
|
('msg', models.TextField(default='')),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('sync', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.Sync')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recipeimport',
|
||||||
|
name='storage',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Storage'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recipe',
|
||||||
|
name='storage',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Storage'),
|
||||||
|
),
|
||||||
|
]
|
23
cookbook/migrations/0002_auto_20180606_2300.py
Normal file
23
cookbook/migrations/0002_auto_20180606_2300.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# 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',
|
||||||
|
),
|
||||||
|
]
|
@ -62,6 +62,7 @@ class Recipe(models.Model):
|
|||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
path = models.CharField(max_length=512, default="")
|
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="")
|
||||||
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)
|
||||||
@ -80,6 +81,7 @@ class Recipe(models.Model):
|
|||||||
class RecipeImport(models.Model):
|
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="")
|
||||||
path = models.CharField(max_length=512, default="")
|
path = models.CharField(max_length=512, default="")
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
<a href="{% url 'new_category' %}" ><i class="fal fa-plus-circle"></i></a>
|
<a href="{% url 'new_category' %}" ><i class="fal fa-plus-circle"></i></a>
|
||||||
{% elif table.Meta.model|get_class == 'Keyword' %}
|
{% elif table.Meta.model|get_class == 'Keyword' %}
|
||||||
<a href="{% url 'new_keyword' %}" ><i class="fal fa-plus-circle"></i></a>
|
<a href="{% url 'new_keyword' %}" ><i class="fal fa-plus-circle"></i></a>
|
||||||
|
{% elif table.Meta.model|get_class == 'Storage' %}
|
||||||
|
<a href="{% url 'new_storage' %}" ><i class="fal fa-plus-circle"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -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)
|
recipe = Recipe(name=new_recipe.name, path=new_recipe.path, storage=new_recipe.storage, file_uid=new_recipe.file_uid)
|
||||||
recipe.save()
|
recipe.save()
|
||||||
new_recipe.delete()
|
new_recipe.delete()
|
||||||
|
|
||||||
|
@ -63,9 +63,12 @@ def create_new_recipe(request, import_id):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = ImportRecipeForm(request.POST)
|
form = ImportRecipeForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
new_recipe = RecipeImport.objects.get(id=import_id)
|
||||||
recipe = Recipe()
|
recipe = Recipe()
|
||||||
|
recipe.storage = new_recipe.storage
|
||||||
recipe.name = form.cleaned_data['name']
|
recipe.name = form.cleaned_data['name']
|
||||||
recipe.path = form.cleaned_data['path']
|
recipe.path = form.cleaned_data['path']
|
||||||
|
recipe.file_uid = form.cleaned_data['file_uid']
|
||||||
recipe.category = form.cleaned_data['category']
|
recipe.category = form.cleaned_data['category']
|
||||||
|
|
||||||
recipe.save()
|
recipe.save()
|
||||||
@ -80,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})
|
form = ImportRecipeForm(initial={'path': new_recipe.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