removed categories
This commit is contained in:
parent
0fd19edcc2
commit
b98f87499a
@ -4,7 +4,6 @@ from .models import *
|
||||
|
||||
admin.site.register(Recipe)
|
||||
admin.site.register(Keyword)
|
||||
admin.site.register(Category)
|
||||
|
||||
admin.site.register(Sync)
|
||||
admin.site.register(SyncLog)
|
||||
|
@ -19,15 +19,14 @@ class RecipeFilter(django_filters.FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['name', 'category', 'keywords']
|
||||
fields = ['name', 'keywords']
|
||||
|
||||
|
||||
class QuickRecipeFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(lookup_expr='contains')
|
||||
category = django_filters.CharFilter(lookup_expr='contains')
|
||||
keywords = django_filters.ModelMultipleChoiceFilter(queryset=Keyword.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_keywords')
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['name', 'category', 'keywords']
|
||||
fields = ['name', 'keywords']
|
||||
|
@ -18,11 +18,10 @@ class EmojiWidget(forms.TextInput):
|
||||
class EditRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords', 'file_path', 'storage', 'file_uid')
|
||||
fields = ('name', 'keywords', 'file_path', 'storage', 'file_uid')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
'file_path': _('Path'),
|
||||
'file_uid': _('Storage UID'),
|
||||
@ -30,13 +29,6 @@ class EditRecipeForm(forms.ModelForm):
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
|
||||
class CategoryForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ('name', 'icon', 'description')
|
||||
widgets = {'icon': EmojiWidget}
|
||||
|
||||
|
||||
class KeywordForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Keyword
|
||||
@ -64,7 +56,6 @@ class SyncForm(forms.ModelForm):
|
||||
|
||||
class BatchEditForm(forms.Form):
|
||||
search = forms.CharField(label=_('Search String'))
|
||||
category = forms.ModelChoiceField(queryset=Category.objects.all().order_by('id'), required=False)
|
||||
keywords = forms.ModelMultipleChoiceField(queryset=Keyword.objects.all().order_by('id'), required=False,
|
||||
widget=MultiSelectWidget)
|
||||
|
||||
@ -72,11 +63,10 @@ class BatchEditForm(forms.Form):
|
||||
class ImportRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords', 'file_path', 'file_uid')
|
||||
fields = ('name', 'keywords', 'file_path', 'file_uid')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
'file_path': _('Path'),
|
||||
'file_uid': _('File ID'),
|
||||
|
@ -46,25 +46,12 @@ class Keyword(models.Model):
|
||||
return "{0} {1}".format(self.icon, self.name)
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=64, unique=True)
|
||||
icon = models.CharField(max_length=1, blank=True, null=True)
|
||||
description = models.TextField(default="", blank=True)
|
||||
created_by = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{0} {1}".format(self.icon, self.name)
|
||||
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
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)
|
||||
created_by = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -10,24 +10,13 @@ class RecipeTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_recipe', args=[A('id')])
|
||||
name = tables.TemplateColumn(
|
||||
"<a href='#' onClick='openRecipe({{record.id}})'>{{record.name}}</a>")
|
||||
category = tables.Column(
|
||||
attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}})
|
||||
all_tags = tables.Column(
|
||||
attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}})
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'name', 'category', 'all_tags')
|
||||
|
||||
|
||||
class CategoryTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_category', args=[A('id')])
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'icon', 'name')
|
||||
fields = ('id', 'name', 'all_tags')
|
||||
|
||||
|
||||
class KeywordTable(tables.Table):
|
||||
|
@ -61,8 +61,6 @@
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
<!--<a class="dropdown-item" href="{% url 'new_recipe' %}"><i
|
||||
class="fas fa-book"></i> {% trans 'Recipe' %}</a>-->
|
||||
<a class="dropdown-item" href="{% url 'new_category' %}"><i
|
||||
class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i
|
||||
class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'new_storage' %}"><i
|
||||
@ -75,8 +73,6 @@
|
||||
{% trans 'List' %}
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
<a class="dropdown-item" href="{% url 'list_category' %}"><i
|
||||
class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'list_keyword' %}"><i
|
||||
class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'list_import' %}"><i
|
||||
|
@ -10,19 +10,16 @@ urlpatterns = [
|
||||
|
||||
path('new/recipe/', new.RecipeCreate.as_view(), name='new_recipe'),
|
||||
path('new/recipe_import/<int:import_id>/', 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/storage/', new.StorageCreate.as_view(), name='new_storage'),
|
||||
|
||||
path('list/keyword', lists.keyword, name='list_keyword'),
|
||||
path('list/category', lists.category, name='list_category'),
|
||||
path('list/import_log', lists.sync_log, name='list_import_log'),
|
||||
path('list/import', lists.recipe_import, name='list_import'),
|
||||
path('list/storage', lists.storage, name='list_storage'),
|
||||
|
||||
path('edit/recipe/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_recipe'),
|
||||
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
||||
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
|
||||
path('edit/sync/<int:pk>/', edit.SyncUpdate.as_view(), name='edit_sync'),
|
||||
path('edit/import/<int:pk>/', edit.ImportUpdate.as_view(), name='edit_import'),
|
||||
path('edit/storage/<int:pk>/', edit.StorageUpdate.as_view(), name='edit_storage'),
|
||||
@ -31,7 +28,6 @@ urlpatterns = [
|
||||
|
||||
path('delete/recipe/<int:pk>/', edit.RecipeDelete.as_view(), name='delete_recipe'),
|
||||
path('delete/keyword/<int:pk>/', edit.KeywordDelete.as_view(), name='delete_keyword'),
|
||||
path('delete/category/<int:pk>/', edit.CategoryDelete.as_view(), name='delete_category'),
|
||||
path('delete/sync/<int:pk>/', edit.MonitorDelete.as_view(), name='delete_sync'),
|
||||
path('delete/import/<int:pk>/', edit.ImportDelete.as_view(), name='delete_import'),
|
||||
path('delete/storage/<int:pk>/', edit.StorageDelete.as_view(), name='delete_storage'),
|
||||
|
@ -53,16 +53,12 @@ def batch_edit(request):
|
||||
form = BatchEditForm(request.POST)
|
||||
if form.is_valid():
|
||||
word = form.cleaned_data['search']
|
||||
category = form.cleaned_data['category']
|
||||
keywords = form.cleaned_data['keywords']
|
||||
|
||||
recipes = Recipe.objects.filter(name__contains=word)
|
||||
count = 0
|
||||
for recipe in recipes:
|
||||
edit = False
|
||||
if category is not None:
|
||||
recipe.category = category
|
||||
edit = True
|
||||
if keywords.__sizeof__() > 0:
|
||||
recipe.keywords.add(*list(keywords))
|
||||
edit = True
|
||||
@ -94,11 +90,9 @@ class Object(object):
|
||||
def statistics(request):
|
||||
counts = Object()
|
||||
counts.recipes = Recipe.objects.count()
|
||||
counts.categories = Category.objects.count()
|
||||
counts.keywords = Keyword.objects.count()
|
||||
counts.recipe_import = RecipeImport.objects.count()
|
||||
|
||||
counts.recipes_no_category = Recipe.objects.filter(category__isnull=True).count()
|
||||
counts.recipes_no_keyword = Recipe.objects.filter(keywords=None).count()
|
||||
|
||||
return render(request, 'stats.html', {'counts': counts})
|
||||
|
@ -5,8 +5,8 @@ from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import UpdateView, DeleteView
|
||||
|
||||
from cookbook.forms import EditRecipeForm, CategoryForm, KeywordForm, StorageForm, SyncForm
|
||||
from cookbook.models import Recipe, Category, Sync, Keyword, RecipeImport, Storage
|
||||
from cookbook.forms import EditRecipeForm, KeywordForm, StorageForm, SyncForm
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage
|
||||
|
||||
|
||||
class SyncUpdate(LoginRequiredMixin, UpdateView):
|
||||
@ -25,22 +25,6 @@ class SyncUpdate(LoginRequiredMixin, UpdateView):
|
||||
return context
|
||||
|
||||
|
||||
class CategoryUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic/edit_template.html"
|
||||
model = Category
|
||||
form_class = CategoryForm
|
||||
|
||||
# TODO add msg box
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('edit_category', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CategoryUpdate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Category")
|
||||
return context
|
||||
|
||||
|
||||
class KeywordUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic/edit_template.html"
|
||||
model = Keyword
|
||||
@ -150,17 +134,6 @@ class MonitorDelete(LoginRequiredMixin, DeleteView):
|
||||
return context
|
||||
|
||||
|
||||
class CategoryDelete(LoginRequiredMixin, DeleteView):
|
||||
template_name = "generic/delete_template.html"
|
||||
model = Category
|
||||
success_url = reverse_lazy('list_category')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CategoryDelete, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Category")
|
||||
return context
|
||||
|
||||
|
||||
class KeywordDelete(LoginRequiredMixin, DeleteView):
|
||||
template_name = "generic/delete_template.html"
|
||||
model = Keyword
|
||||
|
@ -4,16 +4,8 @@ from django.shortcuts import render
|
||||
from django_tables2 import RequestConfig
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.models import Category, Keyword, SyncLog, RecipeImport, Storage
|
||||
from cookbook.tables import CategoryTable, KeywordTable, ImportLogTable, RecipeImportTable, StorageTable
|
||||
|
||||
|
||||
@login_required
|
||||
def category(request):
|
||||
table = CategoryTable(Category.objects.all())
|
||||
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
||||
|
||||
return render(request, 'generic/list_template.html', {'title': _("Category"), 'table': table})
|
||||
from cookbook.models import Keyword, SyncLog, RecipeImport, Storage
|
||||
from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -6,14 +6,14 @@ from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import CreateView
|
||||
|
||||
from cookbook.forms import ImportRecipeForm, RecipeImport, CategoryForm, KeywordForm, Storage, StorageForm
|
||||
from cookbook.models import Category, Keyword, Recipe
|
||||
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm
|
||||
from cookbook.models import Keyword, Recipe
|
||||
|
||||
|
||||
class RecipeCreate(LoginRequiredMixin, CreateView): # this exists for completeness but is not in use at the moment
|
||||
template_name = "generic/new_template.html"
|
||||
model = Recipe
|
||||
fields = ['name', 'category', 'keywords']
|
||||
fields = ['name', 'keywords']
|
||||
success_url = reverse_lazy('index')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -22,18 +22,6 @@ class RecipeCreate(LoginRequiredMixin, CreateView): # this exists for completen
|
||||
return context
|
||||
|
||||
|
||||
class CategoryCreate(LoginRequiredMixin, CreateView):
|
||||
template_name = "generic/new_template.html"
|
||||
model = Category
|
||||
form_class = CategoryForm
|
||||
success_url = reverse_lazy('list_category')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CategoryCreate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Category")
|
||||
return context
|
||||
|
||||
|
||||
class KeywordCreate(LoginRequiredMixin, CreateView):
|
||||
template_name = "generic/new_template.html"
|
||||
model = Keyword
|
||||
@ -69,7 +57,6 @@ def create_new_recipe(request, import_id):
|
||||
recipe.name = form.cleaned_data['name']
|
||||
recipe.file_path = form.cleaned_data['file_path']
|
||||
recipe.file_uid = form.cleaned_data['file_uid']
|
||||
recipe.category = form.cleaned_data['category']
|
||||
|
||||
recipe.save()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user