Merge pull request #340 from eReuse/changes/3746-messages-upload-placeholder

update the message of upload placeholders
This commit is contained in:
cayop 2022-09-12 18:00:57 +02:00 committed by GitHub
commit ce3bab659d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -1490,6 +1490,11 @@ class UploadPlaceholderForm(FlaskForm):
'Select a Placeholder File', [validators.DataRequired()]
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.dev_new = 0
self.dev_update = 0
def get_data_file(self):
files = request.files.getlist(self.placeholder_file.name)
@ -1555,6 +1560,7 @@ class UploadPlaceholderForm(FlaskForm):
# update one
if placeholder:
self.dev_update += 1
device = placeholder.device
device.model = "{}".format(data['Model'][i]).lower()
device.manufacturer = "{}".format(data['Manufacturer'][i]).lower()
@ -1594,9 +1600,11 @@ class UploadPlaceholderForm(FlaskForm):
snapshot_json = schema.load(json_snapshot)
device = snapshot_json['device']
device.placeholder = Placeholder(**json_placeholder)
self.dev_new += 1
typ = 'New device'
placeholder_log = PlaceholdersLog(
type="New device", source=self.source, placeholder=device.placeholder
type=typ, source=self.source, placeholder=device.placeholder
)
self.placeholders.append((device, placeholder_log))

View File

@ -1169,7 +1169,27 @@ class UploadPlaceholderView(GenericMixin):
lot.devices.add(device)
db.session.add(lot)
db.session.commit()
messages.success('Placeholders uploaded successfully!')
dev_new = form.dev_new
dev_update = form.dev_update
total = dev_new + dev_update
txt = 'Placeholders uploaded successfully!'
if dev_update == 0:
txt = f'A total of {total} Placeholders have been successfully'
txt += ' uploaded. All of them have been new registrations in'
txt += ' the system.'
if dev_new == 0:
txt = f'A total of {total} Placeholders have been successfully'
txt += ' uploaded. All of them are updates.'
if dev_new and dev_update:
txt = f'A total of {total} Placeholders have been successfully'
txt += f' uploaded. Among these {dev_new} are registered for '
txt += ' the first time in the system and another'
txt += f' {dev_update} have been updated.'
messages.success(txt)
return flask.render_template(self.template_name, **self.context)