add others device

This commit is contained in:
Cayo Puigdefabregas 2022-11-29 16:49:23 +01:00
parent b84f379468
commit c392270676
6 changed files with 65 additions and 2 deletions

View file

@ -52,6 +52,7 @@ from ereuse_devicehub.resources.device.models import (
MemoryCardReader,
Monitor,
Mouse,
Other,
Placeholder,
Projector,
Server,
@ -84,7 +85,6 @@ DEVICES = {
],
"Mobile, tablet & smartphone": [
"All Mobile",
"Mobile",
"Tablet",
"Smartphone",
"Cellphone",
@ -101,6 +101,7 @@ DEVICES = {
"SAI",
"Keyboard",
],
"Other Devices": ["Other"],
}
COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer']
@ -109,6 +110,7 @@ MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"]
MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"]
STORAGE = ["HardDrive", "SolidStateDrive"]
ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"]
OTHERS = ["Other"]
class AdvancedSearchForm(FlaskForm):
@ -181,7 +183,7 @@ class FilterForm(FlaskForm):
# Generic Filters
if "All Devices" == self.device_type:
filter_type = COMPUTERS + MONITORS + MOBILE
filter_type = COMPUTERS + MONITORS + MOBILE + OTHERS
elif "All Computers" == self.device_type:
filter_type = COMPUTERS
@ -392,6 +394,7 @@ class NewDeviceForm(FlaskForm):
"Keyboard": Keyboard,
"SAI": SAI,
"MemoryCardReader": MemoryCardReader,
"Other": Other,
}
def reset_from_obj(self):

View file

@ -0,0 +1,39 @@
"""device other
Revision ID: 410aadae7652
Revises: d65745749e34
Create Date: 2022-11-29 12:00:40.272121
"""
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = '410aadae7652'
down_revision = 'd65745749e34'
branch_labels = None
depends_on = None
def get_inv():
INV = context.get_x_argument(as_dictionary=True).get('inventory')
if not INV:
raise ValueError("Inventory value is not specified")
return INV
def upgrade():
op.create_table(
'other',
sa.Column('id', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.device.id'],
),
sa.PrimaryKeyConstraint('id'),
schema=f'{get_inv()}',
)
def downgrade():
op.drop_table('other', schema=f'{get_inv()}')

View file

@ -695,3 +695,8 @@ class ManufacturerDef(Resource):
"""Loads the manufacturers to the database."""
if exclude_schema != 'common':
Manufacturer.add_all_to_session(db.session)
class OtherDef(DeviceDef):
VIEW = None
SCHEMA = schemas.Other

View file

@ -1637,3 +1637,11 @@ def create_code_tag(mapper, connection, device):
# from flask_sqlalchemy import event
# event.listen(Device, 'after_insert', create_code_tag, propagate=True)
class Other(Device):
"""
Used for put in there all devices than not have actualy a class
"""
id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)

View file

@ -581,3 +581,7 @@ class Bike(Recreation):
class Racket(Recreation):
pass
class Other(Device):
pass

View file

@ -72,6 +72,10 @@
<option value="Keyboard"
{% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option>
</optgroup>
<optgroup label="Other Type of Device">
<option value="Other"
{% if form.type.data == 'Other' %} selected="selected"{% endif %}>Other</option>
</optgroup>
</select>
<small class="text-muted form-text">Type of devices</small>
{% if form.type.errors %}