'Helper function to create a user activity log entry.'

@classmethod
def begin_user_activity(cls, user, activity_type='login', start_datetime=None, language=None, suppress_save=False):

    if (not cls.is_enabled()):
        return
    if (not user):
        raise ValidationError('A    valid    user    must    always    be    specified.')
    if (not start_datetime):
        start_datetime = datetime.now()
    activity_type = cls.get_activity_int(activity_type)
    cur_log = cls.get_latest_open_log_or_None(user=user, activity_type=activity_type)
    if cur_log:
        logging.warn(('%s:    had    to    END    activity    on    a    begin(%d)    @    %s' % (user.username, activity_type, start_datetime)))
        cls.end_user_activity(user=user, activity_type=activity_type, end_datetime=cur_log.last_active_datetime)
        cur_log = None
    logging.debug(('%s:    BEGIN    activity(%d)    @    %s' % (user.username, activity_type, start_datetime)))
    cur_log = cls(user=user, activity_type=activity_type, start_datetime=start_datetime, last_active_datetime=start_datetime, language=language)
    if (not suppress_save):
        cur_log.save()
    return cur_log
