Merge branch 'feature/server-side-render' into feature/server-side-render-tags

This commit is contained in:
Cayo Puigdefabregas 2022-01-26 13:16:56 +01:00
commit 0f30bbda35
7 changed files with 29 additions and 25 deletions

View File

@ -67,9 +67,6 @@ class Devicehub(Teal):
self.configure_extensions() self.configure_extensions()
def configure_extensions(self): def configure_extensions(self):
# configure & enable CSRF of Flask-WTF
CSRFProtect(self)
# configure Flask-Login # configure Flask-Login
login_manager = LoginManager() login_manager = LoginManager()
login_manager.init_app(self) login_manager.init_app(self)

View File

@ -35,13 +35,10 @@ class LotDeviceForm(FlaskForm):
Lot.owner_id == g.user.id).one() Lot.owner_id == g.user.id).one()
devices = set(self.devices.data.split(",")) devices = set(self.devices.data.split(","))
self._devices = set(Device.query.filter(Device.id.in_(devices)).filter( self._devices = Device.query.filter(Device.id.in_(devices)).filter(
Device.owner_id == g.user.id).all()) Device.owner_id == g.user.id).distinct().all()
if not self._devices: return bool(self._devices)
return False
return True
def save(self): def save(self):
self._lot.devices.update(self._devices) self._lot.devices.update(self._devices)

View File

@ -68,7 +68,8 @@ class LotDeviceAddView(View):
if form.validate_on_submit(): if form.validate_on_submit():
form.save() form.save()
return flask.redirect(request.referrer) next_url = request.referrer or url_for('inventory.devices.devicelist')
return flask.redirect(next_url)
class LotDeviceDeleteView(View): class LotDeviceDeleteView(View):
@ -81,8 +82,8 @@ class LotDeviceDeleteView(View):
if form.validate_on_submit(): if form.validate_on_submit():
form.remove() form.remove()
# TODO @cayop It's possible this redirect not work in production next_url = request.referrer or url_for('inventory.devices.devicelist')
return flask.redirect(request.referrer) return flask.redirect(next_url)
class LotCreateView(View): class LotCreateView(View):

View File

@ -102,19 +102,15 @@ class Lot(Thing):
@property @property
def is_temporary(self): def is_temporary(self):
return False if self.trade else True return not bool(self.trade)
@property @property
def is_incominig(self): def is_incoming(self):
if self.trade and self.trade.user_to == current_user: return bool(self.trade and self.trade.user_to == current_user)
return True
return False
@property @property
def is_outgoing(self): def is_outgoing(self):
if self.trade and self.trade.user_from == current_user: return bool(self.trade and self.trade.user_from == current_user)
return True
return False
@classmethod @classmethod
def descendantsq(cls, id): def descendantsq(cls, id):

View File

@ -103,7 +103,7 @@
</a> </a>
<ul id="incoming-lots-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav"> <ul id="incoming-lots-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav">
{% for lot in lots %} {% for lot in lots %}
{% if lot.is_incominig %} {% if lot.is_incoming %}
<li> <li>
<a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}"> <a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}">
<i class="bi bi-circle"></i><span>{{ lot.name }}</span> <i class="bi bi-circle"></i><span>{{ lot.name }}</span>

View File

@ -12,7 +12,7 @@
{% elif lot.is_temporary %} {% elif lot.is_temporary %}
<li class="breadcrumb-item active">Temporary Lot</li> <li class="breadcrumb-item active">Temporary Lot</li>
<li class="breadcrumb-item active">{{ lot.name }}</li> <li class="breadcrumb-item active">{{ lot.name }}</li>
{% elif lot.is_incominig %} {% elif lot.is_incoming %}
<li class="breadcrumb-item active">Incoming Lot</li> <li class="breadcrumb-item active">Incoming Lot</li>
<li class="breadcrumb-item active">{{ lot.name }}</li> <li class="breadcrumb-item active">{{ lot.name }}</li>
{% elif lot.is_outgoing %} {% elif lot.is_outgoing %}

View File

@ -1,9 +1,22 @@
from ereuse_devicehub.devicehub import Devicehub
""" """
Example app with minimal configuration. Example app with minimal configuration.
Use this as a starting point. Use this as a starting point.
""" """
from flask_wtf.csrf import CSRFProtect
app = Devicehub(inventory='db1') from ereuse_devicehub.config import DevicehubConfig
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.inventory.views import devices
from ereuse_devicehub.views import core
app = Devicehub(inventory=DevicehubConfig.DB_SCHEMA)
app.register_blueprint(core)
app.register_blueprint(devices)
# configure & enable CSRF of Flask-WTF
# NOTE: enable by blueprint to exclude API views
# TODO(@slamora: enable by default & exclude API views when decouple of Teal is completed
csrf = CSRFProtect(app)
csrf.protect(core)
csrf.protect(devices)