From b724dbcb1c45175caeb9cf9f0e20eafdbc9a0b8c Mon Sep 17 00:00:00 2001 From: kid1194 Date: Tue, 27 Jun 2023 01:01:27 +0300 Subject: [PATCH] Update to 1.0.7 --- active_users/hooks.py | 12 ++++++++++-- active_users/setup/install.py | 11 ++++++++--- active_users/setup/migrate.py | 3 ++- active_users/utils/api.py | 32 +++++++++++++++++++++++++++++++- active_users/utils/update.py | 14 ++++++++++++-- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/active_users/hooks.py b/active_users/hooks.py index afed480..c0a5c93 100644 --- a/active_users/hooks.py +++ b/active_users/hooks.py @@ -21,8 +21,16 @@ is_frappe_above_v13 = int(frappe_version.split('.')[0]) > 13 -app_include_css = ['active_users.bundle.css'] if is_frappe_above_v13 else ['/assets/active_users/css/active_users.css'] -app_include_js = ['active_users.bundle.js'] if is_frappe_above_v13 else ['/assets/active_users/js/active_users.js'] +app_include_css = [ + 'active_users.bundle.css' +] if is_frappe_above_v13 else [ + '/assets/active_users/css/active_users.css' +] +app_include_js = [ + 'active_users.bundle.js' +] if is_frappe_above_v13 else [ + '/assets/active_users/js/active_users.js' +] after_install = "active_users.setup.install.after_install" diff --git a/active_users/setup/install.py b/active_users/setup/install.py index 0a086c4..134233a 100644 --- a/active_users/setup/install.py +++ b/active_users/setup/install.py @@ -6,7 +6,11 @@ import frappe -from active_users.utils.common import _SETTINGS_, settings, clear_document_cache +from active_users.utils.common import ( + _SETTINGS_, + settings, + clear_document_cache +) from .migrate import after_migrate @@ -19,14 +23,15 @@ def after_install(): if frappe.db.exists("User Type", "System User"): doc.append("user_types", {"user_type": "System User"}) - if (roles := frappe.db.get_list( + roles = frappe.get_all( "Role", fields=["name"], filters={ "name": ["in", ["Administrator", "System Manager"]], }, pluck="name" - )): + ) + if roles: if doc.roles: doc.roles.clear() diff --git a/active_users/setup/migrate.py b/active_users/setup/migrate.py index e0443f2..3561e00 100644 --- a/active_users/setup/migrate.py +++ b/active_users/setup/migrate.py @@ -13,7 +13,8 @@ def after_migrate(): - if (managers := get_system_managers(only_name=True)): + managers = get_system_managers(only_name=True) + if managers: if "Administrator" in managers: sender = "Administrator" else: diff --git a/active_users/utils/api.py b/active_users/utils/api.py index c7e620e..39b53be 100644 --- a/active_users/utils/api.py +++ b/active_users/utils/api.py @@ -4,13 +4,17 @@ # Licence: Please refer to LICENSE file +#import datetime import json +#import math import re import frappe from frappe import _dict +#from frappe import _dict, _ from frappe.utils import ( cint, + #cstr, has_common, now, add_to_date, @@ -122,6 +126,7 @@ def get_users(): data = frappe.get_all( "User", fields=["name", "full_name", "user_image"], + #fields=["name", "full_name", "user_image", "last_active"], filters={ "enabled": 1, "user_type": ["in", user_types], @@ -131,6 +136,10 @@ def get_users(): limit_page_length=0, ) + #if data and isinstance(data, list): + # for user in data: + # user.last_active = abbr_time(user.last_active) + if app.refresh_interval >= _CACHE_INTERVAL_: set_cache(_CACHE_, cache_key, _dict({ "data": data, @@ -140,4 +149,25 @@ def get_users(): return {"users": data} except Exception as exc: log_error(exc) - return {"error": 1, "message": "Unable to get the list of active users."} \ No newline at end of file + return {"error": 1, "message": "Unable to get the list of active users."} + + +# def abbr_time(date: str): +# if not date: +# return "" +# +# try: +# date = datetime.datetime.strptime(date, DATETIME_FORMAT) +# now_dt = datetime.datetime.strptime(now(), DATETIME_FORMAT) +# dt_diff = now_dt - date +# +# dt_diff_seconds = (dt_diff.days * 86400.0) + dt_diff.seconds +# +# for i in range(0, 29): +# if dt_diff_seconds < (60.0 * (i + 1)): +# return _("{0}m").format(cstr(i)) +# +# return "" +# +# except Exception as exc: +# return "" \ No newline at end of file diff --git a/active_users/utils/update.py b/active_users/utils/update.py index 3c1d59e..45f8422 100644 --- a/active_users/utils/update.py +++ b/active_users/utils/update.py @@ -8,14 +8,24 @@ import re import frappe -from frappe.utils import cint, get_request_session, now, markdown +from frappe.utils import ( + cint, + get_request_session, + now, + markdown +) from frappe.desk.doctype.notification_settings.notification_settings import ( is_notifications_enabled ) from active_users import __version__ -from .common import _SETTINGS_, log_error, settings, parse_json +from .common import ( + _SETTINGS_, + log_error, + settings, + parse_json +) # Daily Schedule