Skip to content

Commit

Permalink
Merge pull request openedx#490 from yangzhenweiq/track_log
Browse files Browse the repository at this point in the history
feat(edxapp track): add port nickname phone
  • Loading branch information
xavierchan authored Dec 13, 2019
2 parents 113f8b3 + d57e944 commit fbb421e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common/djangoapps/track/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def enter_request_context(self, request):
'user_id': self.get_user_primary_key(request),
'username': self.get_username(request),
'ip': self.get_request_ip_address(request),
'nickname': self.get_user_nickname(request),
'phone': self.get_user_phone(request),
'port' : request.META['SERVER_PORT'] if request.META['SERVER_PORT'] else '',
}
for header_name, context_key in META_KEY_TO_CONTEXT_KEY.iteritems():
# HTTP headers may contain Latin1 characters. Decoding using Latin1 encoding here
Expand Down Expand Up @@ -198,6 +201,21 @@ def get_username(self, request):
except AttributeError:
return ''

def get_user_nickname(self, request):
"""Gets the user nickname of the logged in Django user"""
try:
return request.user.profile.name
except AttributeError:
return ''

def get_user_phone(self, request):
"""Gets the user phone of the logged in Django user"""
try:
phone = request.user.profile.phone
return phone if phone is not None else ''
except AttributeError:
return ''

def get_request_ip_address(self, request):
"""Gets the IP address of the request"""
ip_address = get_ip(request)
Expand Down

0 comments on commit fbb421e

Please sign in to comment.