From c9a46128dfb66509e2181ea07245ac666140b650 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 2 Feb 2022 11:41:29 +0100 Subject: [PATCH] Set page_title & fix breadcrumb --- ereuse_devicehub/inventory/views.py | 44 +++++++++++-------- .../templates/ereuse_devicehub/base_site.html | 1 + .../inventory/{tag.html => tag_create.html} | 4 +- ...agUnnamed.html => tag_create_unnamed.html} | 6 +-- .../{tag_details.html => tag_detail.html} | 5 +-- .../templates/inventory/tag_list.html | 3 +- 6 files changed, 35 insertions(+), 28 deletions(-) rename ereuse_devicehub/templates/inventory/{tag.html => tag_create.html} (92%) rename ereuse_devicehub/templates/inventory/{tagUnnamed.html => tag_create_unnamed.html} (91%) rename ereuse_devicehub/templates/inventory/{tag_details.html => tag_detail.html} (96%) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 3bd32a20..eeb9f2e3 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -7,8 +7,9 @@ from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, UploadSnapshotForm, \ - NewDeviceForm, TagForm, TagUnnamedForm, TagDeviceForm + NewDeviceForm, TagForm, TagUnnamedForm, TagDeviceForm +# TODO(@slamora): rename base 'inventory.devices' --> 'inventory' devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') @@ -44,14 +45,14 @@ class DeviceListView(View): return flask.render_template(self.template_name, **context) -class DeviceDetailsView(View): +class DeviceDetailView(View): decorators = [login_required] template_name = 'inventory/device_details.html' def dispatch_request(self, id): lots = Lot.query.filter(Lot.owner_id == current_user.id) device = Device.query.filter( - Device.owner_id == current_user.id).filter(Device.devicehub_id == id).one() + Device.owner_id == current_user.id).filter(Device.devicehub_id == id).one() context = {'device': device, 'lots': lots} @@ -168,54 +169,61 @@ class TagListView(View): template_name = 'inventory/tag_list.html' def dispatch_request(self): - tags = Tag.query.filter( - Tag.owner_id == current_user.id) - context = {'tags': tags, - 'lots': []} + tags = Tag.query.filter(Tag.owner_id == current_user.id) + context = { + 'lots': [], + 'tags': tags, + 'page_title': 'Tags Management', + } return flask.render_template(self.template_name, **context) class TagAddView(View): methods = ['GET', 'POST'] decorators = [login_required] - template_name = 'inventory/tag.html' + template_name = 'inventory/tag_create.html' def dispatch_request(self): + context = {'page_title': 'New Tag'} form = TagForm() if form.validate_on_submit(): form.save() next_url = url_for('inventory.devices.taglist') return flask.redirect(next_url) - return flask.render_template(self.template_name, form=form) + return flask.render_template(self.template_name, form=form, **context) class TagAddUnnamedView(View): methods = ['GET', 'POST'] decorators = [login_required] - template_name = 'inventory/tagUnnamed.html' + template_name = 'inventory/tag_create_unnamed.html' def dispatch_request(self): + context = {'page_title': 'New Unnamed Tag'} form = TagUnnamedForm() if form.validate_on_submit(): form.save() next_url = url_for('inventory.devices.taglist') return flask.redirect(next_url) - return flask.render_template(self.template_name, form=form) + return flask.render_template(self.template_name, form=form, **context) -class TagDetailsView(View): +class TagDetailView(View): decorators = [login_required] - template_name = 'inventory/tag_details.html' + template_name = 'inventory/tag_detail.html' def dispatch_request(self, id): lots = Lot.query.filter(Lot.owner_id == current_user.id) tag = Tag.query.filter( - Tag.owner_id == current_user.id).filter(Tag.id == id).one() + Tag.owner_id == current_user.id).filter(Tag.id == id).one() - context = {'tag': tag, - 'lots': lots} + context = { + 'lots': lots, + 'tag': tag, + 'page_title': '{} Tag'.format(tag.code), + } return flask.render_template(self.template_name, **context) @@ -249,7 +257,7 @@ class TagDeviceDeleteView(View): devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) -devices.add_url_rule('/device//', view_func=DeviceDetailsView.as_view('device_details')) +devices.add_url_rule('/device//', view_func=DeviceDetailView.as_view('device_details')) devices.add_url_rule('/lot//device/', view_func=DeviceListView.as_view('lotdevicelist')) devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add')) devices.add_url_rule('/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del')) @@ -261,6 +269,6 @@ devices.add_url_rule('/device/add/', view_func=CreateDeviceView.as_view('device_ devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist')) devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add')) devices.add_url_rule('/tag/unnamed/add/', view_func=TagAddUnnamedView.as_view('tag_unnamed_add')) -devices.add_url_rule('/tag//', view_func=TagDetailsView.as_view('tag_details')) +devices.add_url_rule('/tag//', view_func=TagDetailView.as_view('tag_details')) devices.add_url_rule('/tag/devices/add/', view_func=TagDeviceAddView.as_view('tag_devices_add')) devices.add_url_rule('/tag/devices//del/', view_func=TagDeviceDeleteView.as_view('tag_devices_del')) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index 477f79c0..99cf0cf5 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -1,4 +1,5 @@ {% extends "ereuse_devicehub/base.html" %} +{% block page_title %}{{ page_title }}{% endblock %} {% block body %}