def clear_device_log_request(domain, xform): from corehq.apps.ota.models import DeviceLogRequest user_subreport = _get_logs(xform.form_data, 'user_subreport', 'user') username = (user_subreport[0].get('username') if user_subreport else cached_user_id_to_username(xform.user_id)) device_id = xform.form_data.get('device_id') try: if not (username and device_id): raise DeviceLogRequest.DoesNotExist() log_request = DeviceLogRequest.objects.get( domain=domain, username=username, device_id=device_id, ) except DeviceLogRequest.DoesNotExist: msg = "Forced log submission, but no corresponding request found." notify_exception(None, msg, details={ 'domain': domain, 'device_id': device_id, 'username': username }) else: log_request.delete()
def migrate(user_history): was_change = False if user_history.changed_by == SYSTEM_USER_ID: changed_by_repr = SYSTEM_USER_ID else: changed_by_repr = cached_user_id_to_username(user_history.changed_by) user_repr = cached_user_id_to_username(user_history.user_id) if changed_by_repr and user_history.changed_by_repr != changed_by_repr: user_history.changed_by_repr = changed_by_repr was_change = True if user_repr and user_history.user_repr != user_repr: user_history.user_repr = user_repr was_change = True if was_change: user_history.save()
def _to_row(xform_dict): def _fmt_url(doc_id): if xform_dict['doc_type'] in [ "XFormInstance", "XFormArchived", "XFormError", "XFormDeprecated"]: view_name = 'render_form_data' else: view_name = 'download_form' try: return "<a class='ajax_dialog' href='%(url)s'>%(text)s</a>" % { "url": reverse(view_name, args=[self.domain, doc_id]), "text": _("View Form") } except NoReverseMatch: return 'unable to view form' def _fmt_date(somedate): time = ServerTime(somedate).user_time(self.timezone).done() return time.strftime(SERVER_DATETIME_FORMAT) if xform_dict['form'].get('meta'): form_name = xmlns_to_name( self.domain, xform_dict.get('xmlns'), app_id=xform_dict.get('app_id'), ) form_username = xform_dict['form']['meta'].get('username', EMPTY_USER) else: form_name = EMPTY_FORM form_username = EMPTY_USER error_type = SubmissionErrorType.display_name_by_doc_type(xform_dict['doc_type']) if xform_dict['doc_type'] == "XFormArchived": archive_operations = [operation for operation in xform_dict.get('history') if operation.get('operation') == 'archive'] if archive_operations: error_type = _("{username} {archived_form} on {date}").format( username=cached_user_id_to_username(archive_operations[-1].get('user')) or "", archived_form=SubmissionErrorType.display_name_by_doc_type(xform_dict['doc_type']), date=_fmt_date(string_to_utc_datetime(archive_operations[-1].get('date'))), ) return [ _fmt_url(xform_dict['_id']), form_username, _fmt_date(string_to_utc_datetime(xform_dict['received_on'])), form_name, error_type, xform_dict.get('problem', EMPTY_ERROR), self._make_reproces_button(xform_dict) if self.support_toggle_enabled else '', ]
def user_id_to_username(user_id, doc): return cached_user_id_to_username(user_id)
def _to_row(xform_dict): def _fmt_url(doc_id): if xform_dict['doc_type'] in [ "XFormInstance", "XFormArchived", "XFormError", "XFormDeprecated" ]: view_name = 'render_form_data' else: view_name = 'download_form' try: return format_html( "<a class='ajax_dialog' href='{url}'>{text}</a>", url=reverse(view_name, args=[self.domain, doc_id]), text=_("View Form")) except NoReverseMatch: return 'unable to view form' def _fmt_date(somedate): time = ServerTime(somedate).user_time(self.timezone).done() return time.strftime(SERVER_DATETIME_FORMAT) if xform_dict['form'].get('meta'): form_name = xmlns_to_name( self.domain, xform_dict.get('xmlns'), app_id=xform_dict.get('app_id'), ) form_username = xform_dict['form']['meta'].get( 'username', EMPTY_USER) else: form_name = EMPTY_FORM form_username = EMPTY_USER error_type = SubmissionTypeFilter.display_name_by_doc_type( xform_dict['doc_type']) if xform_dict['doc_type'] == "XFormArchived": archive_operations = [ operation for operation in xform_dict.get('history') if operation.get('operation') == 'archive' ] if archive_operations: error_type = _( "{username} {archived_form} on {date}").format( username=cached_user_id_to_username( archive_operations[-1].get('user')) or "", archived_form=SubmissionTypeFilter. display_name_by_doc_type(xform_dict['doc_type']), date=_fmt_date( string_to_utc_datetime( archive_operations[-1].get('date'))), ) return [ _fmt_url(xform_dict['_id']), form_username, _fmt_date(string_to_utc_datetime(xform_dict['received_on'])), form_name, error_type, xform_dict.get('problem', EMPTY_ERROR), self._make_reproces_button(xform_dict) if self.support_toggle_enabled else '', ]
def user_id_to_username(user_id, doc): return cached_user_id_to_username(user_id)
def get_user_without_domain_display(user_id): full_username = cached_user_id_to_username(user_id) if full_username: return full_username.split('@')[0] return full_username
def get_user_without_domain_display(user_id): full_username = cached_user_id_to_username(user_id) if full_username: return full_username.split('@')[0] return full_username