add number of devices to be created

This commit is contained in:
Cayo Puigdefabregas 2022-06-29 13:40:00 +02:00
parent ce2694f229
commit 3e2ed58b07
3 changed files with 24 additions and 5 deletions

View File

@ -403,7 +403,7 @@ class NewDeviceForm(FlaskForm):
self.meid.errors = error self.meid.errors = error
is_valid = False is_valid = False
if self.phid.data: if self.phid.data and self.amount.data == 1:
dev = Device.query.filter_by( dev = Device.query.filter_by(
hid=self.phid.data, owner=g.user, active=True hid=self.phid.data, owner=g.user, active=True
).first() ).first()
@ -427,6 +427,16 @@ class NewDeviceForm(FlaskForm):
return True return True
def save(self, commit=True): def save(self, commit=True):
if self.amount.data > 1:
self.phid.data = None
for n in range(self.amount.data):
self.create_device()
if commit:
db.session.commit()
def create_device(self):
json_snapshot = { json_snapshot = {
'type': 'Snapshot', 'type': 'Snapshot',
@ -494,8 +504,6 @@ class NewDeviceForm(FlaskForm):
snapshot.device.resolution = self.resolution.data snapshot.device.resolution = self.resolution.data
snapshot.device.screen = self.screen.data snapshot.device.screen = self.screen.data
if commit:
db.session.commit()
return snapshot return snapshot
def get_placeholder(self): def get_placeholder(self):

View File

@ -1,6 +1,8 @@
$(document).ready(() => { $(document).ready(() => {
$("#type").on("change", deviceInputs); $("#type").on("change", deviceInputs);
$("#amount").on("change", amountInputs);
deviceInputs(); deviceInputs();
amountInputs();
}) })
function deviceInputs() { function deviceInputs() {
@ -19,5 +21,14 @@ function deviceInputs() {
$("#resolution").hide(); $("#resolution").hide();
$("#imei").hide(); $("#imei").hide();
$("#meid").hide(); $("#meid").hide();
} };
amountInputs();
}
function amountInputs() {
if ($("#amount").val() > 1) {
$("#Phid").hide();
} else {
$("#Phid").show();
};
} }

View File

@ -90,7 +90,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="form-group mb-2"> <div class="form-group mb-2" id="Phid">
<label for="label" class="form-label">{{ form.phid.label }}</label> <label for="label" class="form-label">{{ form.phid.label }}</label>
{{ form.phid(class_="form-control") }} {{ form.phid(class_="form-control") }}
<small class="text-muted form-text">Label that you want link to this device</small> <small class="text-muted form-text">Label that you want link to this device</small>