Merge pull request #460 from eReuse/feature/4463-solar-panel
Feature/4463 solar panel
This commit is contained in:
commit
07e506f999
|
@ -41,7 +41,7 @@ from ereuse_devicehub.inventory.models import (
|
|||
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog
|
||||
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
|
||||
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.views.snapshot import (
|
||||
SnapshotMixin,
|
||||
|
@ -68,6 +68,7 @@ from ereuse_devicehub.resources.device.models import (
|
|||
Projector,
|
||||
Server,
|
||||
Smartphone,
|
||||
SolarPanel,
|
||||
SolidStateDrive,
|
||||
Tablet,
|
||||
TelevisionSet,
|
||||
|
@ -113,7 +114,7 @@ DEVICES = {
|
|||
"SAI",
|
||||
"Keyboard",
|
||||
],
|
||||
"Other Devices": ["Other"],
|
||||
"Other Devices": ["SolarPanel", "Other"],
|
||||
}
|
||||
|
||||
TYPES_DOCUMENTS = [
|
||||
|
@ -131,7 +132,7 @@ MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"]
|
|||
MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"]
|
||||
STORAGE = ["HardDrive", "SolidStateDrive"]
|
||||
ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"]
|
||||
OTHERS = ["Other"]
|
||||
OTHERS = ["Other", "SolarPanel"]
|
||||
DATASTORAGE = ['HardDrive', 'SolidStateDrive']
|
||||
|
||||
|
||||
|
@ -433,6 +434,7 @@ class NewDeviceForm(FlaskForm):
|
|||
"Keyboard": Keyboard,
|
||||
"SAI": SAI,
|
||||
"MemoryCardReader": MemoryCardReader,
|
||||
"SolarPanel": SolarPanel,
|
||||
"Other": Other,
|
||||
}
|
||||
|
||||
|
@ -480,6 +482,10 @@ class NewDeviceForm(FlaskForm):
|
|||
if self._obj.type in ['HardDrive', 'SolidStateDrive']:
|
||||
if self._obj.size:
|
||||
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:
|
||||
self.type.render_kw = disabled
|
||||
|
@ -698,17 +704,7 @@ class NewDeviceForm(FlaskForm):
|
|||
if self.data_storage_size.data:
|
||||
self._obj.size = self.data_storage_size.data * 1000
|
||||
|
||||
if (
|
||||
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)
|
||||
self.edit_visual_test(self._obj)
|
||||
|
||||
else:
|
||||
self._obj.placeholder.id_device_supplier = (
|
||||
|
@ -718,11 +714,33 @@ class NewDeviceForm(FlaskForm):
|
|||
self.id_device_internal.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(
|
||||
type="Update", source='Web form', placeholder=self._obj.placeholder
|
||||
)
|
||||
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):
|
||||
tag = SelectField(
|
||||
|
@ -1211,7 +1229,6 @@ class TradeForm(ActionFormMixin):
|
|||
or email_to == email_from
|
||||
or g.user.email not in [email_from, email_to]
|
||||
):
|
||||
|
||||
errors = ["If you want confirm, you need a correct email"]
|
||||
self.user_to.errors = errors
|
||||
self.user_from.errors = errors
|
||||
|
@ -1917,7 +1934,6 @@ class UploadPlaceholderForm(FlaskForm):
|
|||
return True
|
||||
|
||||
def save(self, commit=True):
|
||||
|
||||
for device, placeholder_log in self.placeholders:
|
||||
db.session.add(device)
|
||||
db.session.add(placeholder_log)
|
||||
|
@ -1946,7 +1962,6 @@ class EditPlaceholderForm(FlaskForm):
|
|||
return True
|
||||
|
||||
def save(self, commit=True):
|
||||
|
||||
for device in self.placeholders:
|
||||
db.session.add(device)
|
||||
|
||||
|
|
|
@ -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()}')
|
|
@ -726,3 +726,34 @@ class OtherDef(DeviceDef):
|
|||
root_path,
|
||||
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,
|
||||
)
|
||||
|
|
|
@ -476,7 +476,8 @@ class Device(Thing):
|
|||
"""The trading state, or None if no Trade action has
|
||||
ever been performed to this device. This extract the posibilities for to do.
|
||||
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'):
|
||||
return
|
||||
|
||||
|
@ -1986,3 +1987,11 @@ class Other(Device):
|
|||
"""
|
||||
|
||||
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)
|
||||
|
|
|
@ -590,5 +590,9 @@ class Racket(Recreation):
|
|||
pass
|
||||
|
||||
|
||||
class SolarPanel(Device):
|
||||
pass
|
||||
|
||||
|
||||
class Other(Device):
|
||||
pass
|
||||
|
|
|
@ -176,7 +176,7 @@ class DeviceView(View):
|
|||
"""Gets many devices."""
|
||||
# Compute query
|
||||
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(
|
||||
self.schema.dump(devices.items, many=True, nested=1),
|
||||
devices.page,
|
||||
|
|
|
@ -79,6 +79,8 @@
|
|||
{% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option>
|
||||
</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>
|
||||
|
|
|
@ -72,6 +72,12 @@
|
|||
<option value="Keyboard"
|
||||
{% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option>
|
||||
</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>
|
||||
<small class="text-muted form-text">Type of devices</small>
|
||||
{% if form.type.errors %}
|
||||
|
|
|
@ -125,4 +125,4 @@ def test_api_docs(client: Client):
|
|||
'scheme': 'basic',
|
||||
'name': 'Authorization',
|
||||
}
|
||||
assert len(docs['definitions']) == 135
|
||||
assert len(docs['definitions']) == 136
|
||||
|
|
Reference in New Issue