diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6c0439b0e..2bccfc449 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,17 @@ + + + + + + + + + @@ -232,7 +260,7 @@ - + @@ -300,9 +328,9 @@ - - - + + + @@ -330,22 +358,6 @@ - - - - - - - - - - - - - - - - @@ -419,7 +431,7 @@ - + @@ -437,7 +449,7 @@ - + @@ -586,32 +598,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -619,14 +605,6 @@ - - - - - - - - @@ -648,6 +626,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -656,60 +702,46 @@ - + - - - - - - - - - - - - - - - - + + - + - - + + - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + diff --git a/Recipies/settings.py b/Recipies/settings.py index 7ccb2aafa..8ca53560b 100644 --- a/Recipies/settings.py +++ b/Recipies/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django_tables2', + 'django_filters', 'cookbook.apps.CookbookConfig', ] diff --git a/Recipies/urls.py b/Recipies/urls.py index 2879f849b..ac2ff337e 100644 --- a/Recipies/urls.py +++ b/Recipies/urls.py @@ -13,11 +13,12 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.http import HttpResponseRedirect from django.urls import include, path from django.contrib import admin - urlpatterns = [ + path('', lambda r: HttpResponseRedirect('cookbook/')), path('admin/', admin.site.urls), path('cookbook/', include('cookbook.urls')), path('accounts/', include('django.contrib.auth.urls')), diff --git a/cookbook/filters.py b/cookbook/filters.py new file mode 100644 index 000000000..598c03277 --- /dev/null +++ b/cookbook/filters.py @@ -0,0 +1,11 @@ +import django_filters + +from cookbook.models import Recipe + + +class RecipeFilter(django_filters.FilterSet): + name = django_filters.CharFilter(lookup_expr='iexact') + + class Meta: + model = Recipe + fields = ['name', 'category', 'keywords'] diff --git a/cookbook/forms.py b/cookbook/forms.py index 9de95560b..642dd4f4d 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -54,3 +54,5 @@ class KeywordForm(forms.ModelForm): super(KeywordForm, self).__init__(*args, **kwargs) self.fields['name'].widget.attrs.update({'class': 'form-control'}) self.fields['description'].widget.attrs.update({'class': 'form-control'}) + + diff --git a/cookbook/locale/de/LC_MESSAGES/django.po b/cookbook/locale/de/LC_MESSAGES/django.po new file mode 100644 index 000000000..e211a2fae --- /dev/null +++ b/cookbook/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,27 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-01 11:27+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: .\templates\index.html:10 +msgid "Cookbook" +msgstr "Kochbuch" + +#: .\templates\index.html:17 +msgid "Log in to view Recipies" +msgstr "Log dich ein um die Rezepte zu sehen" diff --git a/cookbook/locale/en/LC_MESSAGES/django.po b/cookbook/locale/en/LC_MESSAGES/django.po new file mode 100644 index 000000000..16062e830 --- /dev/null +++ b/cookbook/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,27 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-01 11:27+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: .\templates\index.html:10 +msgid "Cookbook" +msgstr "" + +#: .\templates\index.html:17 +msgid "Log in to view Recipies" +msgstr "" diff --git a/cookbook/tables.py b/cookbook/tables.py index 99c256086..c06a854d7 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -1,4 +1,5 @@ import django_tables2 as tables + from .models import * diff --git a/cookbook/templates/index.html b/cookbook/templates/index.html index 7025b430e..2ef3724a1 100644 --- a/cookbook/templates/index.html +++ b/cookbook/templates/index.html @@ -2,19 +2,31 @@ {% load django_tables2 %} {% load i18n %} -{% block title %}Rezepte{% endblock %} +{% block title %}{% trans "Cookbook" %}{% endblock %} {% block content %} -

- {% trans "Cookbook" %} -

+
+
+ {% trans "Search" %} +
+
+
+ {{ filter.form.as_p }} + +
+ {% for obj in filter.qs %} + {{ obj.name }} - ${{ obj.price }}
+ {% endfor %} +
+
+
{% if recipes %} - {% render_table recipes %} + {% render_table table %} {% else %} {% endif %} diff --git a/cookbook/templates/registration/login.html b/cookbook/templates/registration/login.html index 4627346b8..e67fc2118 100644 --- a/cookbook/templates/registration/login.html +++ b/cookbook/templates/registration/login.html @@ -1,35 +1,50 @@ {% extends "base.html" %} +{% load i18n %} {% block content %} -{% if form.errors %} -

Your username and password didn't match. Please try again.

-{% endif %} + {% if form.errors %} + -{% if next %} - {% if user.is_authenticated %} -

Your account doesn't have access to this page. To proceed, - please login with an account that has access.

- {% else %} -

Please login to see this page.

{% endif %} -{% endif %} -
-{% csrf_token %} - - - - - - - - - -
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
- - -
+
+ {% csrf_token %} +
+ +
+ +
+ +
+ {% if form.username.errors %} + + {% endif %} +
+ +
+ +
+ +
+ {% if form.password.errors %} + + {% endif %} +
+ + + +
+
+ {% endblock %} \ No newline at end of file diff --git a/cookbook/templates/tables/table_template.html b/cookbook/templates/tables/table_template.html index 18d01d379..3ba9992d3 100644 --- a/cookbook/templates/tables/table_template.html +++ b/cookbook/templates/tables/table_template.html @@ -68,7 +68,7 @@
    {% block pagination.allpages %}
  • - {% blocktrans %}{% endblocktrans %} +
  • {% for page in table.paginator.page_range %} {% with range_start=current_page|add:"-3" range_end=current_page|add:"3" page_count_minus_5=page_count|add:"-5" page_count_minus_1=page_count|add:"-1" %} diff --git a/cookbook/views.py b/cookbook/views.py index f9f8b7eeb..eb980bae3 100644 --- a/cookbook/views.py +++ b/cookbook/views.py @@ -2,15 +2,20 @@ from django.utils.translation import gettext as _ from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect from django_tables2 import RequestConfig + +from cookbook.filters import RecipeFilter from cookbook.forms import * from cookbook.tables import RecipeTable def index(request): if request.user.is_authenticated: - table = RecipeTable(Recipe.objects.all()) + f = RecipeFilter(request.GET, queryset=Recipe.objects.all()) + + table = RecipeTable(f.queryset) RequestConfig(request, paginate={'per_page': 3}).configure(table) - return render(request, 'index.html', {'recipes': table}) + + return render(request, 'index.html', {'recipes': table, 'filter': f}) else: return render(request, 'index.html') diff --git a/db.sqlite3 b/db.sqlite3 index af973a2d0..ba12d5b55 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