import process
This commit is contained in:
parent
8d4506da54
commit
c9f0192a2c
@ -5,24 +5,6 @@ from django import forms
|
||||
from .models import *
|
||||
|
||||
|
||||
class RecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RecipeForm, self).__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.add_input(Submit('save', _('Save'), css_class='btn-primary'))
|
||||
|
||||
|
||||
class EditRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
@ -45,20 +27,21 @@ class EditRecipeForm(forms.ModelForm):
|
||||
class MonitorForm(forms.Form):
|
||||
path = forms.CharField(label=_('Path'))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MonitorForm, self).__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.add_input(Submit('import', _('Sync'), css_class='btn-primary'))
|
||||
|
||||
|
||||
class BatchEditForm(forms.Form):
|
||||
search = forms.CharField(label=_('Search String'))
|
||||
category = forms.ModelChoiceField(queryset=Category.objects.all().order_by('id'), required=False)
|
||||
keyword = forms.ModelMultipleChoiceField(queryset=Keyword.objects.all().order_by('id'), required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BatchEditForm, self).__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.add_input(Submit('update', _('Update'), css_class='btn-primary'))
|
||||
|
||||
class ImportRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords', 'path')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'category': _('Category'),
|
||||
'keywords': _('Keywords'),
|
||||
'path': _('Path'),
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class MonitoredPathTable(tables.Table):
|
||||
|
||||
|
||||
class ImportTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_import', args=[A('id')])
|
||||
id = tables.LinkColumn('new_recipe_import', args=[A('id')])
|
||||
delete = tables.TemplateColumn("<a href='{% url 'delete_import' record.id %}' >" + _('Delete') + "</a>")
|
||||
|
||||
class Meta:
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
@ -1,19 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load django_tables2 %}
|
||||
|
||||
{% block title %}{% trans 'Imported Recipes' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{% trans 'Imported Recipes' %}</h3>
|
||||
<br>
|
||||
<form action="{% url 'batch_import_all' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="{% trans 'import all' %}" class="btn btn-primary"/>
|
||||
</form>
|
||||
<br>
|
||||
|
||||
{% render_table imported_recipes %}
|
||||
|
||||
{% endblock %}
|
@ -16,7 +16,9 @@
|
||||
<br/>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
<br/><br/>
|
||||
|
||||
{% render_table monitored_paths %}
|
||||
|
||||
|
24
cookbook/templates/forms/edit_import_recipe.html
Normal file
24
cookbook/templates/forms/edit_import_recipe.html
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Import new Recipe' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{% trans 'Import new Recipe' %}</h3>
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
//converts multiselct in recipe edit to searchable multiselect
|
||||
//shitty solution that needs to be redone at some point
|
||||
$(document).ready(function () {
|
||||
$('#id_keywords').select2();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@ -9,6 +9,7 @@ urlpatterns = [
|
||||
path('test', views.test, name='test'),
|
||||
|
||||
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'),
|
||||
|
||||
@ -37,6 +38,4 @@ urlpatterns = [
|
||||
path('api/sync_all/', api.dropbox_sync, name='api_dropbox_sync'),
|
||||
|
||||
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
|
||||
|
||||
]
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import render, redirect
|
||||
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.models import Category, Keyword, Recipe
|
||||
|
||||
|
||||
@ -12,6 +16,9 @@ class RecipeCreate(LoginRequiredMixin, CreateView): # this exists for completen
|
||||
fields = ['name', 'category', 'keywords']
|
||||
success_url = reverse_lazy('list_category')
|
||||
|
||||
def get_initial(self):
|
||||
return {'value1': self.request.user}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RecipeCreate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Recipe")
|
||||
@ -40,3 +47,30 @@ class KeywordCreate(LoginRequiredMixin, CreateView):
|
||||
context = super(KeywordCreate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Keyword")
|
||||
return context
|
||||
|
||||
|
||||
@login_required
|
||||
def create_new_recipe(request, import_id):
|
||||
if request.method == "POST":
|
||||
form = ImportRecipeForm(request.POST)
|
||||
if form.is_valid():
|
||||
recipe = Recipe()
|
||||
recipe.name = form.cleaned_data['name']
|
||||
recipe.path = form.cleaned_data['path']
|
||||
recipe.category = form.cleaned_data['category']
|
||||
|
||||
recipe.save()
|
||||
|
||||
recipe.keywords.set(form.cleaned_data['keywords'])
|
||||
|
||||
NewRecipe.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)
|
||||
form = ImportRecipeForm(initial={'path': new_recipe.path, 'name': new_recipe.name})
|
||||
|
||||
return render(request, 'forms/edit_import_recipe.html', {'form': form})
|
||||
|
Loading…
Reference in New Issue
Block a user