misc fixes and updates
This commit is contained in:
parent
c720f6c193
commit
b92c6dd88f
19
cookbook/migrations/0004_auto_20180515_2035.py
Normal file
19
cookbook/migrations/0004_auto_20180515_2035.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.0.5 on 2018-05-15 18:35
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0003_auto_20180514_1121'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='recipe',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cookbook.Category'),
|
||||||
|
),
|
||||||
|
]
|
@ -29,7 +29,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="")
|
||||||
link = models.CharField(max_length=512, default="")
|
link = models.CharField(max_length=512, default="")
|
||||||
category = models.ForeignKey(Category, blank=True, on_delete=models.PROTECT, 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)
|
||||||
created_by = models.IntegerField(default=0)
|
created_by = models.IntegerField(default=0)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
@ -8,7 +8,13 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h3>{{ title }} {% trans 'List' %}</h3>
|
<h3>{{ title }} {% trans 'List' %}
|
||||||
|
{% if table.Meta.model|get_class == 'Category' %}
|
||||||
|
<a href="{% url 'new_category' %}" ><i class="fal fa-plus-circle"></i></a>
|
||||||
|
{% elif table.Meta.model|get_class == 'Keyword' %}
|
||||||
|
<a href="{% url 'new_keyword' %}" ><i class="fal fa-plus-circle"></i></a>
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
{% if table.Meta.model|get_class == 'RecipeImport' %}
|
{% if table.Meta.model|get_class == 'RecipeImport' %}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load class_tag %}
|
||||||
|
|
||||||
{% block title %}{% trans 'New' %} - {{ title }}{% endblock %}
|
{% block title %}{% trans 'New' %} - {{ title }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h3>{% trans 'New' %} {{ title }}</h3>
|
<h3>{% trans 'New' %} {{ title }} </h3>
|
||||||
|
|
||||||
<form action="." method="post">
|
<form action="." method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
@ -7,6 +8,7 @@ from django_tables2 import RequestConfig
|
|||||||
from cookbook.forms import MonitorForm, BatchEditForm, RecipeImport
|
from cookbook.forms import MonitorForm, BatchEditForm, RecipeImport
|
||||||
from cookbook.models import Recipe, Category, Sync
|
from cookbook.models import Recipe, Category, Sync
|
||||||
from cookbook.tables import MonitoredPathTable
|
from cookbook.tables import MonitoredPathTable
|
||||||
|
from django.utils.translation import gettext as _, ngettext
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -49,14 +51,28 @@ def batch_edit(request):
|
|||||||
keyword = form.cleaned_data['keyword']
|
keyword = form.cleaned_data['keyword']
|
||||||
|
|
||||||
recipes = Recipe.objects.filter(name__contains=word)
|
recipes = Recipe.objects.filter(name__contains=word)
|
||||||
|
count = 0
|
||||||
for recipe in recipes:
|
for recipe in recipes:
|
||||||
|
edit = False
|
||||||
if category is not None:
|
if category is not None:
|
||||||
recipe.category = Category.objects.get(name=category)
|
recipe.category = Category.objects.get(name=category)
|
||||||
|
edit = True
|
||||||
if keyword.__sizeof__() > 0:
|
if keyword.__sizeof__() > 0:
|
||||||
recipe.keywords.add(*list(keyword))
|
recipe.keywords.add(*list(keyword))
|
||||||
|
edit = True
|
||||||
|
if edit:
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
|
msg = ngettext(
|
||||||
|
'Batch edit done. %(count)d recipe where updated.',
|
||||||
|
'Batch edit done. %(count)d Recipes where updated.',
|
||||||
|
count) % {
|
||||||
|
'count': count,
|
||||||
|
}
|
||||||
|
messages.add_message(request, messages.SUCCESS, msg)
|
||||||
|
|
||||||
return redirect('batch_edit')
|
return redirect('batch_edit')
|
||||||
else:
|
else:
|
||||||
form = BatchEditForm()
|
form = BatchEditForm()
|
||||||
|
@ -13,8 +13,10 @@ class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Sync
|
model = Sync
|
||||||
fields = ['path']
|
fields = ['path']
|
||||||
|
|
||||||
|
# TODO add msg box
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
return reverse('edit_monitor', kwargs={'pk': self.object.pk})
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(MonitorUpdate, self).get_context_data(**kwargs)
|
context = super(MonitorUpdate, self).get_context_data(**kwargs)
|
||||||
@ -27,8 +29,10 @@ class CategoryUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Category
|
model = Category
|
||||||
fields = ['name', 'icon', 'description']
|
fields = ['name', 'icon', 'description']
|
||||||
|
|
||||||
|
# TODO add msg box
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
return reverse('edit_category', kwargs={'pk': self.object.pk})
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CategoryUpdate, self).get_context_data(**kwargs)
|
context = super(CategoryUpdate, self).get_context_data(**kwargs)
|
||||||
@ -41,8 +45,10 @@ class KeywordUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Keyword
|
model = Keyword
|
||||||
fields = ['name', 'icon', 'description']
|
fields = ['name', 'icon', 'description']
|
||||||
|
|
||||||
|
# TODO add msg box
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
return reverse('edit_keyword', kwargs={'pk': self.object.pk})
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(KeywordUpdate, self).get_context_data(**kwargs)
|
context = super(KeywordUpdate, self).get_context_data(**kwargs)
|
||||||
@ -55,6 +61,8 @@ class ImportUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = RecipeImport
|
model = RecipeImport
|
||||||
fields = ['name', 'path']
|
fields = ['name', 'path']
|
||||||
|
|
||||||
|
# TODO add msg box
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('edit_import', kwargs={'pk': self.object.pk})
|
return reverse('edit_import', kwargs={'pk': self.object.pk})
|
||||||
|
|
||||||
@ -101,7 +109,7 @@ class RecipeDelete(LoginRequiredMixin, DeleteView):
|
|||||||
class ImportDelete(LoginRequiredMixin, DeleteView):
|
class ImportDelete(LoginRequiredMixin, DeleteView):
|
||||||
template_name = "generic\delete_template.html"
|
template_name = "generic\delete_template.html"
|
||||||
model = RecipeImport
|
model = RecipeImport
|
||||||
success_url = reverse_lazy('index')
|
success_url = reverse_lazy('list_import')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(ImportDelete, self).get_context_data(**kwargs)
|
context = super(ImportDelete, self).get_context_data(**kwargs)
|
||||||
@ -123,7 +131,7 @@ class MonitorDelete(LoginRequiredMixin, DeleteView):
|
|||||||
class CategoryDelete(LoginRequiredMixin, DeleteView):
|
class CategoryDelete(LoginRequiredMixin, DeleteView):
|
||||||
template_name = "generic\delete_template.html"
|
template_name = "generic\delete_template.html"
|
||||||
model = Category
|
model = Category
|
||||||
success_url = reverse_lazy('index')
|
success_url = reverse_lazy('list_category')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CategoryDelete, self).get_context_data(**kwargs)
|
context = super(CategoryDelete, self).get_context_data(**kwargs)
|
||||||
@ -134,7 +142,7 @@ class CategoryDelete(LoginRequiredMixin, DeleteView):
|
|||||||
class KeywordDelete(LoginRequiredMixin, DeleteView):
|
class KeywordDelete(LoginRequiredMixin, DeleteView):
|
||||||
template_name = "generic\delete_template.html"
|
template_name = "generic\delete_template.html"
|
||||||
model = Keyword
|
model = Keyword
|
||||||
success_url = reverse_lazy('index')
|
success_url = reverse_lazy('list_keyword')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(KeywordDelete, self).get_context_data(**kwargs)
|
context = super(KeywordDelete, self).get_context_data(**kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user