generic views

This commit is contained in:
vabene1111 2018-03-30 22:41:23 +02:00
parent 8c6019756f
commit 37639ad4c7
23 changed files with 113 additions and 247 deletions

2
.gitignore vendored
View File

@ -70,3 +70,5 @@ secret_settings\.py
*.sqlite3 *.sqlite3
\.idea/workspace\.xml \.idea/workspace\.xml
cookbook/migrations/

View File

@ -4,10 +4,11 @@
<facet type="django" name="Django"> <facet type="django" name="Django">
<configuration> <configuration>
<option name="rootFolder" value="$MODULE_DIR$" /> <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="manageScript" value="$MODULE_DIR$/manage.py" />
<option name="environment" value="&lt;map/&gt;" /> <option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" /> <option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="migrations" />
</configuration> </configuration>
</facet> </facet>
</component> </component>

View File

@ -91,7 +91,7 @@ class ImportForm(forms.Form):
super(ImportForm, self).__init__(*args, **kwargs) super(ImportForm, self).__init__(*args, **kwargs)
self.helper = FormHelper() self.helper = FormHelper()
self.helper.form_method = 'post' 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): class BatchEditForm(forms.Form):

View File

@ -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')),
],
),
]

View File

@ -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=''),
),
]

View File

@ -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,
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -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'),
),
]

View File

@ -39,3 +39,10 @@ class Recipe(models.Model):
@property @property
def all_tags(self): def all_tags(self):
return ', '.join([x.name for x in self.keywords.all()]) 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)

View File

@ -20,7 +20,7 @@ class RecipeTable(tables.Table):
class CategoryTable(tables.Table): class CategoryTable(tables.Table):
id = tables.LinkColumn('edit_recipe', args=[A('id')]) id = tables.LinkColumn('edit_category', args=[A('id')])
class Meta: class Meta:
model = Category model = Category
@ -29,9 +29,18 @@ class CategoryTable(tables.Table):
class KeywordTable(tables.Table): class KeywordTable(tables.Table):
id = tables.LinkColumn('edit_recipe', args=[A('id')]) id = tables.LinkColumn('edit_keyword', args=[A('id')])
class Meta: class Meta:
model = Keyword model = Keyword
template_name = 'generic/table_template.html' template_name = 'generic/table_template.html'
fields = ('id', 'name') 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')

View File

@ -9,11 +9,13 @@
<h3> <h3>
{% trans 'Import Recipes' %} {% 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> </h3>
<form method="POST" class="post-form">{% csrf_token %} <form method="POST" class="post-form">{% csrf_token %}
{% crispy form %} {% crispy form %}
</form> </form>
{% render_table monitored_paths %}
{% endblock %} {% endblock %}

View 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 %}

View 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 %}

View File

@ -12,11 +12,14 @@ urlpatterns = [
path('new/keyword', new.keyword, name='new_keyword'), path('new/keyword', new.keyword, name='new_keyword'),
path('edit/recipe/<int:recipe_id>/', edit.recipe, name='edit_recipe'), 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/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'),
path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='get_file_link'), path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='get_file_link'),
] ]

View File

@ -1,9 +1,12 @@
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from cookbook.models import Recipe from cookbook.models import Recipe
from cookbook.helper import dropbox from cookbook.helper import dropbox
@login_required
def get_file_link(request, recipe_id): def get_file_link(request, recipe_id):
recipe = Recipe.objects.get(id=recipe_id) recipe = Recipe.objects.get(id=recipe_id)
if recipe.link == "": if recipe.link == "":

View File

@ -1,9 +1,13 @@
from datetime import datetime
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 cookbook.forms import ImportForm, BatchEditForm from cookbook.forms import ImportForm, BatchEditForm
from cookbook.helper import dropbox 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 @login_required
@ -11,12 +15,18 @@ def batch_import(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():
dropbox.import_all(form.cleaned_data['path']) new_path = Monitor()
return redirect('index') new_path.path = form.cleaned_data['path']
new_path.last_checked = datetime.now()
new_path.save()
return redirect('batch_import')
else: else:
form = ImportForm() 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 @login_required

View File

@ -1,11 +1,31 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import UpdateView
from cookbook.forms import EditRecipeForm 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 @login_required
@ -28,13 +48,3 @@ def recipe(request, recipe_id):
form = EditRecipeForm(instance=recipe_obj) form = EditRecipeForm(instance=recipe_obj)
return render(request, 'edit/recipe.html', {'form': form}) 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')

View File

@ -1,11 +1,9 @@
from django.contrib.auth.decorators import login_required from django.shortcuts import render
from django.shortcuts import render, redirect
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from cookbook.filters import RecipeFilter from cookbook.filters import RecipeFilter
from cookbook.forms import * from cookbook.forms import *
from cookbook.helper import dropbox from cookbook.tables import RecipeTable
from cookbook.tables import RecipeTable, CategoryTable, KeywordTable
def index(request): def index(request):

View File

@ -98,7 +98,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ # https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'DE-de'
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'