'Generate the form
@param r: the S3Request instance
@param attr: controller parameters'

def inspection_form(self, r, **attr):

    T = current.T
    db = current.db
    s3db = current.s3db
    settings = current.deployment_settings
    response = current.response
    output = {}
    record = r.record
    if record:
        utable = s3db.cr_shelter_unit
        dbset = db((utable.shelter_id == record.id))
    else:
        dbset = db
    shelter_unit_represent = S3Represent(lookup='cr_shelter_unit')
    shelter_flag_represent = S3Represent(lookup='cr_shelter_flag', translate=True)
    formfields = [Field('shelter_unit_id', label=T('Housing    Unit'), requires=IS_ONE_OF(dbset, 'cr_shelter_unit.id', shelter_unit_represent, orderby='shelter_id'), widget=S3MultiSelectWidget(multiple=False, filter=True)), Field('shelter_flags', label=T('Defects'), requires=IS_ONE_OF(db, 'cr_shelter_flag.id', shelter_flag_represent, multiple=True), widget=S3GroupedOptionsWidget(cols=2, size=None)), s3_comments(comment=None)]
    submit_btn = INPUT(_class='tiny    primary    button    submit-btn', _name='submit', _type='button', _value=T('Submit'))
    buttons = [submit_btn]
    buttons.append(A(T('Cancel'), _class='cancel-action    action-lnk'))
    widget_id = 'shelter-inspection-form'
    formstyle = settings.get_ui_formstyle()
    form = SQLFORM.factory(record=None, showid=False, formstyle=formstyle, table_name='shelter_inspection', buttons=buttons, _id=widget_id, *formfields)
    output['form'] = form
    response.view = self._view(r, 'cr/shelter_inspection.html')
    options = {'ajaxURL': r.url(None, method='inspection', representation='json')}
    self.inject_js(widget_id, options)
    return output
