diff --git a/cookbook/fixtures/default_category.json b/cookbook/fixtures/default_category.json
new file mode 100644
index 000000000..69cf367be
--- /dev/null
+++ b/cookbook/fixtures/default_category.json
@@ -0,0 +1,13 @@
+[
+ {
+ "model": "cookbook.category",
+ "pk": 1,
+ "fields": {
+ "name": "-",
+ "description": "Default Category",
+ "created_by": 0,
+ "created_at": "2018-05-06T21:21:08.860Z",
+ "updated_at": "2018-05-06T21:21:08.860Z"
+ }
+ }
+]
\ No newline at end of file
diff --git a/cookbook/helper/dropbox.py b/cookbook/helper/dropbox.py
index 1ddb4f8e5..c8aed0820 100644
--- a/cookbook/helper/dropbox.py
+++ b/cookbook/helper/dropbox.py
@@ -5,11 +5,11 @@ import requests
import json
from django.conf import settings
-from cookbook.models import Recipe, Monitor, NewRecipe, ImportLog
+from cookbook.models import Recipe, Sync, RecipeImport, SyncLog
def sync_all():
- monitors = Monitor.objects.all()
+ monitors = Sync.objects.all()
for monitor in monitors:
ret = import_all(monitor)
@@ -35,20 +35,20 @@ def import_all(monitor):
try:
recipes = r.json()
except ValueError:
- log_entry = ImportLog(status='ERROR', msg=str(r), monitor=monitor)
+ log_entry = SyncLog(status='ERROR', msg=str(r), monitor=monitor)
log_entry.save()
return r
import_count = 0
for recipe in recipes['entries']:
path = recipe['path_lower']
- if not Recipe.objects.filter(path=path).exists() and not NewRecipe.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]
- new_recipe = NewRecipe(name=name, path=path)
+ new_recipe = RecipeImport(name=name, path=path)
new_recipe.save()
import_count += 1
- log_entry = ImportLog(status='SUCCESS', msg='Imported ' + str(import_count) + ' recipes', monitor=monitor)
+ log_entry = SyncLog(status='SUCCESS', msg='Imported ' + str(import_count) + ' recipes', monitor=monitor)
log_entry.save()
monitor.last_checked = datetime.now()
diff --git a/cookbook/models.py b/cookbook/models.py
index d8743a07c..7f369fcf6 100644
--- a/cookbook/models.py
+++ b/cookbook/models.py
@@ -41,21 +41,21 @@ class Recipe(models.Model):
return ', '.join([x.name for x in self.keywords.all()])
-class NewRecipe(models.Model):
+class RecipeImport(models.Model):
name = models.CharField(max_length=128)
path = models.CharField(max_length=512, default="")
created_at = models.DateTimeField(auto_now_add=True)
-class Monitor(models.Model):
+class Sync(models.Model):
path = models.CharField(max_length=512, default="")
last_checked = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
-class ImportLog(models.Model):
- monitor = models.ForeignKey(Monitor, on_delete=models.CASCADE)
+class SyncLog(models.Model):
+ monitor = models.ForeignKey(Sync, on_delete=models.CASCADE)
status = models.CharField(max_length=32)
msg = models.TextField(default="")
created_at = models.DateTimeField(auto_now_add=True)
diff --git a/cookbook/tables.py b/cookbook/tables.py
index 6f30fde23..03cf454f2 100644
--- a/cookbook/tables.py
+++ b/cookbook/tables.py
@@ -45,7 +45,7 @@ class ImportLogTable(tables.Table):
monitor_id = tables.LinkColumn('edit_monitor', args=[A('monitor_id')])
class Meta:
- model = ImportLog
+ model = SyncLog
template_name = 'generic/table_template.html'
fields = ('status', 'msg', 'monitor_id', 'created_at')
@@ -55,7 +55,7 @@ class MonitoredPathTable(tables.Table):
delete = tables.TemplateColumn("" + _('Delete') + "")
class Meta:
- model = Monitor
+ model = Sync
template_name = 'generic/table_template.html'
fields = ('id', 'path', 'last_checked')
@@ -65,6 +65,6 @@ class ImportTable(tables.Table):
delete = tables.TemplateColumn("" + _('Delete') + "")
class Meta:
- model = NewRecipe
+ model = RecipeImport
template_name = 'generic/table_template.html'
fields = ('id', 'name', 'path')
diff --git a/cookbook/urls.py b/cookbook/urls.py
index 373f1427b..bf1144657 100644
--- a/cookbook/urls.py
+++ b/cookbook/urls.py
@@ -8,10 +8,10 @@ urlpatterns = [
path('', views.index, name='index'),
path('test', views.test, name='test'),
- path('new/recipe', new.RecipeCreate.as_view(), name='new_recipe'),
+ path('new/recipe/', new.RecipeCreate.as_view(), name='new_recipe'),
path('new/recipe_import//', new.create_new_recipe, name='new_recipe_import'),
- path('new/category', new.CategoryCreate.as_view(), name='new_category'),
- path('new/keyword', new.KeywordCreate.as_view(), name='new_keyword'),
+ path('new/category/', new.CategoryCreate.as_view(), name='new_category'),
+ path('new/keyword/', new.KeywordCreate.as_view(), name='new_keyword'),
path('list/keyword', lists.keyword, name='list_keyword'),
path('list/category', lists.category, name='list_category'),
diff --git a/cookbook/views/batch.py b/cookbook/views/batch.py
index 107bde066..67fe984e8 100644
--- a/cookbook/views/batch.py
+++ b/cookbook/views/batch.py
@@ -4,8 +4,8 @@ from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django_tables2 import RequestConfig
-from cookbook.forms import MonitorForm, BatchEditForm, NewRecipe
-from cookbook.models import Recipe, Category, Monitor
+from cookbook.forms import MonitorForm, BatchEditForm, RecipeImport
+from cookbook.models import Recipe, Category, Sync
from cookbook.tables import MonitoredPathTable
@@ -14,7 +14,7 @@ def batch_monitor(request):
if request.method == "POST":
form = MonitorForm(request.POST)
if form.is_valid():
- new_path = Monitor()
+ new_path = Sync()
new_path.path = form.cleaned_data['path']
new_path.last_checked = datetime.now()
new_path.save()
@@ -22,7 +22,7 @@ def batch_monitor(request):
else:
form = MonitorForm()
- monitored_paths = MonitoredPathTable(Monitor.objects.all())
+ monitored_paths = MonitoredPathTable(Sync.objects.all())
RequestConfig(request, paginate={'per_page': 25}).configure(monitored_paths)
return render(request, 'batch/monitor.html', {'form': form, 'monitored_paths': monitored_paths})
@@ -31,7 +31,7 @@ def batch_monitor(request):
@login_required
def batch_import_all(request):
if request.method == "POST":
- imports = NewRecipe.objects.all()
+ imports = RecipeImport.objects.all()
for new_recipe in imports:
recipe = Recipe(name=new_recipe.name, path=new_recipe.path, category=(Category.objects.get(id=0)))
recipe.save()
diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py
index 580ff6ed6..6daa0a8ba 100644
--- a/cookbook/views/edit.py
+++ b/cookbook/views/edit.py
@@ -5,12 +5,12 @@ from django.utils.translation import gettext as _
from django.views.generic import UpdateView, DeleteView
from cookbook.forms import EditRecipeForm
-from cookbook.models import Recipe, Category, Monitor, Keyword, NewRecipe
+from cookbook.models import Recipe, Category, Sync, Keyword, RecipeImport
class MonitorUpdate(LoginRequiredMixin, UpdateView):
template_name = "generic\edit_template.html"
- model = Monitor
+ model = Sync
fields = ['path']
def get_success_url(self):
@@ -52,7 +52,7 @@ class KeywordUpdate(LoginRequiredMixin, UpdateView):
class ImportUpdate(LoginRequiredMixin, UpdateView):
template_name = "generic\edit_template.html"
- model = NewRecipe
+ model = RecipeImport
fields = ['name', 'path']
def get_success_url(self):
@@ -100,7 +100,7 @@ class RecipeDelete(LoginRequiredMixin, DeleteView):
class ImportDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
- model = NewRecipe
+ model = RecipeImport
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
@@ -111,7 +111,7 @@ class ImportDelete(LoginRequiredMixin, DeleteView):
class MonitorDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
- model = Monitor
+ model = Sync
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py
index cbfb6e6e7..90995d5a7 100644
--- a/cookbook/views/lists.py
+++ b/cookbook/views/lists.py
@@ -4,7 +4,7 @@ from django.shortcuts import render
from django_tables2 import RequestConfig
from django.utils.translation import gettext as _
-from cookbook.models import Category, Keyword, ImportLog, NewRecipe
+from cookbook.models import Category, Keyword, SyncLog, RecipeImport
from cookbook.tables import CategoryTable, KeywordTable, ImportLogTable, ImportTable
@@ -26,7 +26,7 @@ def keyword(request):
@login_required
def import_log(request):
- table = ImportLogTable(ImportLog.objects.all().order_by(Lower('created_at').desc()))
+ table = ImportLogTable(SyncLog.objects.all().order_by(Lower('created_at').desc()))
RequestConfig(request, paginate={'per_page': 25}).configure(table)
return render(request, 'generic/list_template.html', {'title': _("Import Log"), 'table': table})
@@ -34,7 +34,7 @@ def import_log(request):
@login_required
def new_recipe(request):
- table = ImportTable(NewRecipe.objects.all())
+ table = ImportTable(RecipeImport.objects.all())
RequestConfig(request, paginate={'per_page': 25}).configure(table)
return render(request, 'generic/list_template.html', {'title': _("Import"), 'table': table})
diff --git a/cookbook/views/new.py b/cookbook/views/new.py
index 211e76533..6c1d12be2 100644
--- a/cookbook/views/new.py
+++ b/cookbook/views/new.py
@@ -6,7 +6,7 @@ from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import CreateView
-from cookbook.forms import ImportRecipeForm, NewRecipe
+from cookbook.forms import ImportRecipeForm, RecipeImport
from cookbook.models import Category, Keyword, Recipe
@@ -14,10 +14,7 @@ class RecipeCreate(LoginRequiredMixin, CreateView): # this exists for completen
template_name = "generic\\new_template.html"
model = Recipe
fields = ['name', 'category', 'keywords']
- success_url = reverse_lazy('list_category')
-
- def get_initial(self):
- return {'value1': self.request.user}
+ success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super(RecipeCreate, self).get_context_data(**kwargs)
@@ -63,14 +60,14 @@ def create_new_recipe(request, import_id):
recipe.keywords.set(form.cleaned_data['keywords'])
- NewRecipe.objects.get(id=import_id).delete()
+ RecipeImport.objects.get(id=import_id).delete()
messages.add_message(request, messages.SUCCESS, _('Imported new recipe!'))
return redirect('list_import')
else:
messages.add_message(request, messages.ERROR, _('There was an error importing this recipe!'))
else:
- new_recipe = NewRecipe.objects.get(id=import_id)
+ new_recipe = RecipeImport.objects.get(id=import_id)
form = ImportRecipeForm(initial={'path': new_recipe.path, 'name': new_recipe.name})
return render(request, 'forms/edit_import_recipe.html', {'form': form})