mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
basic import management page
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -44,6 +46,10 @@ def import_all(monitor):
|
|||||||
|
|
||||||
log_entry = ImportLog(status='SUCCESS', msg='Imported ' + str(import_count) + ' recipes', monitor=monitor)
|
log_entry = ImportLog(status='SUCCESS', msg='Imported ' + str(import_count) + ' recipes', monitor=monitor)
|
||||||
log_entry.save()
|
log_entry.save()
|
||||||
|
|
||||||
|
monitor.last_checked = datetime.now()
|
||||||
|
monitor.save()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,18 @@ class KeywordTable(tables.Table):
|
|||||||
|
|
||||||
|
|
||||||
class MonitoredPathTable(tables.Table):
|
class MonitoredPathTable(tables.Table):
|
||||||
edit = tables.TemplateColumn("<a href='{% url 'delete_monitor' record.id %}' >" + _('Delete') + "</a>")
|
delete = tables.TemplateColumn("<a href='{% url 'delete_monitor' record.id %}' >" + _('Delete') + "</a>")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Keyword
|
model = Keyword
|
||||||
template_name = 'generic/table_template.html'
|
template_name = 'generic/table_template.html'
|
||||||
fields = ('path', 'last_checked')
|
fields = ('path', 'last_checked')
|
||||||
|
|
||||||
|
|
||||||
|
class NewRecipeTable(tables.Table):
|
||||||
|
delete = tables.TemplateColumn("<a href='{% url 'delete_new_recipe' record.id %}' >" + _('Delete') + "</a>")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Keyword
|
||||||
|
template_name = 'generic/table_template.html'
|
||||||
|
fields = ('name','path')
|
||||||
|
|||||||
@@ -51,7 +51,8 @@
|
|||||||
{% trans 'Manage Data' %}
|
{% trans 'Manage Data' %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
<a class="dropdown-item" href="{% url 'batch_import' %}">{% trans 'Import' %}</a>
|
<a class="dropdown-item" href="{% url 'batch_monitor' %}">{% trans 'Configure Sync' %}</a>
|
||||||
|
<a class="dropdown-item" href="{% url 'batch_import' %}">{% trans 'Manage imported Recipes' %}</a>
|
||||||
<a class="dropdown-item" href="{% url 'batch_edit' %}">{% trans 'Batch Edit' %}</a>
|
<a class="dropdown-item" href="{% url 'batch_edit' %}">{% trans 'Batch Edit' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load crispy_forms_tags %}
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load django_tables2 %}
|
{% load django_tables2 %}
|
||||||
|
|
||||||
{% block title %}{% trans 'Import Recipes' %}{% endblock %}
|
{% block title %}{% trans 'Imported Recipes' %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h3>
|
<h3>{% trans 'Update imported Recipes' %}</h3>
|
||||||
{% trans 'Import Recipes' %}
|
<br>
|
||||||
<small class="text-muted">{% trans 'Manage all paths that should be imported' %}</small>
|
<button class="btn btn-primary">Auto-Import all</button>
|
||||||
</h3>
|
<br>
|
||||||
|
|
||||||
<form method="POST" class="post-form">{% csrf_token %}
|
{% render_table imported_recipes %}
|
||||||
{% crispy form %}
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% render_table monitored_paths %}
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
21
cookbook/templates/batch/monitor.html
Normal file
21
cookbook/templates/batch/monitor.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load django_tables2 %}
|
||||||
|
|
||||||
|
{% block title %}{% trans 'Sync' %}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h3>{% trans 'Manage watched Folders' %}</h3>
|
||||||
|
|
||||||
|
{% 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/>
|
||||||
|
<form method="POST" class="post-form">{% csrf_token %}
|
||||||
|
{% crispy form %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% render_table monitored_paths %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -20,7 +20,9 @@ urlpatterns = [
|
|||||||
path('delete/keyword/<int:pk>/', edit.KeywordDelete.as_view(), name='delete_keyword'),
|
path('delete/keyword/<int:pk>/', edit.KeywordDelete.as_view(), name='delete_keyword'),
|
||||||
path('delete/category/<int:pk>/', edit.CategoryDelete.as_view(), name='delete_category'),
|
path('delete/category/<int:pk>/', edit.CategoryDelete.as_view(), name='delete_category'),
|
||||||
path('delete/monitor/<int:pk>/', edit.MonitorDelete.as_view(), name='delete_monitor'),
|
path('delete/monitor/<int:pk>/', edit.MonitorDelete.as_view(), name='delete_monitor'),
|
||||||
|
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/import', batch.batch_import, name='batch_import'),
|
||||||
path('batch/category', batch.batch_edit, name='batch_edit'),
|
path('batch/category', batch.batch_edit, name='batch_edit'),
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ def get_file_link(request, recipe_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def dropbox_sync(request):
|
def dropbox_sync(request):
|
||||||
dropbox.sync_all()
|
dropbox.sync_all()
|
||||||
return HttpResponse("Import Successful")
|
return HttpResponse("Import Successful ... or not ? WIP")
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ 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
|
||||||
|
|
||||||
from cookbook.forms import ImportForm, BatchEditForm
|
from cookbook.forms import ImportForm, BatchEditForm, NewRecipe
|
||||||
from cookbook.helper import dropbox
|
|
||||||
from cookbook.models import Recipe, Category, Monitor
|
from cookbook.models import Recipe, Category, Monitor
|
||||||
from cookbook.tables import MonitoredPathTable
|
from cookbook.tables import MonitoredPathTable, NewRecipeTable
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def batch_import(request):
|
def batch_monitor(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = ImportForm(request.POST)
|
form = ImportForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
@@ -26,7 +25,15 @@ def batch_import(request):
|
|||||||
monitored_paths = MonitoredPathTable(Monitor.objects.all())
|
monitored_paths = MonitoredPathTable(Monitor.objects.all())
|
||||||
RequestConfig(request, paginate={'per_page': 25}).configure(monitored_paths)
|
RequestConfig(request, paginate={'per_page': 25}).configure(monitored_paths)
|
||||||
|
|
||||||
return render(request, 'batch/import.html', {'form': form, 'monitored_paths': monitored_paths})
|
return render(request, 'batch/monitor.html', {'form': form, 'monitored_paths': monitored_paths})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def batch_import(request):
|
||||||
|
imported_recipes = NewRecipeTable(NewRecipe.objects.all())
|
||||||
|
RequestConfig(request, paginate={'per_page': 25}).configure(imported_recipes)
|
||||||
|
|
||||||
|
return render(request, 'batch/import.html', {'imported_recipes': imported_recipes})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django.views.generic import UpdateView, DeleteView
|
from django.views.generic import UpdateView, DeleteView
|
||||||
|
|
||||||
from cookbook.forms import EditRecipeForm
|
from cookbook.forms import EditRecipeForm
|
||||||
from cookbook.models import Recipe, Category, Monitor, Keyword
|
from cookbook.models import Recipe, Category, Monitor, Keyword, NewRecipe
|
||||||
|
|
||||||
|
|
||||||
class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
||||||
@@ -67,3 +67,9 @@ 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('index')
|
||||||
|
|
||||||
|
|
||||||
|
class NewRecipeDelete(LoginRequiredMixin, DeleteView):
|
||||||
|
template_name = "generic\delete_template.html"
|
||||||
|
model = NewRecipe
|
||||||
|
success_url = reverse_lazy('batch_import')
|
||||||
|
|||||||
Reference in New Issue
Block a user