def realtime(widget, url_name=None, url_regex=None, time_interval=None):
if not hasattr(widget, '<STR_LIT>'):<EOL><INDENT>raise AttributeError('<STR_LIT>'<EOL>'<STR_LIT>' % widget)<EOL><DEDENT>elif not callable(widget.get_updated_content):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>% widget)<EOL><DEDENT>if url_name is None:<EOL><INDENT>if getattr(widget, '<STR_LIT>', None) is not None:<EOL><INDENT>url_name = widget.url_name<EOL><DEDENT>else:<EOL><INDENT>url_name = widget.__class__.__name__<EOL><DEDENT><DEDENT>if url_name in [w.url_name for w in REALTIME_WIDGETS]:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % url_name)<EOL><DEDENT>if url_regex is None:<EOL><INDENT>if getattr(widget, '<STR_LIT>', None) is not None:<EOL><INDENT>url_regex = widget.url_regex<EOL><DEDENT>else:<EOL><INDENT>url_regex = sha256(url_name.encode('<STR_LIT:utf-8>'))<EOL>url_regex = url_regex.hexdigest()[:<NUM_LIT:32>]<EOL>url_regex = '<STR_LIT>' + url_regex<EOL><DEDENT><DEDENT>if url_regex in [w.url_regex for w in REALTIME_WIDGETS]:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % url_regex)<EOL><DEDENT>if time_interval is None:<EOL><INDENT>if getattr(widget, '<STR_LIT>', None) is not None:<EOL><INDENT>time_interval = widget.time_interval<EOL><DEDENT>else:<EOL><INDENT>time_interval = app_settings.default_time_interval<EOL><DEDENT><DEDENT>from django.views.generic import View<EOL>from braces.views import AjaxResponseMixin, JSONResponseMixin<EOL>class PartialResponse(JSONResponseMixin, AjaxResponseMixin, View):<EOL><INDENT>def get_data(self):<EOL><INDENT>return widget.get_updated_content()<EOL><DEDENT>def get(self, request, *args, **kwargs):<EOL><INDENT>return self.get_ajax(request, *args, **kwargs)<EOL><DEDENT>def get_ajax(self, request, *args, **kwargs):<EOL><INDENT>return self.render_json_response(self.get_data())<EOL><DEDENT><DEDENT>PartialResponse.url_name = url_name<EOL>PartialResponse.url_regex = url_regex<EOL>PartialResponse.time_interval = time_interval<EOL>REALTIME_WIDGETS.append(PartialResponse)<EOL>if not hasattr(widget, '<STR_LIT>'):<EOL><INDENT>widget.url_name = url_name<EOL><DEDENT>if not hasattr(widget, '<STR_LIT>'):<EOL><INDENT>widget.url_regex = url_regex<EOL><DEDENT>if not hasattr(widget, '<STR_LIT>'):<EOL><INDENT>widget.time_interval = time_interval<EOL><DEDENT>return widget<EOL>
Return a widget as real-time.

Args:
    widget (Widget): the widget to register and return as real-time.
    url_name (str): the URL name to call to get updated content.
    url_regex (regex): the URL regex to be matched.
    time_interval (int): the interval of refreshment in milliseconds.

Returns:
    Widget: the "real-timed" widget.