human
Complete the below
def facility_required(handler):

    ''''* Tries to get a facility from the request object.
    * If none exist, it tries to get the user to create one.
    * Otherwise, it fails, telling the user that a facility is required
    for whatever action hey were doing.'
    '''
assistant
#Hereever action hey were doing.
    @facility_from_request
    def facility_required_inner_fn(request, facility, *args, **kwargs):
        if facility:
            return handler(request, facility=facility, *args, **kwargs)
        if (not request.session['facility_exists']):
            if request.is_admin:
                messages.warning(request, (_('To    continue,    you    must    first    add    a    facility    (e.g.    for    your    school).    ') + _('Please    use    the    form    below    to    add    a    facility.')))
            else:
                messages.warning(request, _('You    must    first    have    the    administrator    of    this    server    log    in    below    to    add    a    facility.'))
            zone_id = getattr(Device.get_own_device().get_zone(), 'id', 'None')
            return HttpResponseRedirect(reverse('add_facility', kwargs={'zone_id': zone_id}))
        else:
            @render_to('facility/facility_selection.html')
            def facility_selection(request):
                facilities = list(Facility.objects.all())
                refresh_session_facility_info(request, len(facilities))
                cp_path_match = re.match('^(.*\\/facility\\/)[^/]+(\\/.*)$', request.path)
                if cp_path_match:
                    path_template = ('%s%%(facility_id)s%s' % cp_path_match.groups())
                else:
                    path_template = '%(path)s?%(querystring)s&facility=%(facility_id)s'
                selection_paths = {}
                for facility in facilities:
                    selection_paths[facility.id] = (path_template % {'path': request.path, 'querystring': '', 'facility_id': facility.id})
                return {'facilities': facilities, 'selection_paths': selection_paths}
            return facility_selection(request)
    return facility_required_inner_fn