Merge pull request #460 from eReuse/feature/4463-solar-panel

Feature/4463 solar panel
This commit is contained in:
cayop 2023-07-26 16:35:48 +02:00 committed by GitHub
commit 07e506f999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 128 additions and 20 deletions

View File

@ -41,7 +41,7 @@ from ereuse_devicehub.inventory.models import (
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
from ereuse_devicehub.parser.schemas import Snapshot_lite from ereuse_devicehub.parser.schemas import Snapshot_lite
from ereuse_devicehub.resources.action.models import Snapshot, Trade from ereuse_devicehub.resources.action.models import Snapshot, Trade, VisualTest
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
from ereuse_devicehub.resources.action.views.snapshot import ( from ereuse_devicehub.resources.action.views.snapshot import (
SnapshotMixin, SnapshotMixin,
@ -68,6 +68,7 @@ from ereuse_devicehub.resources.device.models import (
Projector, Projector,
Server, Server,
Smartphone, Smartphone,
SolarPanel,
SolidStateDrive, SolidStateDrive,
Tablet, Tablet,
TelevisionSet, TelevisionSet,
@ -113,7 +114,7 @@ DEVICES = {
"SAI", "SAI",
"Keyboard", "Keyboard",
], ],
"Other Devices": ["Other"], "Other Devices": ["SolarPanel", "Other"],
} }
TYPES_DOCUMENTS = [ TYPES_DOCUMENTS = [
@ -131,7 +132,7 @@ MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"]
MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"]
STORAGE = ["HardDrive", "SolidStateDrive"] STORAGE = ["HardDrive", "SolidStateDrive"]
ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"] ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"]
OTHERS = ["Other"] OTHERS = ["Other", "SolarPanel"]
DATASTORAGE = ['HardDrive', 'SolidStateDrive'] DATASTORAGE = ['HardDrive', 'SolidStateDrive']
@ -433,6 +434,7 @@ class NewDeviceForm(FlaskForm):
"Keyboard": Keyboard, "Keyboard": Keyboard,
"SAI": SAI, "SAI": SAI,
"MemoryCardReader": MemoryCardReader, "MemoryCardReader": MemoryCardReader,
"SolarPanel": SolarPanel,
"Other": Other, "Other": Other,
} }
@ -480,6 +482,10 @@ class NewDeviceForm(FlaskForm):
if self._obj.type in ['HardDrive', 'SolidStateDrive']: if self._obj.type in ['HardDrive', 'SolidStateDrive']:
if self._obj.size: if self._obj.size:
self.data_storage_size.data = self._obj.size / 1000 self.data_storage_size.data = self._obj.size / 1000
if self._obj.appearance():
self.appearance.data = self._obj.appearance().name
if self._obj.functionality():
self.functionality.data = self._obj.functionality().name
if self._obj.placeholder.is_abstract: if self._obj.placeholder.is_abstract:
self.type.render_kw = disabled self.type.render_kw = disabled
@ -698,17 +704,7 @@ class NewDeviceForm(FlaskForm):
if self.data_storage_size.data: if self.data_storage_size.data:
self._obj.size = self.data_storage_size.data * 1000 self._obj.size = self.data_storage_size.data * 1000
if ( self.edit_visual_test(self._obj)
self.appearance.data
and self.appearance.data != self._obj.appearance().name
):
self._obj.set_appearance(self.appearance.data)
if (
self.functionality.data
and self.functionality.data != self._obj.functionality().name
):
self._obj.set_functionality(self.functionality.data)
else: else:
self._obj.placeholder.id_device_supplier = ( self._obj.placeholder.id_device_supplier = (
@ -718,11 +714,33 @@ class NewDeviceForm(FlaskForm):
self.id_device_internal.data or None self.id_device_internal.data or None
) )
self._obj.placeholder.pallet = self.pallet.data or None self._obj.placeholder.pallet = self.pallet.data or None
pl_dev = self._obj.placeholder.device
self.edit_visual_test(pl_dev)
placeholder_log = PlaceholdersLog( placeholder_log = PlaceholdersLog(
type="Update", source='Web form', placeholder=self._obj.placeholder type="Update", source='Web form', placeholder=self._obj.placeholder
) )
db.session.add(placeholder_log) db.session.add(placeholder_log)
def edit_visual_test(self, dev):
if not dev.appearance() or not dev.functionality():
visual_test = VisualTest(
appearance_range=self.appearance.data,
functionality_range=self.functionality.data,
device=dev,
)
db.session.add(visual_test)
else:
if self.appearance.data and self.appearance.data != dev.appearance().name:
dev.set_appearance(self.appearance.data)
if (
self.functionality.data
and self.functionality.data != dev.functionality().name
):
dev.set_functionality(self.functionality.data)
class TagDeviceForm(FlaskForm): class TagDeviceForm(FlaskForm):
tag = SelectField( tag = SelectField(
@ -1211,7 +1229,6 @@ class TradeForm(ActionFormMixin):
or email_to == email_from or email_to == email_from
or g.user.email not in [email_from, email_to] or g.user.email not in [email_from, email_to]
): ):
errors = ["If you want confirm, you need a correct email"] errors = ["If you want confirm, you need a correct email"]
self.user_to.errors = errors self.user_to.errors = errors
self.user_from.errors = errors self.user_from.errors = errors
@ -1917,7 +1934,6 @@ class UploadPlaceholderForm(FlaskForm):
return True return True
def save(self, commit=True): def save(self, commit=True):
for device, placeholder_log in self.placeholders: for device, placeholder_log in self.placeholders:
db.session.add(device) db.session.add(device)
db.session.add(placeholder_log) db.session.add(placeholder_log)
@ -1946,7 +1962,6 @@ class EditPlaceholderForm(FlaskForm):
return True return True
def save(self, commit=True): def save(self, commit=True):
for device in self.placeholders: for device in self.placeholders:
db.session.add(device) db.session.add(device)

