bookmarks wip
This commit is contained in:
parent
417e372c42
commit
8fcafcc25a
@ -76,6 +76,12 @@ class StorageForm(forms.ModelForm):
|
|||||||
fields = ('name', 'method', 'username', 'password', 'token', 'url')
|
fields = ('name', 'method', 'username', 'password', 'token', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeBookForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = RecipeBook
|
||||||
|
fields = ('name',)
|
||||||
|
|
||||||
|
|
||||||
class SyncForm(forms.ModelForm):
|
class SyncForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Sync
|
model = Sync
|
||||||
|
32
cookbook/migrations/0005_recipebook_recipebookentry.py
Normal file
32
cookbook/migrations/0005_recipebook_recipebookentry.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Generated by Django 2.2.9 on 2019-12-24 11:14
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('cookbook', '0004_storage_created_by'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RecipeBook',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=128)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RecipeBookEntry',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.RecipeBook')),
|
||||||
|
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.Recipe')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -96,3 +96,13 @@ class RecipeImport(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeBook(models.Model):
|
||||||
|
name = models.CharField(max_length=128)
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeBookEntry(models.Model):
|
||||||
|
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||||
|
book = models.ForeignKey(RecipeBook, on_delete=models.CASCADE)
|
||||||
|
@ -72,6 +72,9 @@
|
|||||||
<a class="nav-link" href="{% url 'index' %}"><i class="fas fa-book"></i> {% trans 'Cookbook' %}<span
|
<a class="nav-link" href="{% url 'index' %}"><i class="fas fa-book"></i> {% trans 'Cookbook' %}<span
|
||||||
class="sr-only">(current)</span></a>
|
class="sr-only">(current)</span></a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'view_books' %}"><i class="fas fa-bookmark"></i> {% trans 'Books' %}</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
|
||||||
aria-haspopup="true" aria-expanded="false">
|
aria-haspopup="true" aria-expanded="false">
|
||||||
|
41
cookbook/templates/books.html
Normal file
41
cookbook/templates/books.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block title %}{% trans 'Recipe Books' %}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-9">
|
||||||
|
<h2>{% trans 'Recipe Books' %}</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col col-md-3" style="text-align: right">
|
||||||
|
<a href="{% url 'new_book' %}" class="btn btn-success"><i
|
||||||
|
class="fas fa-plus-circle"></i> {% trans 'New Book' %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
{% for b in book_list %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-12">
|
||||||
|
<a data-toggle="collapse" href="#collapse_{{ b.book.pk }}" role="button" aria-expanded="false"
|
||||||
|
aria-controls="collapse_{{ b.book.pk }}"><h4>{{ b.book.name }}</h4></a>
|
||||||
|
<hr/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-12">
|
||||||
|
<div class="collapse" id="collapse_{{ b.book.pk }}">
|
||||||
|
Test
|
||||||
|
{% for r in b.recipes %}
|
||||||
|
{{ r }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
@ -6,7 +6,7 @@ from cookbook.helper import dal
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('test', views.test, name='test'),
|
path('books', views.books, name='view_books'),
|
||||||
|
|
||||||
path('view/recipe/<int:pk>', views.recipe_view, name='view_recipe'),
|
path('view/recipe/<int:pk>', views.recipe_view, name='view_recipe'),
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ urlpatterns = [
|
|||||||
path('new/recipe_import/<int:import_id>/', new.create_new_external_recipe, name='new_recipe_import'),
|
path('new/recipe_import/<int:import_id>/', new.create_new_external_recipe, name='new_recipe_import'),
|
||||||
path('new/keyword/', new.KeywordCreate.as_view(), name='new_keyword'),
|
path('new/keyword/', new.KeywordCreate.as_view(), name='new_keyword'),
|
||||||
path('new/storage/', new.StorageCreate.as_view(), name='new_storage'),
|
path('new/storage/', new.StorageCreate.as_view(), name='new_storage'),
|
||||||
|
path('new/book/', new.RecipeBookCreate.as_view(), name='new_book'),
|
||||||
|
|
||||||
path('list/keyword', lists.keyword, name='list_keyword'),
|
path('list/keyword', lists.keyword, name='list_keyword'),
|
||||||
path('list/import_log', lists.sync_log, name='list_import_log'),
|
path('list/import_log', lists.sync_log, name='list_import_log'),
|
||||||
@ -21,8 +22,10 @@ urlpatterns = [
|
|||||||
path('list/storage', lists.storage, name='list_storage'),
|
path('list/storage', lists.storage, name='list_storage'),
|
||||||
|
|
||||||
path('edit/recipe/<int:pk>/', edit.switch_recipe, name='edit_recipe'),
|
path('edit/recipe/<int:pk>/', edit.switch_recipe, name='edit_recipe'),
|
||||||
path('edit/recipe/internal/<int:pk>/', edit.internal_recipe_update, name='edit_internal_recipe'), # for internal use only
|
path('edit/recipe/internal/<int:pk>/', edit.internal_recipe_update, name='edit_internal_recipe'),
|
||||||
path('edit/recipe/external/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_external_recipe'), # for internal use only
|
# for internal use only
|
||||||
|
path('edit/recipe/external/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_external_recipe'),
|
||||||
|
# for internal use only
|
||||||
path('edit/recipe/convert/<int:pk>/', edit.convert_recipe, name='edit_convert_recipe'), # for internal use only
|
path('edit/recipe/convert/<int:pk>/', edit.convert_recipe, name='edit_convert_recipe'), # for internal use only
|
||||||
|
|
||||||
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
||||||
|
@ -7,14 +7,15 @@ from django.urls import reverse_lazy, reverse
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import CreateView
|
from django.views.generic import CreateView
|
||||||
|
|
||||||
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm
|
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \
|
||||||
from cookbook.models import Keyword, Recipe
|
RecipeBookForm
|
||||||
|
from cookbook.models import Keyword, Recipe, RecipeBook
|
||||||
|
|
||||||
|
|
||||||
class RecipeCreate(LoginRequiredMixin, CreateView):
|
class RecipeCreate(LoginRequiredMixin, CreateView):
|
||||||
template_name = "generic/new_template.html"
|
template_name = "generic/new_template.html"
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', )
|
fields = ('name',)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
obj = form.save(commit=False)
|
obj = form.save(commit=False)
|
||||||
@ -86,6 +87,25 @@ def create_new_external_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={'file_path': new_recipe.file_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})
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeBookCreate(LoginRequiredMixin, CreateView):
|
||||||
|
template_name = "generic/new_template.html"
|
||||||
|
model = RecipeBook
|
||||||
|
form_class = RecipeBookForm
|
||||||
|
success_url = reverse_lazy('view_books')
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
obj = form.save(commit=False)
|
||||||
|
obj.user = self.request.user
|
||||||
|
obj.save()
|
||||||
|
return HttpResponseRedirect(reverse('view_books'))
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(RecipeBookCreate, self).get_context_data(**kwargs)
|
||||||
|
context['title'] = _("Recipe Book")
|
||||||
|
return context
|
||||||
|
@ -46,8 +46,17 @@ def recipe_view(request, pk):
|
|||||||
else:
|
else:
|
||||||
form = CommentForm()
|
form = CommentForm()
|
||||||
|
|
||||||
return render(request, 'recipe_view.html', {'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'form': form})
|
return render(request, 'recipe_view.html',
|
||||||
|
{'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'form': form})
|
||||||
|
|
||||||
|
|
||||||
def test(request):
|
@login_required()
|
||||||
return render(request, 'test.html')
|
def books(request):
|
||||||
|
book_list = []
|
||||||
|
|
||||||
|
books = RecipeBook.objects.filter(user=request.user).all()
|
||||||
|
|
||||||
|
for b in books:
|
||||||
|
book_list.append( {'book': b, 'recipes': RecipeBookEntry.objects.filter(book=b).all()})
|
||||||
|
|
||||||
|
return render(request, 'books.html', {'book_list': book_list})
|
||||||
|
Loading…
Reference in New Issue
Block a user