skeleton for trade action
This commit is contained in:
parent
f2d6c198cc
commit
cd16baaadb
|
@ -619,3 +619,14 @@ class DataWipeForm(NewActionForm):
|
|||
self.document = document
|
||||
|
||||
return self.instance
|
||||
|
||||
|
||||
class TradeForm(NewActionForm):
|
||||
supplier = StringField(u'Supplier', [validators.DataRequired()],
|
||||
description="Please enter the supplier's email address")
|
||||
receiver = StringField(u'Receiver', [validators.DataRequired()],
|
||||
description="Please enter the receiver's email address")
|
||||
confirm = BooleanField(u'Confirm', [validators.Optional()],
|
||||
description="I need confirmation from the other user for every device and document.")
|
||||
code = StringField(u'Code', [validators.Optional()],
|
||||
description="If you don't need confirm, you need put a code for trace the user in the statistics.")
|
||||
|
|
|
@ -8,7 +8,8 @@ from ereuse_devicehub.inventory.forms import (AllocateForm, LotDeviceForm,
|
|||
LotForm, NewActionForm,
|
||||
NewDeviceForm, TagDeviceForm,
|
||||
TagForm, TagUnnamedForm,
|
||||
UploadSnapshotForm, DataWipeForm)
|
||||
UploadSnapshotForm, DataWipeForm,
|
||||
TradeForm)
|
||||
from ereuse_devicehub.resources.device.models import Device
|
||||
from ereuse_devicehub.resources.lot.models import Lot
|
||||
from ereuse_devicehub.resources.tag.model import Tag
|
||||
|
@ -37,6 +38,7 @@ class DeviceListMix(View):
|
|||
form_new_action = NewActionForm(lot=lot.id)
|
||||
form_new_allocate = AllocateForm(lot=lot.id)
|
||||
form_new_datawipe = DataWipeForm(lot=lot.id)
|
||||
form_new_trade = TradeForm(lot=lot.id)
|
||||
else:
|
||||
devices = Device.query.filter(
|
||||
Device.owner_id == current_user.id).filter(
|
||||
|
@ -45,6 +47,7 @@ class DeviceListMix(View):
|
|||
form_new_action = NewActionForm()
|
||||
form_new_allocate = AllocateForm()
|
||||
form_new_datawipe = DataWipeForm()
|
||||
form_new_trade = TradeForm()
|
||||
|
||||
action_devices = form_new_action.devices.data
|
||||
list_devices = []
|
||||
|
@ -59,6 +62,7 @@ class DeviceListMix(View):
|
|||
'form_new_action': form_new_action,
|
||||
'form_new_allocate': form_new_allocate,
|
||||
'form_new_datawipe': form_new_datawipe,
|
||||
'form_new_trade': form_new_trade,
|
||||
'lot': lot,
|
||||
'tags': tags,
|
||||
'list_devices': list_devices
|
||||
|
@ -354,7 +358,28 @@ class NewDataWipeView(NewActionView, DeviceListMix):
|
|||
return flask.render_template(self.template_name, **self.context)
|
||||
|
||||
|
||||
class NewTradeView(NewActionView, DeviceListMix):
|
||||
methods = ['POST']
|
||||
form_class = TradeForm
|
||||
|
||||
def dispatch_request(self):
|
||||
self.form = self.form_class()
|
||||
|
||||
if self.form.validate_on_submit():
|
||||
instance = self.form.save()
|
||||
messages.success('Action "{}" created successfully!'.format(instance.type))
|
||||
|
||||
next_url = self.get_next_url()
|
||||
return flask.redirect(next_url)
|
||||
|
||||
lot_id = self.form.lot.data
|
||||
self.get_context(lot_id)
|
||||
self.context['form_new_datawipe'] = self.form
|
||||
return flask.render_template(self.template_name, **self.context)
|
||||
|
||||
|
||||
devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add'))
|
||||
devices.add_url_rule('/action/trade/add/', view_func=NewTradeView.as_view('trade_add'))
|
||||
devices.add_url_rule('/action/allocate/add/', view_func=NewAllocateView.as_view('allocate_add'))
|
||||
devices.add_url_rule('/action/datawipe/add/', view_func=NewDataWipeView.as_view('datawipe_add'))
|
||||
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
||||
|
|
|
@ -44,20 +44,22 @@
|
|||
<!-- Bordered Tabs -->
|
||||
|
||||
<div class="btn-group dropdown ml-1">
|
||||
{% if lot and lot.is_temporary and not lot.devices %}
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="modal" data-bs-target="#btnRemoveLots">
|
||||
<i class="bi bi-trash"></i>
|
||||
Remove Lot
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
{% else %}
|
||||
<button id="btnLots" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-folder2"></i>
|
||||
Lots
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
{% endif %}
|
||||
<ul class="dropdown-menu" aria-labelledby="btnLots">
|
||||
{% if lot and lot.is_temporary and not lot.devices %}
|
||||
<li>
|
||||
<a href="javascript:newAction('Use')" class="dropdown-item"
|
||||
data-bs-toggle="modal" data-bs-target="#btnRemoveLots">
|
||||
<i class="bi bi-trash"></i>
|
||||
Remove Lot
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="javascript:void()" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#addingLotModal">
|
||||
<i class="bi bi-plus"></i>
|
||||
|
@ -70,6 +72,22 @@
|
|||
Remove selected devices from a lot
|
||||
</a>
|
||||
</li>
|
||||
{% if lot.is_temporary %}
|
||||
<li>
|
||||
<a href="javascript:void()" class="dropdown-item"
|
||||
data-bs-toggle="modal" data-bs-target="#tradeLotModal">
|
||||
<i class="bi bi-plus"></i>
|
||||
Add supplier
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void()" class="dropdown-item"
|
||||
data-bs-toggle="modal" data-bs-target="#tradeLotModal">
|
||||
<i class="bi bi-plus"></i>
|
||||
Add receiver
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
@ -282,6 +300,7 @@
|
|||
{% include "inventory/actions.html" %}
|
||||
{% include "inventory/allocate.html" %}
|
||||
{% include "inventory/data_wipe.html" %}
|
||||
{% include "inventory/trade.html" %}
|
||||
|
||||
<!-- CDN -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest"></script>
|
||||
|
|
59
ereuse_devicehub/templates/inventory/trade.html
Normal file
59
ereuse_devicehub/templates/inventory/trade.html
Normal file
|
@ -0,0 +1,59 @@
|
|||
<div class="modal fade" id="tradeLotModal" tabindex="-1" style="display: none;" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">New Action <span id="title-action"></span></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<form action="{{ url_for('inventory.devices.trade_add') }}" method="post">
|
||||
{{ form_new_trade.csrf_token }}
|
||||
<div class="modal-body">
|
||||
{% for field in form_new_trade %}
|
||||
{% if field != form_new_trade.csrf_token %}
|
||||
{% if field == form_new_trade.devices %}
|
||||
<div class="col-12">
|
||||
{{ field.label(class_="form-label") }}: <span class="devices-count"></span>
|
||||
{{ field(class_="devicesList") }}
|
||||
<p class="enumeration-devices"></p>
|
||||
</div>
|
||||
{% elif field == form_new_trade.lot %}
|
||||
{{ field }}
|
||||
{% elif field == form_new_trade.type %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
<div class="col-12">
|
||||
{{ field.label(class_="form-label") }}
|
||||
{% if field == form_new_trade.confirm %}
|
||||
<div class="form-check form-switch">
|
||||
{{ field(class_="form-check-input") }}
|
||||
<small class="text-muted">{{ field.description }}</small>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ field(class_="form-control") }}
|
||||
<small class="text-muted">{{ field.description }}</small>
|
||||
{% endif %}
|
||||
{% if field.errors %}
|
||||
<p class="text-danger">
|
||||
{% for error in field.errors %}
|
||||
{{ error }}<br/>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<input type="submit" class="btn btn-primary" value="Create" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in a new issue