Merge branch 'feature/server-side-render' into feature/server-side-render-tags
This commit is contained in:
commit
0f30bbda35
|
@ -67,9 +67,6 @@ class Devicehub(Teal):
|
|||
self.configure_extensions()
|
||||
|
||||
def configure_extensions(self):
|
||||
# configure & enable CSRF of Flask-WTF
|
||||
CSRFProtect(self)
|
||||
|
||||
# configure Flask-Login
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(self)
|
||||
|
|
|
@ -35,13 +35,10 @@ class LotDeviceForm(FlaskForm):
|
|||
Lot.owner_id == g.user.id).one()
|
||||
|
||||
devices = set(self.devices.data.split(","))
|
||||
self._devices = set(Device.query.filter(Device.id.in_(devices)).filter(
|
||||
Device.owner_id == g.user.id).all())
|
||||
self._devices = Device.query.filter(Device.id.in_(devices)).filter(
|
||||
Device.owner_id == g.user.id).distinct().all()
|
||||
|
||||
if not self._devices:
|
||||
return False
|
||||
|
||||
return True
|
||||
return bool(self._devices)
|
||||
|
||||
def save(self):
|
||||
self._lot.devices.update(self._devices)
|
||||
|
|
|
@ -68,7 +68,8 @@ class LotDeviceAddView(View):
|
|||
if form.validate_on_submit():
|
||||
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):
|
||||
|
@ -81,8 +82,8 @@ class LotDeviceDeleteView(View):
|
|||
if form.validate_on_submit():
|
||||
form.remove()
|
||||
|
||||
# TODO @cayop It's possible this redirect not work in production
|
||||
return flask.redirect(request.referrer)
|
||||
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||
return flask.redirect(next_url)
|
||||
|
||||
|
||||
class LotCreateView(View):
|
||||
|
|
|
@ -102,19 +102,15 @@ class Lot(Thing):
|
|||
|
||||
@property
|
||||
def is_temporary(self):
|
||||
return False if self.trade else True
|
||||
return not bool(self.trade)
|
||||
|
||||
@property
|
||||
def is_incominig(self):
|
||||
if self.trade and self.trade.user_to == current_user:
|
||||
return True
|
||||
return False
|
||||
def is_incoming(self):
|
||||
return bool(self.trade and self.trade.user_to == current_user)
|
||||
|
||||
@property
|
||||
def is_outgoing(self):
|
||||
if self.trade and self.trade.user_from == current_user:
|
||||
return True
|
||||
return False
|
||||
return bool(self.trade and self.trade.user_from == current_user)
|
||||
|
||||
@classmethod
|
||||
def descendantsq(cls, id):
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
</a>
|
||||
<ul id="incoming-lots-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav">
|
||||
{% for lot in lots %}
|
||||
{% if lot.is_incominig %}
|
||||
{% if lot.is_incoming %}
|
||||
<li>
|
||||
<a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}">
|
||||
<i class="bi bi-circle"></i><span>{{ lot.name }}</span>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{% elif lot.is_temporary %}
|
||||
<li class="breadcrumb-item active">Temporary Lot</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">{{ lot.name }}</li>
|
||||
{% elif lot.is_outgoing %}
|
||||
|
|
|
@ -1,9 +1,22 @@
|
|||
from ereuse_devicehub.devicehub import Devicehub
|
||||
|
||||
"""
|
||||
Example app with minimal configuration.
|
||||
|
||||
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)
|
||||
|
|
Reference in a new issue