From 1feb287ca021c1b5578f0664015ee7a13edfb936 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 11:13:30 +0100 Subject: [PATCH 01/67] SECRET_KEY in config --- ereuse_devicehub/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index 01a98292..e1e5cf12 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -1,3 +1,4 @@ +import os from distutils.version import StrictVersion from itertools import chain from typing import Set @@ -77,3 +78,4 @@ class DevicehubConfig(Config): """Definition of path where save the documents of customers""" PATH_DOCUMENTS_STORAGE = config('PATH_DOCUMENTS_STORAGE', '/tmp/') JWT_PASS = config('JWT_PASS', '') + SECRET_KEY = os.urandom(32) From fb81edf799f2e065cabff2bcf04f89493cac161f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 11:45:53 +0100 Subject: [PATCH 02/67] insert LoginManager in devicehub app --- ereuse_devicehub/devicehub.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ereuse_devicehub/devicehub.py b/ereuse_devicehub/devicehub.py index a15e484a..ea951472 100644 --- a/ereuse_devicehub/devicehub.py +++ b/ereuse_devicehub/devicehub.py @@ -6,6 +6,7 @@ import boltons.urlutils import click import click_spinner import ereuse_utils.cli +from flask_login import LoginManager from ereuse_utils.session import DevicehubClient from flask.globals import _app_ctx_stack, g from flask_sqlalchemy import SQLAlchemy @@ -26,6 +27,7 @@ class Devicehub(Teal): test_client_class = Client Dummy = Dummy jinja_environment = Environment + login_manager = LoginManager() def __init__(self, inventory: str, From 8aa997a2f6858b1bc496e4b22960eaad99fef661 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 11:46:17 +0100 Subject: [PATCH 03/67] comment decorators --- ereuse_devicehub/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 3c5b28d0..1a458345 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -32,8 +32,10 @@ class LoginView(View): return flask.render_template('ereuse_devicehub/user_login.html', form=form) +from flask import g, current_app as app + class UserProfileView(View): - decorators = [login_required] + # decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html' def dispatch_request(self): From ed48df70db185e7056f3e3f5cd300f80b2907f27 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 12:36:02 +0100 Subject: [PATCH 04/67] adding templates for inventory1 --- ereuse_devicehub/inventory/__init__.py | 0 .../inventory/devices/__init__.py | 0 ereuse_devicehub/inventory/devices/views.py | 22 ++ .../templates/inventory/device_list.html | 273 ++++++++++++++++++ ereuse_devicehub/views.py | 2 - 5 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 ereuse_devicehub/inventory/__init__.py create mode 100644 ereuse_devicehub/inventory/devices/__init__.py create mode 100644 ereuse_devicehub/inventory/devices/views.py create mode 100644 ereuse_devicehub/templates/inventory/device_list.html diff --git a/ereuse_devicehub/inventory/__init__.py b/ereuse_devicehub/inventory/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ereuse_devicehub/inventory/devices/__init__.py b/ereuse_devicehub/inventory/devices/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ereuse_devicehub/inventory/devices/views.py b/ereuse_devicehub/inventory/devices/views.py new file mode 100644 index 00000000..8646f09c --- /dev/null +++ b/ereuse_devicehub/inventory/devices/views.py @@ -0,0 +1,22 @@ +import flask +from flask import Blueprint +from flask.views import View +from flask_login import login_required, login_user + +from ereuse_devicehub.forms import LoginForm +from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.utils import is_safe_url + +devices = Blueprint('devices', __name__) + + +class DeviceListView(View): + # decorators = [login_required] + template_name = 'inventory/device_list.html' + + def dispatch_request(self): + context = {} + return flask.render_template(self.template_name, **context) + + +devices.add_url_rule('/inventory/device/list/', view_func=DeviceListView.as_view('devicelist')) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html new file mode 100644 index 00000000..4ea12a71 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -0,0 +1,273 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + +
+

Inventory

+ +
+ +
+
+ +
+ +
+
+ + +
+ +
+ +
Computers
+ +
+
Full Name
+
Kevin Anderson
+
+ +
+
Company
+
Lueilwitz, Wisoky and Leuschke
+
+ +
+
Job
+
Web Designer
+
+ +
+
Country
+
USA
+
+ +
+
Address
+
A108 Adam Street, New York, NY 535022
+
+ +
+
Phone
+
(436) 486-3538 x29071
+
+ +
+
Email
+
k.anderson@example.com
+
+ +
+ +
+ + +
+
+ +
+ Profile +
+ + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ + +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+{% endblock main %} diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 1a458345..2549ec54 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -32,8 +32,6 @@ class LoginView(View): return flask.render_template('ereuse_devicehub/user_login.html', form=form) -from flask import g, current_app as app - class UserProfileView(View): # decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html' From 9e042125a313d0fe8651f6bbe00bf22cf1921eab Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 13:55:26 +0100 Subject: [PATCH 05/67] clean configs --- ereuse_devicehub/config.py | 2 -- ereuse_devicehub/devicehub.py | 2 -- ereuse_devicehub/views.py | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index 5c25e43b..d1f89896 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -1,4 +1,3 @@ -import os from distutils.version import StrictVersion from itertools import chain from typing import Set @@ -79,4 +78,3 @@ class DevicehubConfig(Config): """Definition of path where save the documents of customers""" PATH_DOCUMENTS_STORAGE = config('PATH_DOCUMENTS_STORAGE', '/tmp/') JWT_PASS = config('JWT_PASS', '') - SECRET_KEY = os.urandom(32) diff --git a/ereuse_devicehub/devicehub.py b/ereuse_devicehub/devicehub.py index b3ed0eba..b4321e28 100644 --- a/ereuse_devicehub/devicehub.py +++ b/ereuse_devicehub/devicehub.py @@ -6,7 +6,6 @@ import boltons.urlutils import click import click_spinner import ereuse_utils.cli -from flask_login import LoginManager from ereuse_utils.session import DevicehubClient from flask.globals import _app_ctx_stack, g from flask_sqlalchemy import SQLAlchemy @@ -32,7 +31,6 @@ class Devicehub(Teal): test_client_class = Client Dummy = Dummy jinja_environment = Environment - login_manager = LoginManager() def __init__(self, inventory: str, diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 2549ec54..3c5b28d0 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -33,7 +33,7 @@ class LoginView(View): class UserProfileView(View): - # decorators = [login_required] + decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html' def dispatch_request(self): From c8be2bb6404a069ea50d635f5c24507413ceba57 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 13:55:56 +0100 Subject: [PATCH 06/67] adding rendering list --- ereuse_devicehub/inventory/devices/views.py | 19 +++++--- .../templates/ereuse_devicehub/base_site.html | 2 +- .../templates/inventory/device_list.html | 44 +++++++------------ 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/ereuse_devicehub/inventory/devices/views.py b/ereuse_devicehub/inventory/devices/views.py index 8646f09c..7b028145 100644 --- a/ereuse_devicehub/inventory/devices/views.py +++ b/ereuse_devicehub/inventory/devices/views.py @@ -1,22 +1,27 @@ import flask from flask import Blueprint from flask.views import View -from flask_login import login_required, login_user +from flask_login import login_required, current_user -from ereuse_devicehub.forms import LoginForm -from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.utils import is_safe_url -devices = Blueprint('devices', __name__) +devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') class DeviceListView(View): - # decorators = [login_required] + decorators = [login_required] template_name = 'inventory/device_list.html' def dispatch_request(self): - context = {} + # import pdb; pdb.set_trace() + filter_types = ['Desktop', 'Laptop', 'Server'] + devices = Device.query.filter( + Device.owner_id==current_user.id).filter( + Device.type.in_(filter_types)) + + context = {'devices': devices} return flask.render_template(self.template_name, **context) -devices.add_url_rule('/inventory/device/list/', view_func=DeviceListView.as_view('devicelist')) +devices.add_url_rule('/device/list/', view_func=DeviceListView.as_view('devicelist')) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index b68d5635..f233903d 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -242,7 +242,7 @@