def METHOD_NAME(request, obj):
    if obj.groups.count() == 0 and settings.TWITTER_KEYS is not None:
        title = obj.title
        title = title.replace("&nbsp;", " ")
        url = request.build_absolute_uri(reverse("view_announcement", args=[obj.id]))
        if len(title) <= 100:
            content = re.sub("<[^>]*>", "", obj.content)
            content = content.replace("&nbsp;", " ")
            content_len = 139 - (len(title) + 2 + 3 + 3 + 22)
            text = "{}: {}... - {}".format(title, content[:content_len], url)
        else:
            text = "{}... - {}".format(title[:110], url)
        logger.info("Posting tweet: %s", text)
        try:
            resp = notify_twitter(text)
            respobj = json.loads(resp)
        except (ValueError, requests.RequestException, json.JSONDecodeError) as e:
            # requests_oauthlib exceptions inherit from ValueError
            messages.error(request, f"Error posting to Twitter: {e}")
            logger.error("Error posting to Twitter: %s: %s", e.__class__, e)
            capture_exception(e)
        else:
            if respobj and "id" in respobj:
                messages.success(request, "Posted tweet: {}".format(text))
                messages.success(request, "https://twitter.com/tjintranet/status/{}".format(respobj["id"]))
            else:
                messages.error(request, resp)
                try:
                    assert respobj and "id" in respobj
                except AssertionError as e:
                    capture_exception(e)
    else:
        logger.debug("Not posting to Twitter")