-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds messages cli. * Adds `message_footer` info to footer. Co-Authored-by: Peter Weber <[email protected]>
- Loading branch information
Showing
10 changed files
with
494 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Click command-line interface for item record management.""" | ||
|
||
import click | ||
from flask.cli import with_appcontext | ||
|
||
from rero_ils.modules.messages import Message | ||
|
||
|
||
@click.group() | ||
def messages(): | ||
"""Messages commands.""" | ||
|
||
|
||
def abort_if_false(ctx, param, value): | ||
"""Abort command is value is False.""" | ||
if not value: | ||
ctx.abort() | ||
|
||
|
||
@messages.command() | ||
@with_appcontext | ||
def info(): | ||
"""Messages info.""" | ||
click.secho(f"{'KEY':<20}{'TYPE':<15}MESSAGE", fg="green") | ||
for key, data in Message.get_all_messages().items(): | ||
click.secho(f'{key:<20}{data["type"]:<15}"{data["message"]}"', fg="green") | ||
|
||
|
||
@messages.command() | ||
@click.argument("key") | ||
@with_appcontext | ||
def get(key): | ||
"""Get messages for key.""" | ||
if message := Message.get(key): | ||
click.secho(f'{key:<20}{message["type"]:<15}"{message["message"]}"', fg="green") | ||
else: | ||
click.secho(f"{key:<20}KEY NOT FOUND!", fg="red") | ||
raise click.BadParameter | ||
|
||
|
||
@messages.command("set") | ||
@click.argument("key") | ||
@click.argument("type") | ||
@click.argument("message") | ||
@click.option("-t", "--timeout", "timeout", default=0) | ||
@with_appcontext | ||
def set_message(key, type, message, timeout): | ||
"""Set messages for name.""" | ||
msg = f'{key:<20}{type:<15}"{message}"' | ||
if Message.set(key=key, type=type, value=message, timeout=timeout): | ||
fg = "green" | ||
msg = f"OK: {msg}" | ||
else: | ||
fg = "red" | ||
msg = f"ERROR: {msg}" | ||
click.secho(msg, fg=fg) | ||
if fg == "red": | ||
raise click.BadParameter | ||
|
||
|
||
@messages.command() | ||
@click.argument("key") | ||
@click.option( | ||
"--yes-i-know", | ||
is_flag=True, | ||
callback=abort_if_false, | ||
expose_value=False, | ||
prompt="Do you really want to delete the message?", | ||
) | ||
@with_appcontext | ||
def delete(key): | ||
"""Delete message for name.""" | ||
if Message.delete(key=key): | ||
click.secho(f"{key:<20}DELETED", fg="yellow") | ||
else: | ||
click.secho(f"{key:<20}KEY NOT FOUND!", fg="red") | ||
raise click.BadParameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,4 @@ <h5>Altri cataloghi</h5> | |
</ul> | ||
{% endif %} | ||
</section> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.