-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release User Metadata tab #34734
Release User Metadata tab #34734
Changes from all commits
845b081
2fed30c
6326bb0
cc1a464
6672c32
9f1a31c
fd39ed2
5ac1380
6c6c1d3
25783af
956c6f8
22625b7
3b5df5a
546fa58
d6bbb27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,14 @@ | |
from dimagi.utils.web import json_handler | ||
|
||
from corehq import privileges | ||
from corehq.apps.hqwebapp.exceptions import AlreadyRenderedException, TemplateTagJSONException | ||
from corehq.apps.hqwebapp.exceptions import ( | ||
AlreadyRenderedException, | ||
TemplateTagJSONException, | ||
) | ||
from corehq.apps.hqwebapp.models import Alert | ||
from corehq.motech.utils import pformat_json | ||
from corehq.util.timezones.conversions import ServerTime | ||
from corehq.util.timezones.utils import get_timezone | ||
|
||
register = template.Library() | ||
|
||
|
@@ -114,7 +119,10 @@ def domains_for_user(context, request, selected_domain=None): | |
the user doc updates via save. | ||
""" | ||
|
||
from corehq.apps.domain.views.base import get_domain_links_for_dropdown, get_enterprise_links_for_dropdown | ||
from corehq.apps.domain.views.base import ( | ||
get_domain_links_for_dropdown, | ||
get_enterprise_links_for_dropdown, | ||
) | ||
domain_links = get_domain_links_for_dropdown(request.couch_user) | ||
|
||
# Enterprise permissions projects aren't in the dropdown, but show a hint they exist | ||
|
@@ -746,3 +754,14 @@ def request_has_privilege(request, privilege_name): | |
from corehq import privileges | ||
privilege = _get_obj_from_name_or_instance(privileges, privilege_name) | ||
return domain_has_privilege(request.domain, privilege) | ||
|
||
|
||
@register.filter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much nicer. |
||
def to_user_time(dt, request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: definitely the filter is useful. Thinking if this is a good opportunity to name this better? the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was attempting to mirror the language used in
I feel like that is an implementation detail detail at a lower abstraction level. I think Relatedly, I actually kind of think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I believe I tend to have the naming really explicit and seeing
Right. I don't prefer to have to look at the function definition to understand what it would be doing or have the name be totally ambiguous so I am forced to look into it. This is in the middle.
Ya I was unsure in what cases it needed domain to be passed other than the request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've noticed you and I are often on opposite sides of the spectrum here. I find long names to hurt readability. I also think of a function's parameter names as part of its public interface, so
I disagree with this, actually - it's a question of "user" vs
This functionality expresses an abstraction (what timezone should we use), and callers shouldn't need to know about the implementation. To accurately express the logic happening here it'd have to be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
same same. If a name needs to be long, the function itself probably can be split.
Oh yes, Like i would not mind
Exactly. And that distinction was what I was getting to with
I like that.
Ya, that makes sense to me, like:
haha, that would be too much! I might have misspoken about what I like the naming to be. |
||
"""Convert a datetime to a readable string in the user's timezone""" | ||
if not dt: | ||
return "---" | ||
if not isinstance(dt, datetime): | ||
raise ValueError("to_user_time only accepts datetimes") | ||
timezone = get_timezone(request, getattr(request, 'domain', None)) | ||
return ServerTime(dt).user_time(timezone).ui_string() |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this was an exact copy of
corehq.util.timezones.utils.get_timezone
👍