Skip to content

Commit

Permalink
Update to 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Jun 26, 2023
1 parent a2484ee commit b724dbc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
12 changes: 10 additions & 2 deletions active_users/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions active_users/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion active_users/setup/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 31 additions & 1 deletion active_users/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand All @@ -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."}
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 ""
14 changes: 12 additions & 2 deletions active_users/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b724dbc

Please sign in to comment.