bookmarks wip

This commit is contained in:
vabene1111 2019-12-24 15:06:58 +01:00
parent 417e372c42
commit 8fcafcc25a
8 changed files with 135 additions and 11 deletions

View File

@ -76,6 +76,12 @@ class StorageForm(forms.ModelForm):
fields = ('name', 'method', 'username', 'password', 'token', 'url')
class RecipeBookForm(forms.ModelForm):
class Meta:
model = RecipeBook
fields = ('name',)
class SyncForm(forms.ModelForm):
class Meta:
model = Sync

View 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')),
],
),
]

View File

@ -96,3 +96,13 @@ class RecipeImport(models.Model):
def __str__(self):
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)

View File

@ -72,6 +72,9 @@
<a class="nav-link" href="{% url 'index' %}"><i class="fas fa-book"></i> {% trans 'Cookbook' %}<span
class="sr-only">(current)</span></a>
</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">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">

View 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 %}

View File

@ -6,7 +6,7 @@ from cookbook.helper import dal
urlpatterns = [
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'),
@ -14,6 +14,7 @@ urlpatterns = [
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/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/import_log', lists.sync_log, name='list_import_log'),
@ -21,8 +22,10 @@ urlpatterns = [
path('list/storage', lists.storage, name='list_storage'),
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/external/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_external_recipe'), # for internal use only
path('edit/recipe/internal/<int:pk>/', edit.internal_recipe_update, name='edit_internal_recipe'),
# 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/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),

View File

@ -7,8 +7,9 @@ from django.urls import reverse_lazy, reverse
from django.utils.translation import gettext as _
from django.views.generic import CreateView
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm
from cookbook.models import Keyword, Recipe
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \
RecipeBookForm
from cookbook.models import Keyword, Recipe, RecipeBook
class RecipeCreate(LoginRequiredMixin, CreateView):
@ -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!'))
else:
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})
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

View File

@ -46,8 +46,17 @@ def recipe_view(request, pk):
else:
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):
return render(request, 'test.html')
@login_required()
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})