View File

@ -0,0 +1,41 @@
"""add solar panel
Revision ID: 8ccba3cb37c2
Revises: 5169765e2653
Create Date: 2023-07-26 09:23:21.326465
"""
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = '8ccba3cb37c2'
down_revision = '5169765e2653'
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():
# creating Solar panel device.
op.create_table(
'solar_panel',
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('solar_panel', schema=f'{get_inv()}')

View File

@ -726,3 +726,34 @@ class OtherDef(DeviceDef):
root_path, root_path,
cli_commands, cli_commands,
) )
class SolarPanelDef(DeviceDef):
VIEW = None
SCHEMA = schemas.SolarPanel
def __init__(
self,
app,
import_name=__name__,
static_folder=None,
static_url_path=None,
template_folder=None,
url_prefix=None,
subdomain=None,
url_defaults=None,
root_path=None,
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(),
):
super().__init__(
app,
import_name,
static_folder,
static_url_path,
template_folder,
url_prefix,
subdomain,
url_defaults,
root_path,
cli_commands,
)

View File

@ -476,7 +476,8 @@ class Device(Thing):
"""The trading state, or None if no Trade action has """The trading state, or None if no Trade action has
ever been performed to this device. This extract the posibilities for to do. ever been performed to this device. This extract the posibilities for to do.
This method is performed for show in the web. This method is performed for show in the web.
If you need to do one simple and generic response you can put simple=True for that.""" If you need to do one simple and generic response you can put simple=True for that.
"""
if not hasattr(lot, 'trade'): if not hasattr(lot, 'trade'):
return return
@ -1986,3 +1987,11 @@ class Other(Device):
""" """
id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)
class SolarPanel(Device):
"""
Used solar panels devices.
"""
id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)

View File

@ -590,5 +590,9 @@ class Racket(Recreation):
pass pass
class SolarPanel(Device):
pass
class Other(Device): class Other(Device):
pass pass

View File

@ -176,7 +176,7 @@ class DeviceView(View):
"""Gets many devices.""" """Gets many devices."""
# Compute query # Compute query
query = self.query(args) query = self.query(args)
devices = query.paginate(page=args['page'], per_page=30) # type: Pagination devices = query.paginate(page=args['page'], per_page=100) # type: Pagination
return things_response( return things_response(
self.schema.dump(devices.items, many=True, nested=1), self.schema.dump(devices.items, many=True, nested=1),
devices.page, devices.page,

View File

@ -79,6 +79,8 @@
{% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option> {% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option>
</optgroup> </optgroup>
<optgroup label="Other Type of Device"> <optgroup label="Other Type of Device">
<option value="SolarPanel"
{% if form.type.data == 'SolarPanel' %} selected="selected"{% endif %}>Solar Panel</option>
<option value="Other" <option value="Other"
{% if form.type.data == 'Other' %} selected="selected"{% endif %}>Other</option> {% if form.type.data == 'Other' %} selected="selected"{% endif %}>Other</option>
</optgroup> </optgroup>

View File

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

View File

@ -125,4 +125,4 @@ def test_api_docs(client: Client):
'scheme': 'basic', 'scheme': 'basic',
'name': 'Authorization', 'name': 'Authorization',
} }
assert len(docs['definitions']) == 135 assert len(docs['definitions']) == 136