import all
This commit is contained in:
@ -84,11 +84,11 @@ class EditRecipeForm(forms.ModelForm):
|
||||
self.helper.add_input(Submit('save', _('Save'), css_class='btn-primary'))
|
||||
|
||||
|
||||
class ImportForm(forms.Form):
|
||||
class MonitorForm(forms.Form):
|
||||
path = forms.CharField(label=_('Path'))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ImportForm, self).__init__(*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'))
|
||||
|
@ -8,7 +8,10 @@
|
||||
|
||||
<h3>{% trans 'Update imported Recipes' %}</h3>
|
||||
<br>
|
||||
<button class="btn btn-primary">Auto-Import all</button>
|
||||
<form action="{% url 'batch_import_all' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="{% trans 'Auto import all' %}" class="btn btn-primary"/>
|
||||
</form>
|
||||
<br>
|
||||
|
||||
{% render_table imported_recipes %}
|
||||
|
@ -12,6 +12,8 @@
|
||||
{% trans 'On this Page you can manage all DropBox folder locations that should be monitored and synced' %} <br/>
|
||||
{% trans 'The path must be in the following format' %} <code>/Folder/RecipesFolder</code>
|
||||
<br/>
|
||||
<a href="{% url 'api_dropbox_sync' %}" class="btn btn-success">{% trans 'Sync Now!' %}</a>
|
||||
<br/>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
</form>
|
||||
|
@ -23,8 +23,9 @@ urlpatterns = [
|
||||
path('delete/new_recipe/<int:pk>/', edit.NewRecipeDelete.as_view(), name='delete_new_recipe'),
|
||||
|
||||
path('batch/monitor', batch.batch_monitor, name='batch_monitor'),
|
||||
path('batch/import', batch.batch_import, name='batch_import'),
|
||||
path('batch/category', batch.batch_edit, name='batch_edit'),
|
||||
path('batch/import', batch.batch_import, name='batch_import'),
|
||||
path('batch/import/all', batch.batch_import_all, name='batch_import_all'),
|
||||
|
||||
path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='api_get_file_link'),
|
||||
path('api/sync_all/', api.dropbox_sync, name='api_dropbox_sync'),
|
||||
|
@ -4,7 +4,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import redirect, render
|
||||
from django_tables2 import RequestConfig
|
||||
|
||||
from cookbook.forms import ImportForm, BatchEditForm, NewRecipe
|
||||
from cookbook.forms import MonitorForm, BatchEditForm, NewRecipe
|
||||
from cookbook.models import Recipe, Category, Monitor
|
||||
from cookbook.tables import MonitoredPathTable, NewRecipeTable
|
||||
|
||||
@ -12,7 +12,7 @@ from cookbook.tables import MonitoredPathTable, NewRecipeTable
|
||||
@login_required
|
||||
def batch_monitor(request):
|
||||
if request.method == "POST":
|
||||
form = ImportForm(request.POST)
|
||||
form = MonitorForm(request.POST)
|
||||
if form.is_valid():
|
||||
new_path = Monitor()
|
||||
new_path.path = form.cleaned_data['path']
|
||||
@ -20,7 +20,7 @@ def batch_monitor(request):
|
||||
new_path.save()
|
||||
return redirect('batch_import')
|
||||
else:
|
||||
form = ImportForm()
|
||||
form = MonitorForm()
|
||||
|
||||
monitored_paths = MonitoredPathTable(Monitor.objects.all())
|
||||
RequestConfig(request, paginate={'per_page': 25}).configure(monitored_paths)
|
||||
@ -36,6 +36,18 @@ def batch_import(request):
|
||||
return render(request, 'batch/import.html', {'imported_recipes': imported_recipes})
|
||||
|
||||
|
||||
@login_required
|
||||
def batch_import_all(request):
|
||||
if request.method == "POST":
|
||||
imports = NewRecipe.objects.all()
|
||||
for new_recipe in imports:
|
||||
recipe = Recipe(name=new_recipe.name, path=new_recipe.path, category=(Category.objects.get(id=0)))
|
||||
recipe.save()
|
||||
new_recipe.delete()
|
||||
|
||||
return redirect('batch_import')
|
||||
|
||||
|
||||
@login_required
|
||||
def batch_edit(request):
|
||||
if request.method == "POST":
|
||||
|
Reference in New Issue
Block a user