generic views
This commit is contained in:
parent
8c6019756f
commit
37639ad4c7
2
.gitignore
vendored
2
.gitignore
vendored
@ -70,3 +70,5 @@ secret_settings\.py
|
||||
*.sqlite3
|
||||
|
||||
\.idea/workspace\.xml
|
||||
|
||||
cookbook/migrations/
|
||||
|
@ -4,10 +4,11 @@
|
||||
<facet type="django" name="Django">
|
||||
<configuration>
|
||||
<option name="rootFolder" value="$MODULE_DIR$" />
|
||||
<option name="settingsModule" value="Recipies/settings.py" />
|
||||
<option name="settingsModule" value="recipes/settings.py" />
|
||||
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
|
||||
<option name="environment" value="<map/>" />
|
||||
<option name="doNotUseTestRunner" value="false" />
|
||||
<option name="trackFilePattern" value="migrations" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
|
@ -91,7 +91,7 @@ class ImportForm(forms.Form):
|
||||
super(ImportForm, self).__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.add_input(Submit('import', _('Import'), css_class='btn-primary'))
|
||||
self.helper.add_input(Submit('import', _('Sync'), css_class='btn-primary'))
|
||||
|
||||
|
||||
class BatchEditForm(forms.Form):
|
||||
|
@ -1,49 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-01-31 21:52
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('description', models.TextField(default='')),
|
||||
('created_by', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Keyword',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('description', models.TextField(default='')),
|
||||
('created_by', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Recipe',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('created_by', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.Category')),
|
||||
('keywords', models.ManyToManyField(to='cookbook.Keyword')),
|
||||
],
|
||||
),
|
||||
]
|
@ -1,23 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-02-01 13:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='category',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='keyword',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
]
|
@ -1,19 +0,0 @@
|
||||
# Generated by Django 2.0.2 on 2018-02-05 18:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0002_auto_20180201_1457'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='path',
|
||||
field=models.CharField(default='', max_length=512),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -1,28 +0,0 @@
|
||||
# Generated by Django 2.0.2 on 2018-02-05 22:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0003_recipe_path'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='link',
|
||||
field=models.CharField(default='', max_length=512),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='keywords',
|
||||
field=models.ManyToManyField(blank=True, to='cookbook.Keyword'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='path',
|
||||
field=models.CharField(default='', max_length=512),
|
||||
),
|
||||
]
|
@ -1,23 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-02-09 11:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0004_auto_20180205_2316'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='category',
|
||||
name='name',
|
||||
field=models.CharField(max_length=64, unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='keyword',
|
||||
name='name',
|
||||
field=models.CharField(max_length=64, unique=True),
|
||||
),
|
||||
]
|
@ -1,29 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-02-09 11:46
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0005_auto_20180209_1241'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='category',
|
||||
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.Category'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='link',
|
||||
field=models.CharField(blank=True, default='', max_length=512),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='path',
|
||||
field=models.CharField(blank=True, default='', max_length=512),
|
||||
),
|
||||
]
|
@ -1,29 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-02-09 11:50
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0006_auto_20180209_1246'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='category',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.SET_DEFAULT, to='cookbook.Category'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='link',
|
||||
field=models.CharField(default='', max_length=512),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='path',
|
||||
field=models.CharField(default='', max_length=512),
|
||||
),
|
||||
]
|
@ -1,19 +0,0 @@
|
||||
# Generated by Django 2.0.1 on 2018-02-09 11:51
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0007_auto_20180209_1250'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='category',
|
||||
field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.SET_DEFAULT, to='cookbook.Category'),
|
||||
),
|
||||
]
|
@ -39,3 +39,10 @@ class Recipe(models.Model):
|
||||
@property
|
||||
def all_tags(self):
|
||||
return ', '.join([x.name for x in self.keywords.all()])
|
||||
|
||||
|
||||
class Monitor(models.Model):
|
||||
path = models.CharField(max_length=512, default="")
|
||||
last_checked = models.DateTimeField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
@ -20,7 +20,7 @@ class RecipeTable(tables.Table):
|
||||
|
||||
|
||||
class CategoryTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_recipe', args=[A('id')])
|
||||
id = tables.LinkColumn('edit_category', args=[A('id')])
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
@ -29,9 +29,18 @@ class CategoryTable(tables.Table):
|
||||
|
||||
|
||||
class KeywordTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_recipe', args=[A('id')])
|
||||
id = tables.LinkColumn('edit_keyword', args=[A('id')])
|
||||
|
||||
class Meta:
|
||||
model = Keyword
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'name')
|
||||
|
||||
|
||||
class MonitoredPathTable(tables.Table):
|
||||
edit = tables.TemplateColumn("<a href='#' >Löschen</a>")
|
||||
|
||||
class Meta:
|
||||
model = Keyword
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('path', 'last_checked')
|
||||
|
@ -9,11 +9,13 @@
|
||||
|
||||
<h3>
|
||||
{% trans 'Import Recipes' %}
|
||||
<small class="text-muted">{% trans 'Import Recipes from Dropbox Storage' %}</small>
|
||||
<small class="text-muted">{% trans 'Manage all paths that should be imported' %}</small>
|
||||
</h3>
|
||||
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
</form>
|
||||
|
||||
{% render_table monitored_paths %}
|
||||
|
||||
{% endblock %}
|
20
cookbook/templates/generic/delete_template.html
Normal file
20
cookbook/templates/generic/delete_template.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Delete' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>
|
||||
{% trans 'Delete' %}
|
||||
<small class="text-muted">{% trans 'Delete this Object' %}</small>
|
||||
</h3>
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
20
cookbook/templates/generic/edit_template.html
Normal file
20
cookbook/templates/generic/edit_template.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Edit' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>
|
||||
{% trans 'Edit' %}
|
||||
<small class="text-muted">{% trans 'Edit this Object' %}</small>
|
||||
</h3>
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
@ -12,11 +12,14 @@ urlpatterns = [
|
||||
path('new/keyword', new.keyword, name='new_keyword'),
|
||||
|
||||
path('edit/recipe/<int:recipe_id>/', edit.recipe, name='edit_recipe'),
|
||||
path('edit/category/<int:category_id>/', edit.category, name='edit_category'),
|
||||
path('edit/keyword/<int:keyword_id>/', edit.keyword, name='edit_keyword'),
|
||||
|
||||
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
||||
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
|
||||
path('edit/monitor/<int:pk>/', edit.MonitorUpdate.as_view(), name='edit_monitor'),
|
||||
|
||||
path('batch/import', batch.batch_import, name='batch_import'),
|
||||
path('batch/category', batch.batch_edit, name='batch_edit'),
|
||||
|
||||
path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='get_file_link'),
|
||||
]
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
from django.http import HttpResponse
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from cookbook.models import Recipe
|
||||
from cookbook.helper import dropbox
|
||||
|
||||
|
||||
@login_required
|
||||
def get_file_link(request, recipe_id):
|
||||
recipe = Recipe.objects.get(id=recipe_id)
|
||||
if recipe.link == "":
|
||||
|
@ -1,9 +1,13 @@
|
||||
from datetime import datetime
|
||||
|
||||
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
|
||||
from cookbook.helper import dropbox
|
||||
from cookbook.models import Recipe, Category
|
||||
from cookbook.models import Recipe, Category, Monitor
|
||||
from cookbook.tables import MonitoredPathTable
|
||||
|
||||
|
||||
@login_required
|
||||
@ -11,12 +15,18 @@ def batch_import(request):
|
||||
if request.method == "POST":
|
||||
form = ImportForm(request.POST)
|
||||
if form.is_valid():
|
||||
dropbox.import_all(form.cleaned_data['path'])
|
||||
return redirect('index')
|
||||
new_path = Monitor()
|
||||
new_path.path = form.cleaned_data['path']
|
||||
new_path.last_checked = datetime.now()
|
||||
new_path.save()
|
||||
return redirect('batch_import')
|
||||
else:
|
||||
form = ImportForm()
|
||||
|
||||
return render(request, 'batch/import.html', {'form': form})
|
||||
monitored_paths = MonitoredPathTable(Monitor.objects.all())
|
||||
RequestConfig(request, paginate={'per_page': 25}).configure(monitored_paths)
|
||||
|
||||
return render(request, 'batch/import.html', {'form': form, 'monitored_paths': monitored_paths})
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -1,11 +1,31 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import redirect, render
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import UpdateView
|
||||
|
||||
from cookbook.forms import EditRecipeForm
|
||||
from cookbook.models import Recipe, Category
|
||||
from cookbook.models import Recipe, Category, Monitor, Keyword
|
||||
|
||||
|
||||
class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic\edit_template.html"
|
||||
model = Monitor
|
||||
fields = ['path']
|
||||
|
||||
|
||||
class CategoryUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic\edit_template.html"
|
||||
model = Category
|
||||
fields = ['name', 'description']
|
||||
|
||||
|
||||
class KeywordUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic\edit_template.html"
|
||||
model = Keyword
|
||||
fields = ['name', 'description']
|
||||
|
||||
|
||||
@login_required
|
||||
@ -28,13 +48,3 @@ def recipe(request, recipe_id):
|
||||
form = EditRecipeForm(instance=recipe_obj)
|
||||
|
||||
return render(request, 'edit/recipe.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def category(request, category_id):
|
||||
return render(request, 'index.html')
|
||||
|
||||
|
||||
@login_required
|
||||
def keyword(request, keyword_id):
|
||||
return render(request, 'index.html')
|
||||
|
@ -1,11 +1,9 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render, redirect
|
||||
from django.shortcuts import render
|
||||
from django_tables2 import RequestConfig
|
||||
|
||||
from cookbook.filters import RecipeFilter
|
||||
from cookbook.forms import *
|
||||
from cookbook.helper import dropbox
|
||||
from cookbook.tables import RecipeTable, CategoryTable, KeywordTable
|
||||
from cookbook.tables import RecipeTable
|
||||
|
||||
|
||||
def index(request):
|
||||
|
@ -98,7 +98,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = 'DE-de'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user