added history page

This commit is contained in:
vabene1111
2020-05-11 12:59:54 +02:00
parent 5ad27c015e
commit f6aa50bbfc
6 changed files with 66 additions and 4 deletions

View File

@ -106,3 +106,21 @@ class RecipeImportTable(tables.Table):
model = RecipeImport
template_name = 'generic/table_template.html'
fields = ('id', 'name', 'file_path')
class ViewLogTable(tables.Table):
recipe = tables.LinkColumn('view_recipe', args=[A('recipe_id')])
class Meta:
model = ViewLog
template_name = 'generic/table_template.html'
fields = ('recipe', 'created_at')
class CookLogTable(tables.Table):
recipe = tables.LinkColumn('view_recipe', args=[A('recipe_id')])
class Meta:
model = CookLog
template_name = 'generic/table_template.html'
fields = ('recipe', 'rating', 'serving', 'created_at')

View File

@ -128,7 +128,7 @@
<ul class="navbar-nav ml-auto">
{% if user.is_authenticated %}
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_settings' %}active{% endif %}">
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_settings,view_history' %}active{% endif %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false"><i
class="fas fa-user-alt"></i> {{ user.get_user_name }}
@ -137,6 +137,7 @@
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="{% url 'view_settings' %}"><i
class="fas fa-user-cog fa-fw"></i> {% trans 'Settings' %}</a>
<a class="dropdown-item" href="{% url 'view_history' %}"><i class="fas fa-history"></i> {% trans 'History' %}</a>
{% if user.is_superuser %}
<a class="dropdown-item" href="{% url 'admin:index' %}"><i
class="fas fa-user-shield fa-fw"></i> {% trans 'Admin' %}</a>

View File

@ -0,0 +1,37 @@
{% extends "base.html" %}
{% load django_tables2 %}
{% load static %}
{% load i18n %}
{% block title %}{% trans "History" %}{% endblock %}
{% block extra_head %}
{% endblock %}
{% block content %}
<h3>{% trans 'History' %}</h3>
<br/>
<ul class="nav nav-tabs" id="id_tab_nav" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#view_log" role="tab" aria-controls="view_log"
aria-selected="true">{% trans 'View Log' %}</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#cook_log" role="tab" aria-controls="cook_log"
aria-selected="false">{% trans 'Cook Log' %}</a>
</li>
</ul>
<div class="tab-content" id="id_tab_content">
<div class="tab-pane fade show active" id="view_log" role="tabpanel" aria-labelledby="view-log">
{% render_table view_log %}
</div>
<div class="tab-pane fade" id="cook_log" role="tabpanel" aria-labelledby="profile-tab">
{% render_table cook_log %}
</div>
</div>
{% endblock %}

View File

@ -83,7 +83,6 @@
<h4>{% trans 'Recips' %}</h4>
{% endif %}
{% if user.is_authenticated and recipes %}
{% render_table recipes %}
{% else %}

View File

@ -14,6 +14,7 @@ urlpatterns = [
path('plan/entry/<int:pk>', views.meal_plan_entry, name='view_plan_entry'),
path('shopping/', views.shopping_list, name='view_shopping'),
path('settings/', views.settings, name='view_settings'),
path('history/', views.history, name='view_history'),
path('import/', import_export.import_recipe, name='view_import'),
path('export/', import_export.export_recipe, name='view_export'),

View File

@ -15,7 +15,7 @@ from django.utils.translation import gettext as _
from cookbook.filters import RecipeFilter
from cookbook.forms import *
from cookbook.helper.permission_helper import group_required
from cookbook.tables import RecipeTable, RecipeTableSmall
from cookbook.tables import RecipeTable, RecipeTableSmall, CookLogTable, ViewLogTable
def index(request):
@ -242,5 +242,11 @@ def settings(request):
return render(request, 'settings.html', {'preference_form': preference_form, 'user_name_form': user_name_form, 'password_form': password_form})
def history(request):
view_log = ViewLogTable(ViewLog.objects.filter(created_by=request.user).order_by('-created_at').all())
cook_log = CookLogTable(CookLog.objects.filter(created_by=request.user).order_by('-created_at').all())
return render(request, 'history.html', {'view_log': view_log, 'cook_log': cook_log})
def markdown_info(request):
return render(request, 'markdown_info.html', {})