Merge pull request #431 from eReuse/bugfix/4277-testing-erasure

Bugfix/4277 testing erasure
This commit is contained in:
cayop 2023-03-08 18:08:12 +01:00 committed by GitHub
commit e6de54873e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 30 deletions

View file

@ -116,7 +116,10 @@ class SanitizationEntityForm(FlaskForm):
logo = URLField(
'Logo',
[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"})
location = StringField('Location', render_kw={'class': "form-control"})
@ -141,15 +144,17 @@ class SanitizationEntityForm(FlaskForm):
return True
def save(self, commit=True):
sanitation_data = SanitizationEntity(
logo=URL(self.logo.data),
company_name=self.company_name.data,
location=self.location.data,
responsable_person=self.responsable_person.data,
supervisor_person=self.supervisor_person.data,
user=g.user,
)
db.session.add(sanitation_data)
if isinstance(self.logo.data, str):
self.logo.data = URL(self.logo.data)
sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first()
if not sanitation_data:
sanitation_data = SanitizationEntity(user_id=g.user.id)
self.populate_obj(sanitation_data)
db.session.add(sanitation_data)
else:
self.populate_obj(sanitation_data)
if commit:
db.session.commit()

View file

@ -1062,8 +1062,7 @@ class ExportsView(View):
my_data = None
customer_details = None
if hasattr(g.user, 'sanitization_entity'):
if g.user.sanitization_entity:
my_data = list(g.user.sanitization_entity)[0]
my_data = g.user.sanitization_entity
try:
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]:
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 = {
'title': 'Erasure Certificate',
'erasures': tuple(erasures),
@ -1115,7 +1120,7 @@ class ExportsView(View):
'result': result,
'customer_details': customer_details,
'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)

View file

@ -1,11 +1,12 @@
from uuid import uuid4
from flask import current_app as app
from flask import g
from flask_login import UserMixin
from sqlalchemy import BigInteger, Boolean, Column, Sequence
from sqlalchemy.dialects.postgresql import UUID
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.resources.enums import SessionType
@ -122,18 +123,24 @@ class Session(Thing):
class SanitizationEntity(Thing):
id = Column(BigInteger, primary_key=True)
company_name = Column(db.String, nullable=True)
location = Column(db.String, nullable=True)
logo = Column(db.String, nullable=True)
logo = Column(URL(), nullable=True)
responsable_person = Column(db.String, nullable=True)
supervisor_person = Column(db.String, nullable=True)
user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id))
id = db.Column(BigInteger, primary_key=True)
company_name = db.Column(db.String, nullable=True)
location = db.Column(db.String, nullable=True)
# logo = db.Column(db.String, nullable=True)
logo = db.Column(URL(), nullable=True)
responsable_person = db.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),
default=lambda: g.user.id,
)
user = db.relationship(
User,
backref=db.backref('sanitization_entity', lazy=True, collection_class=set),
collection_class=set,
backref=db.backref(
'sanitization_entity', lazy=True, uselist=False, cascade=CASCADE_OWN
),
primaryjoin=user_id == User.id,
)
def __str__(self) -> str:

View file

@ -102,7 +102,7 @@ class UserProfileView(GenericMixin):
self.get_context()
sanitization_form = SanitizationEntityForm()
if g.user.sanitization_entity:
sanitization = list(g.user.sanitization_entity)[0]
sanitization = g.user.sanitization_entity
sanitization_form = SanitizationEntityForm(obj=sanitization)
self.context.update(
{
@ -138,14 +138,13 @@ class SanitizationEntityView(View):
def dispatch_request(self):
form = SanitizationEntityForm()
db.session.commit()
if form.validate_on_submit():
form.save(commit=False)
messages.success('Sanitization datas updated successfully!')
form.save()
messages.success('Sanitization data updated successfully!')
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'))