Merge pull request #431 from eReuse/bugfix/4277-testing-erasure
Bugfix/4277 testing erasure
This commit is contained in:
commit
e6de54873e
|
@ -116,7 +116,10 @@ class SanitizationEntityForm(FlaskForm):
|
||||||
logo = URLField(
|
logo = URLField(
|
||||||
'Logo',
|
'Logo',
|
||||||
[validators.Optional(), validators.URL()],
|
[validators.Optional(), validators.URL()],
|
||||||
render_kw={'class': "form-control"},
|
render_kw={
|
||||||
|
'class': "form-control",
|
||||||
|
"placeholder": "Url where is the logo - acceptd only .png, .jpg, .gif, svg",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
company_name = StringField('Company Name', render_kw={'class': "form-control"})
|
company_name = StringField('Company Name', render_kw={'class': "form-control"})
|
||||||
location = StringField('Location', render_kw={'class': "form-control"})
|
location = StringField('Location', render_kw={'class': "form-control"})
|
||||||
|
@ -141,15 +144,17 @@ class SanitizationEntityForm(FlaskForm):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
sanitation_data = SanitizationEntity(
|
if isinstance(self.logo.data, str):
|
||||||
logo=URL(self.logo.data),
|
self.logo.data = URL(self.logo.data)
|
||||||
company_name=self.company_name.data,
|
|
||||||
location=self.location.data,
|
sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first()
|
||||||
responsable_person=self.responsable_person.data,
|
|
||||||
supervisor_person=self.supervisor_person.data,
|
if not sanitation_data:
|
||||||
user=g.user,
|
sanitation_data = SanitizationEntity(user_id=g.user.id)
|
||||||
)
|
self.populate_obj(sanitation_data)
|
||||||
db.session.add(sanitation_data)
|
db.session.add(sanitation_data)
|
||||||
|
else:
|
||||||
|
self.populate_obj(sanitation_data)
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -1062,8 +1062,7 @@ class ExportsView(View):
|
||||||
my_data = None
|
my_data = None
|
||||||
customer_details = None
|
customer_details = None
|
||||||
if hasattr(g.user, 'sanitization_entity'):
|
if hasattr(g.user, 'sanitization_entity'):
|
||||||
if g.user.sanitization_entity:
|
my_data = g.user.sanitization_entity
|
||||||
my_data = list(g.user.sanitization_entity)[0]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(request.referrer.split('/lot/')) > 1:
|
if len(request.referrer.split('/lot/')) > 1:
|
||||||
|
@ -1103,6 +1102,12 @@ class ExportsView(View):
|
||||||
if "Failed" in [e.severity.get_public_name() for e in erasures]:
|
if "Failed" in [e.severity.get_public_name() for e in erasures]:
|
||||||
result = 'Failed'
|
result = 'Failed'
|
||||||
|
|
||||||
|
erasures = sorted(erasures, key=lambda x: x.end_time)
|
||||||
|
erasures_on_server = sorted(erasures_on_server, key=lambda x: x.end_time)
|
||||||
|
erasures_host = sorted(erasures_host, key=lambda x: x.end_time)
|
||||||
|
erasures_normal = list(set(erasures) - set(erasures_on_server))
|
||||||
|
erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'title': 'Erasure Certificate',
|
'title': 'Erasure Certificate',
|
||||||
'erasures': tuple(erasures),
|
'erasures': tuple(erasures),
|
||||||
|
@ -1115,7 +1120,7 @@ class ExportsView(View):
|
||||||
'result': result,
|
'result': result,
|
||||||
'customer_details': customer_details,
|
'customer_details': customer_details,
|
||||||
'erasure_hosts': erasures_host,
|
'erasure_hosts': erasures_host,
|
||||||
'erasures_normal': list(set(erasures) - set(erasures_on_server)),
|
'erasures_normal': erasures_normal,
|
||||||
}
|
}
|
||||||
return flask.render_template('inventory/erasure.html', **params)
|
return flask.render_template('inventory/erasure.html', **params)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
|
from flask import g
|
||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from sqlalchemy import BigInteger, Boolean, Column, Sequence
|
from sqlalchemy import BigInteger, Boolean, Column, Sequence
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy_utils import EmailType, PasswordType
|
from sqlalchemy_utils import EmailType, PasswordType
|
||||||
from teal.db import URL, IntEnum
|
from teal.db import CASCADE_OWN, URL, IntEnum
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.enums import SessionType
|
from ereuse_devicehub.resources.enums import SessionType
|
||||||
|
@ -122,18 +123,24 @@ class Session(Thing):
|
||||||
|
|
||||||
|
|
||||||
class SanitizationEntity(Thing):
|
class SanitizationEntity(Thing):
|
||||||
id = Column(BigInteger, primary_key=True)
|
id = db.Column(BigInteger, primary_key=True)
|
||||||
company_name = Column(db.String, nullable=True)
|
company_name = db.Column(db.String, nullable=True)
|
||||||
location = Column(db.String, nullable=True)
|
location = db.Column(db.String, nullable=True)
|
||||||
logo = Column(db.String, nullable=True)
|
# logo = db.Column(db.String, nullable=True)
|
||||||
logo = Column(URL(), nullable=True)
|
logo = db.Column(URL(), nullable=True)
|
||||||
responsable_person = Column(db.String, nullable=True)
|
responsable_person = db.Column(db.String, nullable=True)
|
||||||
supervisor_person = Column(db.String, nullable=True)
|
supervisor_person = db.Column(db.String, nullable=True)
|
||||||
user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id))
|
user_id = db.Column(
|
||||||
|
db.UUID(as_uuid=True),
|
||||||
|
db.ForeignKey(User.id),
|
||||||
|
default=lambda: g.user.id,
|
||||||
|
)
|
||||||
user = db.relationship(
|
user = db.relationship(
|
||||||
User,
|
User,
|
||||||
backref=db.backref('sanitization_entity', lazy=True, collection_class=set),
|
backref=db.backref(
|
||||||
collection_class=set,
|
'sanitization_entity', lazy=True, uselist=False, cascade=CASCADE_OWN
|
||||||
|
),
|
||||||
|
primaryjoin=user_id == User.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
|
|
@ -102,7 +102,7 @@ class UserProfileView(GenericMixin):
|
||||||
self.get_context()
|
self.get_context()
|
||||||
sanitization_form = SanitizationEntityForm()
|
sanitization_form = SanitizationEntityForm()
|
||||||
if g.user.sanitization_entity:
|
if g.user.sanitization_entity:
|
||||||
sanitization = list(g.user.sanitization_entity)[0]
|
sanitization = g.user.sanitization_entity
|
||||||
sanitization_form = SanitizationEntityForm(obj=sanitization)
|
sanitization_form = SanitizationEntityForm(obj=sanitization)
|
||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
|
@ -138,14 +138,13 @@ class SanitizationEntityView(View):
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
form = SanitizationEntityForm()
|
form = SanitizationEntityForm()
|
||||||
db.session.commit()
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.save(commit=False)
|
form.save()
|
||||||
messages.success('Sanitization datas updated successfully!')
|
messages.success('Sanitization data updated successfully!')
|
||||||
else:
|
else:
|
||||||
messages.error('Error modifying Sanitization datas!')
|
messages.error('Error modifying Sanitization data!')
|
||||||
|
|
||||||
db.session.commit()
|
# db.session.commit()
|
||||||
return flask.redirect(flask.url_for('core.user-profile'))
|
return flask.redirect(flask.url_for('core.user-profile'))
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue